newspack-components 4.2.0 → 4.4.0-epic-editor-refactor.1

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 (315) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/DEVELOPMENT.md +868 -0
  3. package/copy-styles.js +3 -2
  4. package/dist/cjs/accordion/index.js +17 -12
  5. package/dist/cjs/action-card/index.js +186 -140
  6. package/dist/cjs/action-card/style.scss +25 -2
  7. package/dist/cjs/autocomplete-tokenfield/index.js +254 -234
  8. package/dist/cjs/autocomplete-with-latest-posts/index.js +351 -0
  9. package/dist/cjs/autocomplete-with-latest-posts/style.scss +150 -0
  10. package/dist/cjs/autocomplete-with-suggestions/index.js +229 -126
  11. package/dist/cjs/badge/index.js +32 -0
  12. package/dist/cjs/badge/style.scss +36 -0
  13. package/dist/cjs/box-contrast/index.js +19 -15
  14. package/dist/cjs/button/index.js +41 -24
  15. package/dist/cjs/button-props/button-props.js +5 -5
  16. package/dist/cjs/button-props/index.js +2 -2
  17. package/dist/cjs/card/core-card.js +199 -0
  18. package/dist/cjs/card/index.js +75 -35
  19. package/dist/cjs/card/style-core.scss +295 -0
  20. package/dist/cjs/card/style.scss +4 -4
  21. package/dist/cjs/card-feature/index.js +141 -0
  22. package/dist/cjs/card-feature/style.scss +75 -0
  23. package/dist/cjs/card-form/index.js +144 -0
  24. package/dist/cjs/card-form/style.scss +20 -0
  25. package/dist/cjs/card-settings-group/index.js +69 -0
  26. package/dist/cjs/card-settings-group/style.scss +33 -0
  27. package/dist/cjs/card-sortable-list/index.js +426 -0
  28. package/dist/cjs/card-sortable-list/style.scss +48 -0
  29. package/dist/cjs/category-autocomplete/index.js +175 -155
  30. package/dist/cjs/color-picker/index.js +41 -23
  31. package/dist/cjs/color-picker/index.test.js +82 -0
  32. package/dist/cjs/color-picker/style.scss +11 -13
  33. package/dist/cjs/confirm-dialog/index.js +123 -0
  34. package/dist/cjs/consts.js +1 -1
  35. package/dist/cjs/custom-select-control/index.js +39 -28
  36. package/dist/cjs/dataviews/index.js +38 -0
  37. package/dist/cjs/dataviews/style.scss +9 -0
  38. package/dist/cjs/divider/index.js +47 -0
  39. package/dist/cjs/divider/style.scss +51 -0
  40. package/dist/cjs/footer/index.js +36 -30
  41. package/dist/cjs/form-token-field/index.js +51 -40
  42. package/dist/cjs/form-token-field/style.scss +0 -5
  43. package/dist/cjs/global-notices/index.js +5 -5
  44. package/dist/cjs/grid/index.js +25 -18
  45. package/dist/cjs/grid/style.scss +67 -8
  46. package/dist/cjs/handoff/index.js +204 -156
  47. package/dist/cjs/handoff-message/index.js +12 -7
  48. package/dist/cjs/hooks/index.js +10 -8
  49. package/dist/cjs/hooks/use-confirm-dialog.js +79 -0
  50. package/dist/cjs/hooks/use-unsaved-changes-dialog.js +144 -0
  51. package/dist/cjs/hooks/useObjectState.js +21 -12
  52. package/dist/cjs/hooks/useObjectState.test.js +55 -33
  53. package/dist/cjs/hooks/useOnClickOutside.js +6 -6
  54. package/dist/cjs/hooks/usePrompt.js +10 -13
  55. package/dist/cjs/image-upload/index.js +114 -123
  56. package/dist/cjs/image-upload/index.test.js +11 -13
  57. package/dist/cjs/image-upload/style.scss +12 -40
  58. package/dist/cjs/index.js +166 -92
  59. package/dist/cjs/info-button/index.js +43 -32
  60. package/dist/cjs/integration-icons/active-campaign.js +22 -0
  61. package/dist/cjs/integration-icons/constant-contact.js +28 -0
  62. package/dist/cjs/integration-icons/fundraise-up.js +25 -0
  63. package/dist/cjs/integration-icons/index.js +48 -0
  64. package/dist/cjs/integration-icons/mailchimp.js +19 -0
  65. package/dist/cjs/integration-icons/salesforce.js +17 -0
  66. package/dist/cjs/integration-icons/wisepops.js +20 -0
  67. package/dist/cjs/modal/index.js +29 -19
  68. package/dist/cjs/modal/style.scss +47 -13
  69. package/dist/cjs/newspack-icon/index.js +45 -38
  70. package/dist/cjs/newspack-icon/style.scss +5 -3
  71. package/dist/cjs/notice/index.js +64 -55
  72. package/dist/cjs/plugin-installer/index.js +259 -253
  73. package/dist/cjs/plugin-settings/SettingsSection.js +66 -60
  74. package/dist/cjs/plugin-settings/index.js +217 -200
  75. package/dist/cjs/plugin-toggle/index.js +192 -199
  76. package/dist/cjs/popover/index.js +41 -28
  77. package/dist/cjs/position-control/index.js +24 -23
  78. package/dist/cjs/progress-bar/index.js +71 -59
  79. package/dist/cjs/progress-bar/index.test.js +62 -68
  80. package/dist/cjs/proxied-imports/router.js +3 -3
  81. package/dist/cjs/radio-control/index.js +40 -27
  82. package/dist/cjs/section-header/index.js +143 -39
  83. package/dist/cjs/section-header/style.scss +129 -4
  84. package/dist/cjs/select-control/ButtonGroupControl.js +26 -21
  85. package/dist/cjs/select-control/GroupedSelectControl.js +41 -35
  86. package/dist/cjs/select-control/index.js +52 -40
  87. package/dist/cjs/settings/MinMaxSetting.js +30 -20
  88. package/dist/cjs/settings/SettingsCard.js +20 -17
  89. package/dist/cjs/settings/SettingsSection.js +22 -21
  90. package/dist/cjs/settings/index.js +5 -5
  91. package/dist/cjs/sortable-newsletter-list-control/index.js +78 -57
  92. package/dist/cjs/steps-list/index.js +44 -34
  93. package/dist/cjs/steps-list-item/index.js +47 -39
  94. package/dist/cjs/style-card/index.js +70 -63
  95. package/dist/cjs/style.scss +2 -0
  96. package/dist/cjs/tabbed-navigation/index.js +38 -36
  97. package/dist/cjs/text-control/index.js +27 -25
  98. package/dist/cjs/utils/color.js +4 -4
  99. package/dist/cjs/utils/editor-toolbar-back-button.js +61 -0
  100. package/dist/cjs/utils/index.js +31 -19
  101. package/dist/cjs/utils/style.scss +8 -0
  102. package/dist/cjs/waiting/index.js +48 -35
  103. package/dist/cjs/waiting/style.scss +4 -0
  104. package/dist/cjs/web-preview/index.js +219 -154
  105. package/dist/cjs/web-preview/style.scss +20 -53
  106. package/dist/cjs/with-wizard/index.js +362 -364
  107. package/dist/cjs/with-wizard/style.scss +28 -60
  108. package/dist/cjs/with-wizard-screen/index.js +54 -58
  109. package/dist/cjs/with-wizard-screen/style.scss +77 -10
  110. package/dist/cjs/wizard/components/WizardError.js +20 -18
  111. package/dist/cjs/wizard/components/WizardSnackbar.js +73 -0
  112. package/dist/cjs/wizard/components/style.scss +48 -0
  113. package/dist/cjs/wizard/index.js +207 -64
  114. package/dist/cjs/wizard/store/index.js +191 -97
  115. package/dist/cjs/wizard/store/utils.js +13 -8
  116. package/dist/esm/accordion/index.js +14 -9
  117. package/dist/esm/action-card/index.js +178 -124
  118. package/dist/esm/action-card/style.scss +25 -2
  119. package/dist/esm/autocomplete-tokenfield/index.js +248 -222
  120. package/dist/esm/autocomplete-with-latest-posts/index.js +347 -0
  121. package/dist/esm/autocomplete-with-latest-posts/style.scss +150 -0
  122. package/dist/esm/autocomplete-with-suggestions/index.js +226 -119
  123. package/dist/esm/badge/index.js +24 -0
  124. package/dist/esm/badge/style.scss +36 -0
  125. package/dist/esm/box-contrast/index.js +15 -11
  126. package/dist/esm/button/index.js +39 -19
  127. package/dist/esm/button-props/button-props.js +1 -1
  128. package/dist/esm/card/core-card.js +195 -0
  129. package/dist/esm/card/index.js +70 -22
  130. package/dist/esm/card/style-core.scss +295 -0
  131. package/dist/esm/card/style.scss +4 -4
  132. package/dist/esm/card-feature/index.js +131 -0
  133. package/dist/esm/card-feature/style.scss +75 -0
  134. package/dist/esm/card-form/index.js +134 -0
  135. package/dist/esm/card-form/style.scss +20 -0
  136. package/dist/esm/card-settings-group/index.js +61 -0
  137. package/dist/esm/card-settings-group/style.scss +33 -0
  138. package/dist/esm/card-sortable-list/index.js +425 -0
  139. package/dist/esm/card-sortable-list/style.scss +48 -0
  140. package/dist/esm/category-autocomplete/index.js +168 -140
  141. package/dist/esm/color-picker/index.js +39 -21
  142. package/dist/esm/color-picker/index.test.js +78 -0
  143. package/dist/esm/color-picker/style.scss +11 -13
  144. package/dist/esm/confirm-dialog/index.js +116 -0
  145. package/dist/esm/consts.js +1 -1
  146. package/dist/esm/custom-select-control/index.js +34 -15
  147. package/dist/esm/dataviews/index.js +34 -0
  148. package/dist/esm/dataviews/style.scss +9 -0
  149. package/dist/esm/divider/index.js +42 -0
  150. package/dist/esm/divider/style.scss +51 -0
  151. package/dist/esm/footer/index.js +34 -28
  152. package/dist/esm/form-token-field/index.js +46 -27
  153. package/dist/esm/form-token-field/style.scss +0 -5
  154. package/dist/esm/global-notices/index.js +3 -3
  155. package/dist/esm/grid/index.js +23 -13
  156. package/dist/esm/grid/style.scss +67 -8
  157. package/dist/esm/handoff/index.js +199 -143
  158. package/dist/esm/handoff-message/index.js +10 -6
  159. package/dist/esm/hooks/index.js +8 -6
  160. package/dist/esm/hooks/use-confirm-dialog.js +73 -0
  161. package/dist/esm/hooks/use-unsaved-changes-dialog.js +136 -0
  162. package/dist/esm/hooks/useObjectState.js +19 -9
  163. package/dist/esm/hooks/useObjectState.test.js +54 -32
  164. package/dist/esm/hooks/useOnClickOutside.js +4 -4
  165. package/dist/esm/hooks/usePrompt.js +9 -11
  166. package/dist/esm/image-upload/index.js +110 -111
  167. package/dist/esm/image-upload/index.test.js +11 -13
  168. package/dist/esm/image-upload/style.scss +12 -40
  169. package/dist/esm/index.js +13 -1
  170. package/dist/esm/info-button/index.js +38 -19
  171. package/dist/esm/integration-icons/active-campaign.js +16 -0
  172. package/dist/esm/integration-icons/constant-contact.js +22 -0
  173. package/dist/esm/integration-icons/fundraise-up.js +19 -0
  174. package/dist/esm/integration-icons/index.js +6 -0
  175. package/dist/esm/integration-icons/mailchimp.js +13 -0
  176. package/dist/esm/integration-icons/salesforce.js +11 -0
  177. package/dist/esm/integration-icons/wisepops.js +14 -0
  178. package/dist/esm/modal/index.js +27 -13
  179. package/dist/esm/modal/style.scss +47 -13
  180. package/dist/esm/newspack-icon/index.js +40 -25
  181. package/dist/esm/newspack-icon/style.scss +5 -3
  182. package/dist/esm/notice/index.js +59 -42
  183. package/dist/esm/plugin-installer/index.js +255 -243
  184. package/dist/esm/plugin-settings/SettingsSection.js +61 -50
  185. package/dist/esm/plugin-settings/index.js +212 -189
  186. package/dist/esm/plugin-toggle/index.js +187 -190
  187. package/dist/esm/popover/index.js +35 -16
  188. package/dist/esm/position-control/index.js +22 -18
  189. package/dist/esm/progress-bar/index.js +66 -49
  190. package/dist/esm/progress-bar/index.test.js +61 -67
  191. package/dist/esm/radio-control/index.js +34 -15
  192. package/dist/esm/section-header/index.js +140 -38
  193. package/dist/esm/section-header/style.scss +129 -4
  194. package/dist/esm/select-control/ButtonGroupControl.js +23 -18
  195. package/dist/esm/select-control/GroupedSelectControl.js +38 -30
  196. package/dist/esm/select-control/index.js +47 -27
  197. package/dist/esm/settings/MinMaxSetting.js +27 -16
  198. package/dist/esm/settings/SettingsCard.js +18 -13
  199. package/dist/esm/settings/SettingsSection.js +20 -19
  200. package/dist/esm/settings/index.js +3 -3
  201. package/dist/esm/sortable-newsletter-list-control/index.js +74 -53
  202. package/dist/esm/steps-list/index.js +39 -21
  203. package/dist/esm/steps-list-item/index.js +42 -26
  204. package/dist/esm/style-card/index.js +65 -50
  205. package/dist/esm/style.scss +2 -0
  206. package/dist/esm/tabbed-navigation/index.js +35 -33
  207. package/dist/esm/text-control/index.js +25 -19
  208. package/dist/esm/utils/color.js +4 -4
  209. package/dist/esm/utils/editor-toolbar-back-button.js +53 -0
  210. package/dist/esm/utils/index.js +29 -16
  211. package/dist/esm/utils/style.scss +8 -0
  212. package/dist/esm/waiting/index.js +43 -22
  213. package/dist/esm/waiting/style.scss +4 -0
  214. package/dist/esm/web-preview/index.js +218 -147
  215. package/dist/esm/web-preview/style.scss +20 -53
  216. package/dist/esm/with-wizard/index.js +360 -358
  217. package/dist/esm/with-wizard/style.scss +28 -60
  218. package/dist/esm/with-wizard-screen/index.js +48 -46
  219. package/dist/esm/with-wizard-screen/style.scss +77 -10
  220. package/dist/esm/wizard/components/WizardError.js +18 -16
  221. package/dist/esm/wizard/components/WizardSnackbar.js +70 -0
  222. package/dist/esm/wizard/components/style.scss +48 -0
  223. package/dist/esm/wizard/index.js +207 -58
  224. package/dist/esm/wizard/store/index.js +189 -90
  225. package/dist/esm/wizard/store/utils.js +13 -6
  226. package/package.json +30 -17
  227. package/release.config.js +1 -0
  228. package/shared/author-context.js +26 -0
  229. package/shared/hooks/use-coauthors.js +388 -0
  230. package/shared/hooks/use-coauthors.test.js +850 -0
  231. package/shared/hooks/use-custom-byline.js +47 -0
  232. package/shared/hooks/use-custom-byline.test.js +133 -0
  233. package/shared/scss/_mixins.scss +54 -0
  234. package/src/accordion/index.js +8 -7
  235. package/src/action-card/action-card.d.ts +7 -3
  236. package/src/action-card/index.js +39 -12
  237. package/src/action-card/style.scss +25 -2
  238. package/src/autocomplete-tokenfield/index.js +2 -2
  239. package/src/autocomplete-with-latest-posts/index.js +290 -0
  240. package/src/autocomplete-with-latest-posts/style.scss +150 -0
  241. package/src/badge/index.tsx +26 -0
  242. package/src/badge/style.scss +36 -0
  243. package/src/button/index.tsx +3 -2
  244. package/src/card/core-card.js +224 -0
  245. package/src/card/index.js +40 -1
  246. package/src/card/style-core.scss +295 -0
  247. package/src/card/style.scss +4 -4
  248. package/src/card-feature/README.md +188 -0
  249. package/src/card-feature/index.tsx +186 -0
  250. package/src/card-feature/style.scss +75 -0
  251. package/src/card-form/README.md +113 -0
  252. package/src/card-form/index.tsx +128 -0
  253. package/src/card-form/style.scss +20 -0
  254. package/src/card-settings-group/README.md +43 -0
  255. package/src/card-settings-group/index.tsx +78 -0
  256. package/src/card-settings-group/style.scss +33 -0
  257. package/src/card-sortable-list/README.md +51 -0
  258. package/src/card-sortable-list/index.tsx +435 -0
  259. package/src/card-sortable-list/style.scss +48 -0
  260. package/src/color-picker/index.js +15 -8
  261. package/src/color-picker/index.test.js +52 -0
  262. package/src/color-picker/style.scss +11 -13
  263. package/src/confirm-dialog/README.md +128 -0
  264. package/src/confirm-dialog/index.tsx +132 -0
  265. package/src/dataviews/index.tsx +34 -0
  266. package/src/dataviews/style.scss +9 -0
  267. package/src/divider/README.md +25 -0
  268. package/src/divider/index.js +31 -0
  269. package/src/divider/style.scss +51 -0
  270. package/src/form-token-field/style.scss +0 -5
  271. package/src/grid/index.tsx +2 -1
  272. package/src/grid/style.scss +67 -8
  273. package/src/handoff/README.md +93 -0
  274. package/src/handoff/index.js +46 -8
  275. package/src/hooks/index.ts +2 -1
  276. package/src/hooks/use-confirm-dialog.tsx +80 -0
  277. package/src/hooks/use-unsaved-changes-dialog.tsx +140 -0
  278. package/src/image-upload/index.js +10 -15
  279. package/src/image-upload/style.scss +12 -40
  280. package/src/index.js +13 -1
  281. package/src/integration-icons/active-campaign.js +14 -0
  282. package/src/integration-icons/constant-contact.js +22 -0
  283. package/src/integration-icons/fundraise-up.js +18 -0
  284. package/src/integration-icons/index.js +6 -0
  285. package/src/integration-icons/mailchimp.js +10 -0
  286. package/src/integration-icons/salesforce.js +10 -0
  287. package/src/integration-icons/wisepops.js +14 -0
  288. package/src/modal/index.js +12 -3
  289. package/src/modal/style.scss +47 -13
  290. package/src/newspack-icon/style.scss +5 -3
  291. package/src/plugin-installer/index.js +30 -19
  292. package/src/section-header/index.js +105 -14
  293. package/src/section-header/style.scss +129 -4
  294. package/src/select-control/index.js +4 -0
  295. package/src/style.scss +2 -0
  296. package/src/utils/editor-toolbar-back-button.tsx +48 -0
  297. package/src/utils/index.js +6 -0
  298. package/src/utils/style.scss +8 -0
  299. package/src/waiting/index.js +2 -1
  300. package/src/waiting/style.scss +4 -0
  301. package/src/web-preview/index.js +90 -35
  302. package/src/web-preview/style.scss +20 -53
  303. package/src/with-wizard/index.js +1 -1
  304. package/src/with-wizard/style.scss +28 -60
  305. package/src/with-wizard-screen/style.scss +77 -10
  306. package/src/wizard/components/WizardSnackbar.js +58 -0
  307. package/src/wizard/components/style.scss +48 -0
  308. package/src/wizard/index.js +152 -21
  309. package/src/wizard/store/index.js +28 -2
  310. package/dist/cjs/button-card/index.js +0 -72
  311. package/dist/cjs/button-card/style.scss +0 -180
  312. package/dist/esm/button-card/index.js +0 -64
  313. package/dist/esm/button-card/style.scss +0 -180
  314. package/src/button-card/index.js +0 -52
  315. package/src/button-card/style.scss +0 -180
@@ -1,3 +1,13 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
1
11
  /**
2
12
  * WordPress dependencies.
3
13
  */
@@ -14,384 +24,376 @@ import Router from '../proxied-imports/router';
14
24
  import Footer from '../footer';
15
25
  import './style.scss';
16
26
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
- const {
18
- Redirect,
19
- Route
20
- } = Router;
27
+ var Redirect = Router.Redirect,
28
+ Route = Router.Route;
21
29
 
22
30
  /**
23
31
  * Higher-Order Component to provide plugin management and error handling to Newspack Wizards.
24
32
  */
25
33
  export default function withWizard(WrappedComponent, requiredPlugins) {
26
- return class WrappedWithWizard extends Component {
27
- constructor(props) {
28
- super(props);
29
- this.state = {
30
- complete: null,
31
- error: null,
32
- loading: requiredPlugins && requiredPlugins.length > 0 ? 1 : 0,
33
- quietLoading: false,
34
- confirmation: null
35
- };
36
- this.wrappedComponentRef = createRef();
37
- }
38
- componentDidMount = () => {
39
- // If there are no requiredPlugins, fire onWizardReady as soon as component mounts.
40
- if (!requiredPlugins) {
41
- const instance = this.wrappedComponentRef.current;
42
- // eslint-disable-next-line no-unused-expressions
43
- instance && instance.onWizardReady && instance.onWizardReady();
44
- }
45
- };
46
-
47
- /**
48
- * Set the error. Called by Wizards when an error occurs.
49
- *
50
- * @return {Promise} Resolved after state update
51
- */
52
- setError = error => {
53
- return new Promise(resolve => {
54
- this.setState({
55
- error: error || null
56
- }, () => resolve());
34
+ return /*#__PURE__*/function (_Component) {
35
+ function WrappedWithWizard(props) {
36
+ var _this;
37
+ _classCallCheck(this, WrappedWithWizard);
38
+ _this = _callSuper(this, WrappedWithWizard, [props]);
39
+ _defineProperty(_this, "componentDidMount", function () {
40
+ // If there are no requiredPlugins, fire onWizardReady as soon as component mounts.
41
+ if (!requiredPlugins) {
42
+ var instance = _this.wrappedComponentRef.current;
43
+ // eslint-disable-next-line no-unused-expressions
44
+ instance && instance.onWizardReady && instance.onWizardReady();
45
+ }
57
46
  });
58
- };
59
-
60
- /**
61
- * Render any errors that need rendering.
62
- *
63
- * @return {Component} Error UI
64
- */
65
- getError = () => {
66
- const {
67
- error
68
- } = this.state;
69
- if (!error) {
70
- return null;
71
- }
72
- const parsedError = this.parseError(error);
73
- const {
74
- level
75
- } = parsedError;
76
- if ('fatal' === level) {
77
- return this.getFatalError(parsedError);
78
- }
79
- return this.getErrorNotice(parsedError);
80
- };
81
-
82
- /**
83
- * Get a notice-level error.
84
- *
85
- * @param {Error} error object already parsed by parseError
86
- * @return {Component} Error notice
87
- */
88
- getErrorNotice = error => {
89
- const {
90
- message
91
- } = error;
92
- return /*#__PURE__*/_jsx(Notice, {
93
- isError: true,
94
- className: "newspack-wizard__above-header",
95
- noticeText: message,
96
- rawHTML: true
47
+ /**
48
+ * Set the error. Called by Wizards when an error occurs.
49
+ *
50
+ * @return {Promise} Resolved after state update
51
+ */
52
+ _defineProperty(_this, "setError", function (error) {
53
+ return new Promise(function (resolve) {
54
+ _this.setState({
55
+ error: error || null
56
+ }, function () {
57
+ return resolve();
58
+ });
59
+ });
97
60
  });
98
- };
99
-
100
- /**
101
- * Get a fatal-level error.
102
- *
103
- * @param {Error} error object already parsed by parseError
104
- * @return {Component} React object
105
- */
106
- getFatalError = error => {
107
- const fallbackURL = this.getFallbackURL();
108
- if (!fallbackURL) {
109
- return null;
110
- }
111
- const {
112
- message
113
- } = error;
114
- return /*#__PURE__*/_jsxs(Modal, {
115
- title: __('Unrecoverable error'),
116
- onRequestClose: () => window.location = fallbackURL,
117
- children: [/*#__PURE__*/_jsx(Notice, {
118
- noticeText: message,
61
+ /**
62
+ * Render any errors that need rendering.
63
+ *
64
+ * @return {Component} Error UI
65
+ */
66
+ _defineProperty(_this, "getError", function () {
67
+ var error = _this.state.error;
68
+ if (!error) {
69
+ return null;
70
+ }
71
+ var parsedError = _this.parseError(error);
72
+ var level = parsedError.level;
73
+ if ('fatal' === level) {
74
+ return _this.getFatalError(parsedError);
75
+ }
76
+ return _this.getErrorNotice(parsedError);
77
+ });
78
+ /**
79
+ * Get a notice-level error.
80
+ *
81
+ * @param {Error} error object already parsed by parseError
82
+ * @return {Component} Error notice
83
+ */
84
+ _defineProperty(_this, "getErrorNotice", function (error) {
85
+ var message = error.message;
86
+ return /*#__PURE__*/_jsx(Notice, {
119
87
  isError: true,
88
+ className: "newspack-wizard__above-header",
89
+ noticeText: message,
120
90
  rawHTML: true
121
- }), /*#__PURE__*/_jsx(Card, {
122
- buttonsCard: true,
123
- noBorder: true,
124
- className: "justify-end",
125
- children: /*#__PURE__*/_jsx(Button, {
126
- isPrimary: true,
127
- href: fallbackURL,
128
- children: __('Return to Dashboard', 'newspack-plugin')
129
- })
130
- })]
91
+ });
131
92
  });
132
- };
133
-
134
- /**
135
- * Get all the relevant info out of a raw API error response.
136
- *
137
- * @param {Object} error error object
138
- * @return {Object} Error object with relevant fields and defaults
139
- */
140
- parseError = error => {
141
- const {
142
- data,
143
- message,
144
- code
145
- } = error;
146
- let level = 'fatal';
147
- if (!!data && 'level' in data) {
148
- level = data.level;
149
- } else if ('rest_invalid_param' === code) {
150
- level = 'notice';
151
- }
152
- return {
153
- message,
154
- level
155
- };
156
- };
157
-
158
- /**
159
- * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
160
- */
161
- pluginInstallationStatus = ({
162
- complete
163
- }) => {
164
- if (this.state.loading) {
165
- this.doneLoading();
166
- }
167
- const instance = this.wrappedComponentRef.current;
168
- this.setState({
169
- complete
170
- }, () => {
171
- // eslint-disable-next-line no-unused-expressions
172
- complete && instance && instance.onWizardReady && instance.onWizardReady();
93
+ /**
94
+ * Get a fatal-level error.
95
+ *
96
+ * @param {Error} error object already parsed by parseError
97
+ * @return {Component} React object
98
+ */
99
+ _defineProperty(_this, "getFatalError", function (error) {
100
+ var fallbackURL = _this.getFallbackURL();
101
+ if (!fallbackURL) {
102
+ return null;
103
+ }
104
+ var message = error.message;
105
+ return /*#__PURE__*/_jsxs(Modal, {
106
+ title: __('Unrecoverable error'),
107
+ onRequestClose: function onRequestClose() {
108
+ return window.location = fallbackURL;
109
+ },
110
+ children: [/*#__PURE__*/_jsx(Notice, {
111
+ noticeText: message,
112
+ isError: true,
113
+ rawHTML: true
114
+ }), /*#__PURE__*/_jsx(Card, {
115
+ buttonsCard: true,
116
+ noBorder: true,
117
+ className: "justify-end",
118
+ children: /*#__PURE__*/_jsx(Button, {
119
+ isPrimary: true,
120
+ href: fallbackURL,
121
+ children: __('Return to Dashboard', 'newspack-plugin')
122
+ })
123
+ })]
124
+ });
173
125
  });
174
- };
175
-
176
- /**
177
- * Begin loading.
178
- */
179
- startLoading = quiet => {
180
- if (quiet) {
181
- this.setState(state => ({
182
- quietLoading: state.quietLoading + 1
183
- }));
184
- } else {
185
- this.setState(state => ({
186
- loading: state.loading + 1
187
- }));
188
- }
189
- };
190
-
191
- /**
192
- * End loading.
193
- */
194
- doneLoading = quiet => {
195
- if (quiet) {
196
- this.setState(state => ({
197
- quietLoading: state.quietLoading - 1
198
- }));
199
- } else {
200
- this.setState(state => ({
201
- loading: state.loading - 1
202
- }));
203
- }
204
- };
205
-
206
- /**
207
- * Replacement for core apiFetch that automatically manages wizard loading UI.
208
- */
209
- wizardApiFetch = args => {
210
- const {
211
- quiet
212
- } = args;
213
- this.startLoading(quiet);
214
- return new Promise((resolve, reject) => {
215
- apiFetch(args).then(response => {
216
- this.doneLoading(quiet);
217
- resolve(response);
218
- }).catch(error => {
219
- this.doneLoading(quiet);
220
- reject(error);
126
+ /**
127
+ * Get all the relevant info out of a raw API error response.
128
+ *
129
+ * @param {Object} error error object
130
+ * @return {Object} Error object with relevant fields and defaults
131
+ */
132
+ _defineProperty(_this, "parseError", function (error) {
133
+ var data = error.data,
134
+ message = error.message,
135
+ code = error.code;
136
+ var level = 'fatal';
137
+ if (!!data && 'level' in data) {
138
+ level = data.level;
139
+ } else if ('rest_invalid_param' === code) {
140
+ level = 'notice';
141
+ }
142
+ return {
143
+ message: message,
144
+ level: level
145
+ };
146
+ });
147
+ /**
148
+ * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
149
+ */
150
+ _defineProperty(_this, "pluginInstallationStatus", function (_ref) {
151
+ var complete = _ref.complete;
152
+ if (_this.state.loading) {
153
+ _this.doneLoading();
154
+ }
155
+ var instance = _this.wrappedComponentRef.current;
156
+ _this.setState({
157
+ complete: complete
158
+ }, function () {
159
+ // eslint-disable-next-line no-unused-expressions
160
+ complete && instance && instance.onWizardReady && instance.onWizardReady();
221
161
  });
222
162
  });
223
- };
224
-
225
- /**
226
- * Render a Route that checks for plugin installation requirements, and redirects to '/' when all are done.
227
- *
228
- * @return {void}
229
- */
230
- pluginRequirements = () => {
231
- const {
232
- complete
233
- } = this.state;
234
- /* After all plugins are loaded, redirect to / (this could be configurable) */
235
- if (complete) {
236
- return /*#__PURE__*/_jsx(Redirect, {
237
- from: "/plugin-requirements",
238
- to: "/"
163
+ /**
164
+ * Begin loading.
165
+ */
166
+ _defineProperty(_this, "startLoading", function (quiet) {
167
+ if (quiet) {
168
+ _this.setState(function (state) {
169
+ return {
170
+ quietLoading: state.quietLoading + 1
171
+ };
172
+ });
173
+ } else {
174
+ _this.setState(function (state) {
175
+ return {
176
+ loading: state.loading + 1
177
+ };
178
+ });
179
+ }
180
+ });
181
+ /**
182
+ * End loading.
183
+ */
184
+ _defineProperty(_this, "doneLoading", function (quiet) {
185
+ if (quiet) {
186
+ _this.setState(function (state) {
187
+ return {
188
+ quietLoading: state.quietLoading - 1
189
+ };
190
+ });
191
+ } else {
192
+ _this.setState(function (state) {
193
+ return {
194
+ loading: state.loading - 1
195
+ };
196
+ });
197
+ }
198
+ });
199
+ /**
200
+ * Replacement for core apiFetch that automatically manages wizard loading UI.
201
+ */
202
+ _defineProperty(_this, "wizardApiFetch", function (args) {
203
+ var quiet = args.quiet;
204
+ _this.startLoading(quiet);
205
+ return new Promise(function (resolve, reject) {
206
+ apiFetch(args).then(function (response) {
207
+ _this.doneLoading(quiet);
208
+ resolve(response);
209
+ })["catch"](function (error) {
210
+ _this.doneLoading(quiet);
211
+ reject(error);
212
+ });
239
213
  });
240
- }
241
- return /*#__PURE__*/_jsx(Route, {
242
- path: "/",
243
- render: () => /*#__PURE__*/_jsxs(Fragment, {
244
- children: [complete !== null && /*#__PURE__*/_jsx("div", {
245
- className: "newspack-wizard__header",
246
- children: /*#__PURE__*/_jsx("div", {
247
- className: "newspack-wizard__header__inner",
248
- children: /*#__PURE__*/_jsxs("div", {
249
- className: "newspack-wizard__title",
250
- children: [/*#__PURE__*/_jsx(Button, {
251
- isLink: true,
252
- href: newspack_urls.dashboard,
253
- label: __('Return to Dashboard', 'newspack-plugin'),
254
- showTooltip: true,
255
- icon: category,
256
- iconSize: 36,
257
- children: /*#__PURE__*/_jsx(NewspackIcon, {
258
- size: 36
259
- })
260
- }), /*#__PURE__*/_jsx("div", {
261
- children: /*#__PURE__*/_jsx("h2", {
262
- children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack-plugin') : __('Required plugin', 'newspack-plugin')
214
+ });
215
+ /**
216
+ * Render a Route that checks for plugin installation requirements, and redirects to '/' when all are done.
217
+ *
218
+ * @return {void}
219
+ */
220
+ _defineProperty(_this, "pluginRequirements", function () {
221
+ var complete = _this.state.complete;
222
+ /* After all plugins are loaded, redirect to / (this could be configurable) */
223
+ if (complete) {
224
+ return /*#__PURE__*/_jsx(Redirect, {
225
+ from: "/plugin-requirements",
226
+ to: "/"
227
+ });
228
+ }
229
+ return /*#__PURE__*/_jsx(Route, {
230
+ path: "/",
231
+ render: function render() {
232
+ return /*#__PURE__*/_jsxs(Fragment, {
233
+ children: [complete !== null && /*#__PURE__*/_jsx("div", {
234
+ className: "newspack-wizard__header",
235
+ children: /*#__PURE__*/_jsx("div", {
236
+ className: "newspack-wizard__header__inner",
237
+ children: /*#__PURE__*/_jsxs("div", {
238
+ className: "newspack-wizard__title",
239
+ children: [/*#__PURE__*/_jsx(Button, {
240
+ isLink: true,
241
+ href: newspack_urls.dashboard,
242
+ label: __('Return to Dashboard', 'newspack-plugin'),
243
+ showTooltip: true,
244
+ icon: category,
245
+ iconSize: 36,
246
+ children: /*#__PURE__*/_jsx(NewspackIcon, {
247
+ size: 36
248
+ })
249
+ }), /*#__PURE__*/_jsx("div", {
250
+ children: /*#__PURE__*/_jsx("h2", {
251
+ children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack-plugin') : __('Required plugin', 'newspack-plugin')
252
+ })
253
+ })]
263
254
  })
264
- })]
265
- })
266
- })
267
- }), /*#__PURE__*/_jsx("div", {
268
- className: "newspack-wizard newspack-wizard__content",
269
- children: /*#__PURE__*/_jsx(PluginInstaller, {
270
- plugins: requiredPlugins,
271
- onStatus: status => this.pluginInstallationStatus(status)
272
- })
273
- })]
274
- })
255
+ })
256
+ }), /*#__PURE__*/_jsx("div", {
257
+ className: "newspack-wizard newspack-wizard__content",
258
+ children: /*#__PURE__*/_jsx(PluginInstaller, {
259
+ plugins: requiredPlugins,
260
+ onStatus: function onStatus(status) {
261
+ return _this.pluginInstallationStatus(status);
262
+ }
263
+ })
264
+ })]
265
+ });
266
+ }
267
+ });
275
268
  });
276
- };
277
-
278
- /**
279
- * Build a confirmation modal with the given title & message.
280
- * Execute {callback} if confirmed.
281
- *
282
- * @property {Object} options Options for the confirmation modal.
283
- * @property {string} options.title The title for the modal component.
284
- * @property {string} options.message The message for the modal component body.
285
- * @property {string} options.confirmText The text for the confirmation button.
286
- * @property {string} options.cancelText The text for the cancel button.
287
- * @property {Function} options.callback A function to call if the user confirms the action.
288
- */
289
- confirmAction = options => {
290
- const modalOptions = {
291
- title: null,
292
- message: __('Are you sure?', 'newpack-plugin'),
293
- confirmText: __('OK', 'newspack-plugin'),
294
- cancelText: __('Cancel', 'newspack-plugin'),
295
- callback: null,
296
- ...options
297
- };
298
- this.setState({
299
- confirmation: modalOptions
269
+ /**
270
+ * Build a confirmation modal with the given title & message.
271
+ * Execute {callback} if confirmed.
272
+ *
273
+ * @property {Object} options Options for the confirmation modal.
274
+ * @property {string} options.title The title for the modal component.
275
+ * @property {string} options.message The message for the modal component body.
276
+ * @property {string} options.confirmText The text for the confirmation button.
277
+ * @property {string} options.cancelText The text for the cancel button.
278
+ * @property {Function} options.callback A function to call if the user confirms the action.
279
+ */
280
+ _defineProperty(_this, "confirmAction", function (options) {
281
+ var modalOptions = _objectSpread({
282
+ title: null,
283
+ message: __('Are you sure?', 'newpack-plugin'),
284
+ confirmText: __('OK', 'newspack-plugin'),
285
+ cancelText: __('Cancel', 'newspack-plugin'),
286
+ callback: null
287
+ }, options);
288
+ _this.setState({
289
+ confirmation: modalOptions
290
+ });
300
291
  });
301
- };
302
-
303
- /**
304
- * Show a confirmation modal with the given title & message.
305
- * Execute {callback} if confirmed.
306
- *
307
- * @return {Component} <Modal>
308
- */
309
- getModal = () => {
310
- if (!this.state.confirmation) {
311
- return null;
312
- }
313
- const {
314
- title,
315
- message,
316
- confirmText,
317
- cancelText,
318
- callback
319
- } = this.state.confirmation;
320
- return message && callback && /*#__PURE__*/_jsxs(Modal, {
321
- isNarrow: true,
322
- hideTitle: !title,
323
- title: title,
324
- onRequestClose: () => this.setState({
325
- confirmation: null
326
- }),
327
- children: [/*#__PURE__*/_jsx("p", {
328
- children: message
329
- }), /*#__PURE__*/_jsxs(Card, {
330
- buttonsCard: true,
331
- noBorder: true,
332
- className: "justify-end",
333
- children: [/*#__PURE__*/_jsx(Button, {
334
- variant: "secondary",
335
- onClick: () => this.setState({
292
+ /**
293
+ * Show a confirmation modal with the given title & message.
294
+ * Execute {callback} if confirmed.
295
+ *
296
+ * @return {Component} <Modal>
297
+ */
298
+ _defineProperty(_this, "getModal", function () {
299
+ if (!_this.state.confirmation) {
300
+ return null;
301
+ }
302
+ var _this$state$confirmat = _this.state.confirmation,
303
+ title = _this$state$confirmat.title,
304
+ message = _this$state$confirmat.message,
305
+ confirmText = _this$state$confirmat.confirmText,
306
+ cancelText = _this$state$confirmat.cancelText,
307
+ callback = _this$state$confirmat.callback;
308
+ return message && callback && /*#__PURE__*/_jsxs(Modal, {
309
+ size: "small",
310
+ hideTitle: !title,
311
+ title: title,
312
+ onRequestClose: function onRequestClose() {
313
+ return _this.setState({
336
314
  confirmation: null
337
- }),
338
- children: cancelText
339
- }), /*#__PURE__*/_jsx(Button, {
340
- variant: "primary",
341
- onClick: () => {
342
- this.setState({
343
- confirmation: null
344
- });
345
- callback();
346
- },
347
- children: confirmText
315
+ });
316
+ },
317
+ children: [/*#__PURE__*/_jsx("p", {
318
+ children: message
319
+ }), /*#__PURE__*/_jsxs(Card, {
320
+ buttonsCard: true,
321
+ noBorder: true,
322
+ className: "justify-end",
323
+ children: [/*#__PURE__*/_jsx(Button, {
324
+ variant: "secondary",
325
+ onClick: function onClick() {
326
+ return _this.setState({
327
+ confirmation: null
328
+ });
329
+ },
330
+ children: cancelText
331
+ }), /*#__PURE__*/_jsx(Button, {
332
+ variant: "primary",
333
+ onClick: function onClick() {
334
+ _this.setState({
335
+ confirmation: null
336
+ });
337
+ callback();
338
+ },
339
+ children: confirmText
340
+ })]
348
341
  })]
349
- })]
342
+ });
350
343
  });
351
- };
352
- getFallbackURL = () => {
353
- if (typeof newspack_urls !== 'undefined') {
354
- return newspack_urls.dashboard;
355
- }
356
- };
357
-
358
- /**
359
- * Render.
360
- */
361
- render() {
362
- const {
363
- simpleFooter
364
- } = this.props;
365
- const {
366
- loading,
367
- quietLoading,
368
- error
369
- } = this.state;
370
- const loadingClasses = [loading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded'];
371
- if (quietLoading) {
372
- loadingClasses.push('newspack-wizard__is-loading-quiet');
373
- }
374
- return /*#__PURE__*/_jsxs(Fragment, {
375
- children: [this.getError(), this.getModal(), /*#__PURE__*/_jsx("div", {
376
- className: loadingClasses.join(' '),
377
- children: /*#__PURE__*/_jsx(WrappedComponent, {
378
- confirmAction: this.confirmAction,
379
- pluginRequirements: requiredPlugins && this.pluginRequirements(),
380
- clearError: this.clearError,
381
- getError: this.getError,
382
- errorData: error,
383
- setError: this.setError,
384
- isLoading: loading,
385
- startLoading: this.startLoading,
386
- doneLoading: this.doneLoading,
387
- wizardApiFetch: this.wizardApiFetch,
388
- ref: this.wrappedComponentRef,
389
- ...this.props
390
- })
391
- }), !loading && /*#__PURE__*/_jsx(Footer, {
392
- simple: simpleFooter
393
- })]
344
+ _defineProperty(_this, "getFallbackURL", function () {
345
+ if (typeof newspack_urls !== 'undefined') {
346
+ return newspack_urls.dashboard;
347
+ }
394
348
  });
349
+ _this.state = {
350
+ complete: null,
351
+ error: null,
352
+ loading: requiredPlugins && requiredPlugins.length > 0 ? 1 : 0,
353
+ quietLoading: false,
354
+ confirmation: null
355
+ };
356
+ _this.wrappedComponentRef = createRef();
357
+ return _this;
395
358
  }
396
- };
359
+ _inherits(WrappedWithWizard, _Component);
360
+ return _createClass(WrappedWithWizard, [{
361
+ key: "render",
362
+ value:
363
+ /**
364
+ * Render.
365
+ */
366
+ function render() {
367
+ var simpleFooter = this.props.simpleFooter;
368
+ var _this$state = this.state,
369
+ loading = _this$state.loading,
370
+ quietLoading = _this$state.quietLoading,
371
+ error = _this$state.error;
372
+ var loadingClasses = [loading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded'];
373
+ if (quietLoading) {
374
+ loadingClasses.push('newspack-wizard__is-loading-quiet');
375
+ }
376
+ return /*#__PURE__*/_jsxs(Fragment, {
377
+ children: [this.getError(), this.getModal(), /*#__PURE__*/_jsx("div", {
378
+ className: loadingClasses.join(' '),
379
+ children: /*#__PURE__*/_jsx(WrappedComponent, _objectSpread({
380
+ confirmAction: this.confirmAction,
381
+ pluginRequirements: requiredPlugins && this.pluginRequirements(),
382
+ clearError: this.clearError,
383
+ getError: this.getError,
384
+ errorData: error,
385
+ setError: this.setError,
386
+ isLoading: loading,
387
+ startLoading: this.startLoading,
388
+ doneLoading: this.doneLoading,
389
+ wizardApiFetch: this.wizardApiFetch,
390
+ ref: this.wrappedComponentRef
391
+ }, this.props))
392
+ }), !loading && /*#__PURE__*/_jsx(Footer, {
393
+ simple: simpleFooter
394
+ })]
395
+ });
396
+ }
397
+ }]);
398
+ }(Component);
397
399
  }