@wordpress/edit-widgets 7.0.0 → 7.1.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 (188) 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 +72 -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 +37 -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 +44 -48
  34. package/build/components/layout/unsaved-changes-warning.cjs.map +1 -7
  35. package/build/components/more-menu/index.cjs +125 -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 +269 -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 +103 -128
  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 +40 -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 +31 -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 +37 -26
  125. package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -7
  126. package/build-module/components/more-menu/index.mjs +95 -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 +250 -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/package.json +33 -33
  184. package/src/components/header/index.jsx +2 -2
  185. package/src/components/sidebar/index.jsx +18 -18
  186. package/src/components/welcome-guide/index.jsx +4 -2
  187. package/build/filters/index.cjs.map +0 -7
  188. package/build-module/filters/index.mjs.map +0 -7
@@ -1,43 +1,27 @@
1
- // packages/edit-widgets/src/blocks/widget-area/edit/inner-blocks.jsx
2
1
  import clsx from "clsx";
3
2
  import { useEntityBlockEditor } from "@wordpress/core-data";
4
3
  import { InnerBlocks, useInnerBlocksProps } from "@wordpress/block-editor";
5
4
  import { useRef } from "@wordpress/element";
6
5
  import useIsDraggingWithin from "./use-is-dragging-within.mjs";
7
6
  import { jsx } from "react/jsx-runtime";
7
+ // packages/edit-widgets/src/blocks/widget-area/edit/inner-blocks.jsx
8
8
  function WidgetAreaInnerBlocks({ id }) {
9
- const [blocks, onInput, onChange] = useEntityBlockEditor(
10
- "root",
11
- "postType"
12
- );
13
- const innerBlocksRef = useRef();
14
- const isDraggingWithinInnerBlocks = useIsDraggingWithin(innerBlocksRef);
15
- const shouldHighlightDropZone = isDraggingWithinInnerBlocks;
16
- const innerBlocksProps = useInnerBlocksProps(
17
- { ref: innerBlocksRef },
18
- {
19
- value: blocks,
20
- onInput,
21
- onChange,
22
- templateLock: false,
23
- renderAppender: InnerBlocks.ButtonBlockAppender
24
- }
25
- );
26
- return /* @__PURE__ */ jsx(
27
- "div",
28
- {
29
- "data-widget-area-id": id,
30
- className: clsx(
31
- "wp-block-widget-area__inner-blocks block-editor-inner-blocks editor-styles-wrapper",
32
- {
33
- "wp-block-widget-area__highlight-drop-zone": shouldHighlightDropZone
34
- }
35
- ),
36
- children: /* @__PURE__ */ jsx("div", { ...innerBlocksProps })
37
- }
38
- );
9
+ const [blocks, onInput, onChange] = useEntityBlockEditor("root", "postType");
10
+ const innerBlocksRef = useRef();
11
+ const shouldHighlightDropZone = useIsDraggingWithin(innerBlocksRef);
12
+ const innerBlocksProps = useInnerBlocksProps({ ref: innerBlocksRef }, {
13
+ value: blocks,
14
+ onInput,
15
+ onChange,
16
+ templateLock: false,
17
+ renderAppender: InnerBlocks.ButtonBlockAppender
18
+ });
19
+ return /* @__PURE__ */ jsx("div", {
20
+ "data-widget-area-id": id,
21
+ className: clsx("wp-block-widget-area__inner-blocks block-editor-inner-blocks editor-styles-wrapper", { "wp-block-widget-area__highlight-drop-zone": shouldHighlightDropZone }),
22
+ children: /* @__PURE__ */ jsx("div", { ...innerBlocksProps })
23
+ });
39
24
  }
40
- export {
41
- WidgetAreaInnerBlocks as default
42
- };
43
- //# sourceMappingURL=inner-blocks.mjs.map
25
+ export { WidgetAreaInnerBlocks as default };
26
+
27
+ //# sourceMappingURL=inner-blocks.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/blocks/widget-area/edit/inner-blocks.jsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport { useEntityBlockEditor } from '@wordpress/core-data';\nimport { InnerBlocks, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useRef } from '@wordpress/element';\nimport useIsDraggingWithin from './use-is-dragging-within';\n\nexport default function WidgetAreaInnerBlocks( { id } ) {\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'root',\n\t\t'postType'\n\t);\n\tconst innerBlocksRef = useRef();\n\tconst isDraggingWithinInnerBlocks = useIsDraggingWithin( innerBlocksRef );\n\tconst shouldHighlightDropZone = isDraggingWithinInnerBlocks;\n\t// Using the experimental hook so that we can control the className of the element.\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ ref: innerBlocksRef },\n\t\t{\n\t\t\tvalue: blocks,\n\t\t\tonInput,\n\t\t\tonChange,\n\t\t\ttemplateLock: false,\n\t\t\trenderAppender: InnerBlocks.ButtonBlockAppender,\n\t\t}\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tdata-widget-area-id={ id }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wp-block-widget-area__inner-blocks block-editor-inner-blocks editor-styles-wrapper',\n\t\t\t\t{\n\t\t\t\t\t'wp-block-widget-area__highlight-drop-zone':\n\t\t\t\t\t\tshouldHighlightDropZone,\n\t\t\t\t}\n\t\t\t) }\n\t\t>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,4BAA4B;AACrC,SAAS,aAAa,2BAA2B;AACjD,SAAS,cAAc;AACvB,OAAO,yBAAyB;AAiC7B;AA/BY,SAAR,sBAAwC,EAAE,GAAG,GAAI;AACvD,QAAM,CAAE,QAAQ,SAAS,QAAS,IAAI;AAAA,IACrC;AAAA,IACA;AAAA,EACD;AACA,QAAM,iBAAiB,OAAO;AAC9B,QAAM,8BAA8B,oBAAqB,cAAe;AACxE,QAAM,0BAA0B;AAEhC,QAAM,mBAAmB;AAAA,IACxB,EAAE,KAAK,eAAe;AAAA,IACtB;AAAA,MACC,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,gBAAgB,YAAY;AAAA,IAC7B;AAAA,EACD;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,uBAAsB;AAAA,MACtB,WAAY;AAAA,QACX;AAAA,QACA;AAAA,UACC,6CACC;AAAA,QACF;AAAA,MACD;AAAA,MAEA,8BAAC,SAAM,GAAG,kBAAmB;AAAA;AAAA,EAC9B;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"inner-blocks.mjs","names":[],"sources":["../../../../src/blocks/widget-area/edit/inner-blocks.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useEntityBlockEditor } from '@wordpress/core-data';\nimport { InnerBlocks, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useRef } from '@wordpress/element';\nimport useIsDraggingWithin from './use-is-dragging-within';\n\nexport default function WidgetAreaInnerBlocks( { id } ) {\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'root',\n\t\t'postType'\n\t);\n\tconst innerBlocksRef = useRef();\n\tconst isDraggingWithinInnerBlocks = useIsDraggingWithin( innerBlocksRef );\n\tconst shouldHighlightDropZone = isDraggingWithinInnerBlocks;\n\t// Using the experimental hook so that we can control the className of the element.\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ ref: innerBlocksRef },\n\t\t{\n\t\t\tvalue: blocks,\n\t\t\tonInput,\n\t\t\tonChange,\n\t\t\ttemplateLock: false,\n\t\t\trenderAppender: InnerBlocks.ButtonBlockAppender,\n\t\t}\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tdata-widget-area-id={ id }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wp-block-widget-area__inner-blocks block-editor-inner-blocks editor-styles-wrapper',\n\t\t\t\t{\n\t\t\t\t\t'wp-block-widget-area__highlight-drop-zone':\n\t\t\t\t\t\tshouldHighlightDropZone,\n\t\t\t\t}\n\t\t\t) }\n\t\t>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAMA,SAAwB,sBAAuB,EAAE,MAAO;CACvD,MAAM,CAAE,QAAQ,SAAS,YAAa,qBACrC,QACA,UACD;CACA,MAAM,iBAAiB,OAAO;CAE9B,MAAM,0BAD8B,oBAAqB,cACC;CAE1D,MAAM,mBAAmB,oBACxB,EAAE,KAAK,eAAe,GACtB;EACC,OAAO;EACP;EACA;EACA,cAAc;EACd,gBAAgB,YAAY;CAC7B,CACD;CAEA,OACC,oBAAC,OAAD;EACC,uBAAsB;EACtB,WAAY,KACX,sFACA,EACC,6CACC,wBACF,CACD;EAEA,UAAA,oBAAC,OAAD,EAAK,GAAK,iBAAoB,CAAA;CAC1B,CAAA;AAEP"}
@@ -1,35 +1,38 @@
1
+ import { useEffect, useState } from "@wordpress/element";
1
2
  // packages/edit-widgets/src/blocks/widget-area/edit/use-is-dragging-within.js
2
- import { useState, useEffect } from "@wordpress/element";
3
- var useIsDraggingWithin = (elementRef) => {
4
- const [isDraggingWithin, setIsDraggingWithin] = useState(false);
5
- useEffect(() => {
6
- const { ownerDocument } = elementRef.current;
7
- function handleDragStart(event) {
8
- handleDragEnter(event);
9
- }
10
- function handleDragEnd() {
11
- setIsDraggingWithin(false);
12
- }
13
- function handleDragEnter(event) {
14
- if (elementRef.current.contains(event.target)) {
15
- setIsDraggingWithin(true);
16
- } else {
17
- setIsDraggingWithin(false);
18
- }
19
- }
20
- ownerDocument.addEventListener("dragstart", handleDragStart);
21
- ownerDocument.addEventListener("dragend", handleDragEnd);
22
- ownerDocument.addEventListener("dragenter", handleDragEnter);
23
- return () => {
24
- ownerDocument.removeEventListener("dragstart", handleDragStart);
25
- ownerDocument.removeEventListener("dragend", handleDragEnd);
26
- ownerDocument.removeEventListener("dragenter", handleDragEnter);
27
- };
28
- }, []);
29
- return isDraggingWithin;
3
+ /** @typedef {import('@wordpress/element').RefObject} RefObject */
4
+ /**
5
+ * A React hook to determine if it's dragging within the target element.
6
+ *
7
+ * @param {RefObject<HTMLElement>} elementRef The target elementRef object.
8
+ *
9
+ * @return {boolean} Is dragging within the target element.
10
+ */
11
+ const useIsDraggingWithin = (elementRef) => {
12
+ const [isDraggingWithin, setIsDraggingWithin] = useState(false);
13
+ useEffect(() => {
14
+ const { ownerDocument } = elementRef.current;
15
+ function handleDragStart(event) {
16
+ handleDragEnter(event);
17
+ }
18
+ function handleDragEnd() {
19
+ setIsDraggingWithin(false);
20
+ }
21
+ function handleDragEnter(event) {
22
+ if (elementRef.current.contains(event.target)) setIsDraggingWithin(true);
23
+ else setIsDraggingWithin(false);
24
+ }
25
+ ownerDocument.addEventListener("dragstart", handleDragStart);
26
+ ownerDocument.addEventListener("dragend", handleDragEnd);
27
+ ownerDocument.addEventListener("dragenter", handleDragEnter);
28
+ return () => {
29
+ ownerDocument.removeEventListener("dragstart", handleDragStart);
30
+ ownerDocument.removeEventListener("dragend", handleDragEnd);
31
+ ownerDocument.removeEventListener("dragenter", handleDragEnter);
32
+ };
33
+ }, []);
34
+ return isDraggingWithin;
30
35
  };
31
- var use_is_dragging_within_default = useIsDraggingWithin;
32
- export {
33
- use_is_dragging_within_default as default
34
- };
35
- //# sourceMappingURL=use-is-dragging-within.mjs.map
36
+ export { useIsDraggingWithin as default };
37
+
38
+ //# sourceMappingURL=use-is-dragging-within.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/blocks/widget-area/edit/use-is-dragging-within.js"],
4
- "sourcesContent": ["import { useState, useEffect } from '@wordpress/element';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [] );\n\n\treturn isDraggingWithin;\n};\n\nexport default useIsDraggingWithin;\n"],
5
- "mappings": ";AAAA,SAAS,UAAU,iBAAiB;AAWpC,IAAM,sBAAsB,CAAE,eAAgB;AAC7C,QAAM,CAAE,kBAAkB,mBAAoB,IAAI,SAAU,KAAM;AAElE,YAAW,MAAM;AAChB,UAAM,EAAE,cAAc,IAAI,WAAW;AAErC,aAAS,gBAAiB,OAAQ;AAEjC,sBAAiB,KAAM;AAAA,IACxB;AAGA,aAAS,gBAAgB;AACxB,0BAAqB,KAAM;AAAA,IAC5B;AAEA,aAAS,gBAAiB,OAAQ;AAEjC,UAAK,WAAW,QAAQ,SAAU,MAAM,MAAO,GAAI;AAClD,4BAAqB,IAAK;AAAA,MAC3B,OAAO;AACN,4BAAqB,KAAM;AAAA,MAC5B;AAAA,IACD;AAIA,kBAAc,iBAAkB,aAAa,eAAgB;AAC7D,kBAAc,iBAAkB,WAAW,aAAc;AACzD,kBAAc,iBAAkB,aAAa,eAAgB;AAE7D,WAAO,MAAM;AACZ,oBAAc,oBAAqB,aAAa,eAAgB;AAChE,oBAAc,oBAAqB,WAAW,aAAc;AAC5D,oBAAc,oBAAqB,aAAa,eAAgB;AAAA,IACjE;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,SAAO;AACR;AAEA,IAAO,iCAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-is-dragging-within.mjs","names":[],"sources":["../../../../src/blocks/widget-area/edit/use-is-dragging-within.js"],"sourcesContent":["import { useState, useEffect } from '@wordpress/element';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [] );\n\n\treturn isDraggingWithin;\n};\n\nexport default useIsDraggingWithin;\n"],"mappings":";;;;;;;;;;AAWA,MAAM,uBAAwB,eAAgB;CAC7C,MAAM,CAAE,kBAAkB,uBAAwB,SAAU,KAAM;CAElE,gBAAiB;EAChB,MAAM,EAAE,kBAAkB,WAAW;EAErC,SAAS,gBAAiB,OAAQ;GAEjC,gBAAiB,KAAM;EACxB;EAGA,SAAS,gBAAgB;GACxB,oBAAqB,KAAM;EAC5B;EAEA,SAAS,gBAAiB,OAAQ;GAEjC,IAAK,WAAW,QAAQ,SAAU,MAAM,MAAO,GAC9C,oBAAqB,IAAK;QAE1B,oBAAqB,KAAM;EAE7B;EAIA,cAAc,iBAAkB,aAAa,eAAgB;EAC7D,cAAc,iBAAkB,WAAW,aAAc;EACzD,cAAc,iBAAkB,aAAa,eAAgB;EAE7D,aAAa;GACZ,cAAc,oBAAqB,aAAa,eAAgB;GAChE,cAAc,oBAAqB,WAAW,aAAc;GAC5D,cAAc,oBAAqB,aAAa,eAAgB;EACjE;CACD,GAAG,CAAC,CAAE;CAEN,OAAO;AACR"}
@@ -1,19 +1,16 @@
1
- // packages/edit-widgets/src/blocks/widget-area/index.js
2
1
  import { __ } from "@wordpress/i18n";
3
- import { layout as icon } from "@wordpress/icons";
2
+ import { layout } from "@wordpress/icons";
4
3
  import metadata from "./block.json";
5
4
  import edit from "./edit/index.mjs";
6
- var { name } = metadata;
7
- var settings = {
8
- title: __("Widget Area"),
9
- description: __("A widget area container."),
10
- __experimentalLabel: ({ name: label }) => label,
11
- icon,
12
- edit
13
- };
14
- export {
15
- metadata,
16
- name,
17
- settings
5
+ // packages/edit-widgets/src/blocks/widget-area/index.js
6
+ const { name } = metadata;
7
+ const settings = {
8
+ title: __("Widget Area"),
9
+ description: __("A widget area container."),
10
+ __experimentalLabel: ({ name: label }) => label,
11
+ icon: layout,
12
+ edit
18
13
  };
19
- //# sourceMappingURL=index.mjs.map
14
+ export { metadata, name, settings };
15
+
16
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/blocks/widget-area/index.js"],
4
- "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { layout as icon } from '@wordpress/icons';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ttitle: __( 'Widget Area' ),\n\tdescription: __( 'A widget area container.' ),\n\t__experimentalLabel: ( { name: label } ) => label,\n\ticon,\n\tedit,\n};\n"],
5
- "mappings": ";AAAA,SAAS,UAAU;AACnB,SAAS,UAAU,YAAY;AAC/B,OAAO,cAAc;AACrB,OAAO,UAAU;AAEjB,IAAM,EAAE,KAAK,IAAI;AAGV,IAAM,WAAW;AAAA,EACvB,OAAO,GAAI,aAAc;AAAA,EACzB,aAAa,GAAI,0BAA2B;AAAA,EAC5C,qBAAqB,CAAE,EAAE,MAAM,MAAM,MAAO;AAAA,EAC5C;AAAA,EACA;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/blocks/widget-area/index.js"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { layout as icon } from '@wordpress/icons';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ttitle: __( 'Widget Area' ),\n\tdescription: __( 'A widget area container.' ),\n\t__experimentalLabel: ( { name: label } ) => label,\n\ticon,\n\tedit,\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,SAAS;AAGjB,MAAa,WAAW;CACvB,OAAO,GAAI,aAAc;CACzB,aAAa,GAAI,0BAA2B;CAC5C,sBAAuB,EAAE,MAAM,YAAa;CAC5C,MAAA;CACA;AACD"}
@@ -1,4 +1,3 @@
1
- // packages/edit-widgets/src/components/error-boundary/index.jsx
2
1
  import { Component } from "@wordpress/element";
3
2
  import { speak } from "@wordpress/a11y";
4
3
  import { __ } from "@wordpress/i18n";
@@ -6,148 +5,124 @@ import { Card, CollapsibleCard, Notice, Stack, Text } from "@wordpress/ui";
6
5
  import { useCopyToClipboard } from "@wordpress/compose";
7
6
  import { doAction } from "@wordpress/hooks";
8
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
+ // packages/edit-widgets/src/components/error-boundary/index.jsx
9
9
  function getErrorNotice() {
10
- return {
11
- title: __("The editor has crashed"),
12
- description: __(
13
- "An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search."
14
- )
15
- };
10
+ return {
11
+ title: __("The editor has crashed"),
12
+ description: __("An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.")
13
+ };
16
14
  }
17
15
  function getErrorName(error) {
18
- return error instanceof Error && error.name || "Error";
16
+ return error instanceof Error && error.name || "Error";
19
17
  }
20
18
  function getErrorMessage(error) {
21
- if (typeof error === "string" && error) {
22
- return error;
23
- }
24
- if (typeof error?.message === "string" && error.message) {
25
- return error.message;
26
- }
27
- return "An unknown error occurred.";
19
+ if (typeof error === "string" && error) return error;
20
+ if (typeof error?.message === "string" && error.message) return error.message;
21
+ return "An unknown error occurred.";
28
22
  }
29
23
  function getErrorSections(error, componentStack) {
30
- const sections = [
31
- { label: getErrorName(error), content: getErrorMessage(error) }
32
- ];
33
- if (error?.stack) {
34
- sections.push({
35
- label: "Stack",
36
- content: error.stack.trim(),
37
- preformatted: true
38
- });
39
- }
40
- if (componentStack) {
41
- sections.push({
42
- label: "Component stack",
43
- content: componentStack.trim(),
44
- preformatted: true
45
- });
46
- }
47
- sections.push({
48
- label: "Environment",
49
- content: `User agent: ${window.navigator.userAgent}`,
50
- preformatted: true
51
- });
52
- return sections;
24
+ const sections = [{
25
+ label: getErrorName(error),
26
+ content: getErrorMessage(error)
27
+ }];
28
+ if (error?.stack) sections.push({
29
+ label: "Stack",
30
+ content: error.stack.trim(),
31
+ preformatted: true
32
+ });
33
+ if (componentStack) sections.push({
34
+ label: "Component stack",
35
+ content: componentStack.trim(),
36
+ preformatted: true
37
+ });
38
+ sections.push({
39
+ label: "Environment",
40
+ content: `User agent: ${window.navigator.userAgent}`,
41
+ preformatted: true
42
+ });
43
+ return sections;
53
44
  }
54
45
  function getErrorReport(error, componentStack) {
55
- const sections = getErrorSections(error, componentStack).map(
56
- ({ label, content, preformatted }) => `**${label}**
57
-
58
- ${preformatted ? `\`\`\`
59
- ${content}
60
- \`\`\`` : content}`
61
- );
62
- return ["### Error report", ...sections].join("\n\n");
46
+ return ["### Error report", ...getErrorSections(error, componentStack).map(({ label, content, preformatted }) => `**${label}**\n\n${preformatted ? `\`\`\`\n${content}\n\`\`\`` : content}`)].join("\n\n");
63
47
  }
64
48
  function CopyButton({ text, children, variant = "outline" }) {
65
- const ref = useCopyToClipboard(text);
66
- return /* @__PURE__ */ jsx(Notice.ActionButton, { variant, ref, children });
49
+ const ref = useCopyToClipboard(text);
50
+ return /* @__PURE__ */ jsx(Notice.ActionButton, {
51
+ variant,
52
+ ref,
53
+ children
54
+ });
67
55
  }
68
56
  function ErrorReport({ error, componentStack }) {
69
- return /* @__PURE__ */ jsx(
70
- Stack,
71
- {
72
- className: "edit-widgets-error-boundary__report",
73
- direction: "column",
74
- gap: "md",
75
- children: getErrorSections(error, componentStack).map(
76
- ({ label, content }) => /* @__PURE__ */ jsxs(Stack, { direction: "column", gap: "xs", children: [
77
- /* @__PURE__ */ jsx(Text, { variant: "heading-md", children: label }),
78
- /* @__PURE__ */ jsx("pre", { className: "edit-widgets-error-boundary__report-section", children: content })
79
- ] }, label)
80
- )
81
- }
82
- );
57
+ return /* @__PURE__ */ jsx(Stack, {
58
+ className: "edit-widgets-error-boundary__report",
59
+ direction: "column",
60
+ gap: "md",
61
+ children: getErrorSections(error, componentStack).map(({ label, content }) => /* @__PURE__ */ jsxs(Stack, {
62
+ direction: "column",
63
+ gap: "xs",
64
+ children: [/* @__PURE__ */ jsx(Text, {
65
+ variant: "heading-md",
66
+ children: label
67
+ }), /* @__PURE__ */ jsx("pre", {
68
+ className: "edit-widgets-error-boundary__report-section",
69
+ children: content
70
+ })]
71
+ }, label))
72
+ });
83
73
  }
84
74
  function ErrorDetails({ error, componentStack }) {
85
- return /* @__PURE__ */ jsxs(CollapsibleCard.Root, { className: "edit-widgets-error-boundary__details", children: [
86
- /* @__PURE__ */ jsx(CollapsibleCard.Header, { children: /* @__PURE__ */ jsx(Card.Title, { children: __("Error details") }) }),
87
- /* @__PURE__ */ jsx(CollapsibleCard.Content, { children: /* @__PURE__ */ jsx(
88
- ErrorReport,
89
- {
90
- error,
91
- componentStack
92
- }
93
- ) })
94
- ] });
75
+ return /* @__PURE__ */ jsxs(CollapsibleCard.Root, {
76
+ className: "edit-widgets-error-boundary__details",
77
+ children: [/* @__PURE__ */ jsx(CollapsibleCard.Header, { children: /* @__PURE__ */ jsx(Card.Title, { children: __("Error details") }) }), /* @__PURE__ */ jsx(CollapsibleCard.Content, { children: /* @__PURE__ */ jsx(ErrorReport, {
78
+ error,
79
+ componentStack
80
+ }) })]
81
+ });
95
82
  }
96
83
  var ErrorBoundary = class extends Component {
97
- constructor() {
98
- super(...arguments);
99
- this.state = {
100
- error: null,
101
- componentStack: null
102
- };
103
- }
104
- componentDidCatch(error, errorInfo) {
105
- const { title, description } = getErrorNotice();
106
- speak(`${title}. ${description}`, "assertive");
107
- this.setState({ componentStack: errorInfo?.componentStack });
108
- doAction("editor.ErrorBoundary.errorLogged", error, errorInfo);
109
- }
110
- static getDerivedStateFromError(error) {
111
- return { error };
112
- }
113
- render() {
114
- const { error, componentStack } = this.state;
115
- if (!error) {
116
- return this.props.children;
117
- }
118
- const { title, description } = getErrorNotice();
119
- return /* @__PURE__ */ jsxs(
120
- Stack,
121
- {
122
- className: "edit-widgets-error-boundary",
123
- direction: "column",
124
- gap: "lg",
125
- children: [
126
- /* @__PURE__ */ jsxs(Notice.Root, { intent: "error", children: [
127
- /* @__PURE__ */ jsx(Notice.Title, { children: title }),
128
- /* @__PURE__ */ jsx(Notice.Description, { children: description }),
129
- /* @__PURE__ */ jsx(Notice.Actions, { children: /* @__PURE__ */ jsx(
130
- CopyButton,
131
- {
132
- variant: "solid",
133
- text: () => getErrorReport(error, componentStack),
134
- children: __("Copy error")
135
- }
136
- ) })
137
- ] }),
138
- globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ jsx(
139
- ErrorDetails,
140
- {
141
- error,
142
- componentStack
143
- }
144
- ) : null
145
- ]
146
- }
147
- );
148
- }
84
+ constructor() {
85
+ super(...arguments);
86
+ this.state = {
87
+ error: null,
88
+ componentStack: null
89
+ };
90
+ }
91
+ componentDidCatch(error, errorInfo) {
92
+ const { title, description } = getErrorNotice();
93
+ speak(`${title}. ${description}`, "assertive");
94
+ this.setState({ componentStack: errorInfo?.componentStack });
95
+ doAction("editor.ErrorBoundary.errorLogged", error, errorInfo);
96
+ }
97
+ static getDerivedStateFromError(error) {
98
+ return { error };
99
+ }
100
+ render() {
101
+ const { error, componentStack } = this.state;
102
+ if (!error) return this.props.children;
103
+ const { title, description } = getErrorNotice();
104
+ return /* @__PURE__ */ jsxs(Stack, {
105
+ className: "edit-widgets-error-boundary",
106
+ direction: "column",
107
+ gap: "lg",
108
+ children: [/* @__PURE__ */ jsxs(Notice.Root, {
109
+ intent: "error",
110
+ children: [
111
+ /* @__PURE__ */ jsx(Notice.Title, { children: title }),
112
+ /* @__PURE__ */ jsx(Notice.Description, { children: description }),
113
+ /* @__PURE__ */ jsx(Notice.Actions, { children: /* @__PURE__ */ jsx(CopyButton, {
114
+ variant: "solid",
115
+ text: () => getErrorReport(error, componentStack),
116
+ children: __("Copy error")
117
+ }) })
118
+ ]
119
+ }), globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ jsx(ErrorDetails, {
120
+ error,
121
+ componentStack
122
+ }) : null]
123
+ });
124
+ }
149
125
  };
150
- export {
151
- ErrorBoundary as default
152
- };
153
- //# sourceMappingURL=index.mjs.map
126
+ export { ErrorBoundary as default };
127
+
128
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/error-boundary/index.jsx"],
4
- "sourcesContent": ["import { Component } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport { __ } from '@wordpress/i18n';\nimport { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction getErrorNotice() {\n\treturn {\n\t\ttitle: __( 'The editor has crashed' ),\n\t\tdescription: __(\n\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t),\n\t};\n}\n\n// A boundary catches whatever was thrown, which is not always an `Error`.\nfunction getErrorName( error ) {\n\treturn ( error instanceof Error && error.name ) || 'Error';\n}\n\nfunction getErrorMessage( error ) {\n\tif ( typeof error === 'string' && error ) {\n\t\treturn error;\n\t}\n\n\tif ( typeof error?.message === 'string' && error.message ) {\n\t\treturn error.message;\n\t}\n\n\treturn 'An unknown error occurred.';\n}\n\n// The sections of the report, shared by the copied Markdown and the details\n// panel so that the two cannot drift apart. Deliberately untranslated: both\n// are developer-facing, and the report is pasted into a bug report.\nfunction getErrorSections( error, componentStack ) {\n\tconst sections = [\n\t\t{ label: getErrorName( error ), content: getErrorMessage( error ) },\n\t];\n\n\tif ( error?.stack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Stack',\n\t\t\tcontent: error.stack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tif ( componentStack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Component stack',\n\t\t\tcontent: componentStack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tsections.push( {\n\t\tlabel: 'Environment',\n\t\tcontent: `User agent: ${ window.navigator.userAgent }`,\n\t\tpreformatted: true,\n\t} );\n\n\treturn sections;\n}\n\n// Markdown, so the report stays readable as plain text and renders when pasted\n// into a bug report.\nfunction getErrorReport( error, componentStack ) {\n\tconst sections = getErrorSections( error, componentStack ).map(\n\t\t( { label, content, preformatted } ) =>\n\t\t\t`**${ label }**\\n\\n${\n\t\t\t\tpreformatted ? `\\`\\`\\`\\n${ content }\\n\\`\\`\\`` : content\n\t\t\t}`\n\t);\n\n\treturn [ '### Error report', ...sections ].join( '\\n\\n' );\n}\n\nfunction CopyButton( { text, children, variant = 'outline' } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Notice.ActionButton variant={ variant } ref={ ref }>\n\t\t\t{ children }\n\t\t</Notice.ActionButton>\n\t);\n}\n\nfunction ErrorReport( { error, componentStack } ) {\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"edit-widgets-error-boundary__report\"\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t{ getErrorSections( error, componentStack ).map(\n\t\t\t\t( { label, content } ) => (\n\t\t\t\t\t<Stack key={ label } direction=\"column\" gap=\"xs\">\n\t\t\t\t\t\t<Text variant=\"heading-md\">{ label }</Text>\n\t\t\t\t\t\t<pre className=\"edit-widgets-error-boundary__report-section\">\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</pre>\n\t\t\t\t\t</Stack>\n\t\t\t\t)\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction ErrorDetails( { error, componentStack } ) {\n\treturn (\n\t\t<CollapsibleCard.Root className=\"edit-widgets-error-boundary__details\">\n\t\t\t<CollapsibleCard.Header>\n\t\t\t\t<Card.Title>{ __( 'Error details' ) }</Card.Title>\n\t\t\t</CollapsibleCard.Header>\n\t\t\t<CollapsibleCard.Content>\n\t\t\t\t<ErrorReport\n\t\t\t\t\terror={ error }\n\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t/>\n\t\t\t</CollapsibleCard.Content>\n\t\t</CollapsibleCard.Root>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t\tcomponentStack: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error, errorInfo ) {\n\t\tconst { title, description } = getErrorNotice();\n\t\tspeak( `${ title }. ${ description }`, 'assertive' );\n\t\tthis.setState( { componentStack: errorInfo?.componentStack } );\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error, componentStack } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\tconst { title, description } = getErrorNotice();\n\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tclassName=\"edit-widgets-error-boundary\"\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t>\n\t\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t\t<Notice.Title>{ title }</Notice.Title>\n\t\t\t\t\t<Notice.Description>{ description }</Notice.Description>\n\t\t\t\t\t<Notice.Actions>\n\t\t\t\t\t\t<CopyButton\n\t\t\t\t\t\t\tvariant=\"solid\"\n\t\t\t\t\t\t\ttext={ () =>\n\t\t\t\t\t\t\t\tgetErrorReport( error, componentStack )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Copy error' ) }\n\t\t\t\t\t\t</CopyButton>\n\t\t\t\t\t</Notice.Actions>\n\t\t\t\t</Notice.Root>\n\t\t\t\t{ globalThis.SCRIPT_DEBUG ? (\n\t\t\t\t\t<ErrorDetails\n\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t\t/>\n\t\t\t\t) : null }\n\t\t\t</Stack>\n\t\t);\n\t}\n}\n"],
5
- "mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,UAAU;AACnB,SAAS,MAAM,iBAAiB,QAAQ,OAAO,YAAY;AAC3D,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AA6EvB,cAeG,YAfH;AA3EF,S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AS;AACR,UAAM,EAAE,OAAO,eAAe,IAAI,KAAK;AACvC,QAAK,CAAE,OAAQ;AACd,aAAO,KAAK,MAAM;AAAA,IACnB;AAEA,UAAM,EAAE,OAAO,YAAY,IAAI,eAAe;AAE9C,WACC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,WAAU;AAAA,QACV,KAAI;AAAA,QAEJ;AAAA,+BAAC,OAAO,MAAP,EAAY,QAAO,SACnB;AAAA,gCAAC,OAAO,OAAP,EAAe,iBAAO;AAAA,YACvB,oBAAC,OAAO,aAAP,EAAqB,uBAAa;AAAA,YACnC,oBAAC,OAAO,SAAP,EACA;AAAA,cAAC;AAAA;AAAA,gBACA,SAAQ;AAAA,gBACR,MAAO,MACN,eAAgB,OAAO,cAAe;AAAA,gBAGrC,aAAI,YAAa;AAAA;AAAA,YACpB,GACD;AAAA,aACD;AAAA,UACE,WAAW,eACZ;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACD,IACG;AAAA;AAAA;AAAA,IACL;AAAA,EAEF;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/error-boundary/index.jsx"],"sourcesContent":["import { Component } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport { __ } from '@wordpress/i18n';\nimport { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction getErrorNotice() {\n\treturn {\n\t\ttitle: __( 'The editor has crashed' ),\n\t\tdescription: __(\n\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t),\n\t};\n}\n\n// A boundary catches whatever was thrown, which is not always an `Error`.\nfunction getErrorName( error ) {\n\treturn ( error instanceof Error && error.name ) || 'Error';\n}\n\nfunction getErrorMessage( error ) {\n\tif ( typeof error === 'string' && error ) {\n\t\treturn error;\n\t}\n\n\tif ( typeof error?.message === 'string' && error.message ) {\n\t\treturn error.message;\n\t}\n\n\treturn 'An unknown error occurred.';\n}\n\n// The sections of the report, shared by the copied Markdown and the details\n// panel so that the two cannot drift apart. Deliberately untranslated: both\n// are developer-facing, and the report is pasted into a bug report.\nfunction getErrorSections( error, componentStack ) {\n\tconst sections = [\n\t\t{ label: getErrorName( error ), content: getErrorMessage( error ) },\n\t];\n\n\tif ( error?.stack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Stack',\n\t\t\tcontent: error.stack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tif ( componentStack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Component stack',\n\t\t\tcontent: componentStack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tsections.push( {\n\t\tlabel: 'Environment',\n\t\tcontent: `User agent: ${ window.navigator.userAgent }`,\n\t\tpreformatted: true,\n\t} );\n\n\treturn sections;\n}\n\n// Markdown, so the report stays readable as plain text and renders when pasted\n// into a bug report.\nfunction getErrorReport( error, componentStack ) {\n\tconst sections = getErrorSections( error, componentStack ).map(\n\t\t( { label, content, preformatted } ) =>\n\t\t\t`**${ label }**\\n\\n${\n\t\t\t\tpreformatted ? `\\`\\`\\`\\n${ content }\\n\\`\\`\\`` : content\n\t\t\t}`\n\t);\n\n\treturn [ '### Error report', ...sections ].join( '\\n\\n' );\n}\n\nfunction CopyButton( { text, children, variant = 'outline' } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Notice.ActionButton variant={ variant } ref={ ref }>\n\t\t\t{ children }\n\t\t</Notice.ActionButton>\n\t);\n}\n\nfunction ErrorReport( { error, componentStack } ) {\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"edit-widgets-error-boundary__report\"\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t{ getErrorSections( error, componentStack ).map(\n\t\t\t\t( { label, content } ) => (\n\t\t\t\t\t<Stack key={ label } direction=\"column\" gap=\"xs\">\n\t\t\t\t\t\t<Text variant=\"heading-md\">{ label }</Text>\n\t\t\t\t\t\t<pre className=\"edit-widgets-error-boundary__report-section\">\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</pre>\n\t\t\t\t\t</Stack>\n\t\t\t\t)\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction ErrorDetails( { error, componentStack } ) {\n\treturn (\n\t\t<CollapsibleCard.Root className=\"edit-widgets-error-boundary__details\">\n\t\t\t<CollapsibleCard.Header>\n\t\t\t\t<Card.Title>{ __( 'Error details' ) }</Card.Title>\n\t\t\t</CollapsibleCard.Header>\n\t\t\t<CollapsibleCard.Content>\n\t\t\t\t<ErrorReport\n\t\t\t\t\terror={ error }\n\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t/>\n\t\t\t</CollapsibleCard.Content>\n\t\t</CollapsibleCard.Root>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t\tcomponentStack: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error, errorInfo ) {\n\t\tconst { title, description } = getErrorNotice();\n\t\tspeak( `${ title }. ${ description }`, 'assertive' );\n\t\tthis.setState( { componentStack: errorInfo?.componentStack } );\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error, componentStack } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\tconst { title, description } = getErrorNotice();\n\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tclassName=\"edit-widgets-error-boundary\"\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t>\n\t\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t\t<Notice.Title>{ title }</Notice.Title>\n\t\t\t\t\t<Notice.Description>{ description }</Notice.Description>\n\t\t\t\t\t<Notice.Actions>\n\t\t\t\t\t\t<CopyButton\n\t\t\t\t\t\t\tvariant=\"solid\"\n\t\t\t\t\t\t\ttext={ () =>\n\t\t\t\t\t\t\t\tgetErrorReport( error, componentStack )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Copy error' ) }\n\t\t\t\t\t\t</CopyButton>\n\t\t\t\t\t</Notice.Actions>\n\t\t\t\t</Notice.Root>\n\t\t\t\t{ globalThis.SCRIPT_DEBUG ? (\n\t\t\t\t\t<ErrorDetails\n\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t\t/>\n\t\t\t\t) : null }\n\t\t\t</Stack>\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;AAOA,SAAS,iBAAiB;CACzB,OAAO;EACN,OAAO,GAAI,wBAAyB;EACpC,aAAa,GACZ,iHACD;CACD;AACD;AAGA,SAAS,aAAc,OAAQ;CAC9B,OAAS,iBAAiB,SAAS,MAAM,QAAU;AACpD;AAEA,SAAS,gBAAiB,OAAQ;CACjC,IAAK,OAAO,UAAU,YAAY,OACjC,OAAO;CAGR,IAAK,OAAO,OAAO,YAAY,YAAY,MAAM,SAChD,OAAO,MAAM;CAGd,OAAO;AACR;AAKA,SAAS,iBAAkB,OAAO,gBAAiB;CAClD,MAAM,WAAW,CAChB;EAAE,OAAO,aAAc,KAAM;EAAG,SAAS,gBAAiB,KAAM;CAAE,CACnE;CAEA,IAAK,OAAO,OACX,SAAS,KAAM;EACd,OAAO;EACP,SAAS,MAAM,MAAM,KAAK;EAC1B,cAAc;CACf,CAAE;CAGH,IAAK,gBACJ,SAAS,KAAM;EACd,OAAO;EACP,SAAS,eAAe,KAAK;EAC7B,cAAc;CACf,CAAE;CAGH,SAAS,KAAM;EACd,OAAO;EACP,SAAS,eAAgB,OAAO,UAAU;EAC1C,cAAc;CACf,CA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