newspack-components 3.0.0-alpha.1 → 3.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/babel.config.cjs.js +26 -0
  2. package/babel.config.js +26 -0
  3. package/dist/cjs/accordion/index.js +50 -0
  4. package/dist/cjs/accordion/style.scss +31 -0
  5. package/dist/cjs/action-card/index.js +38 -41
  6. package/dist/cjs/action-card/style.scss +9 -9
  7. package/dist/cjs/autocomplete-tokenfield/index.js +19 -18
  8. package/dist/cjs/autocomplete-tokenfield/style.scss +3 -3
  9. package/dist/cjs/autocomplete-with-suggestions/index.js +29 -29
  10. package/dist/cjs/autocomplete-with-suggestions/style.scss +8 -8
  11. package/dist/cjs/button/style.scss +1 -1
  12. package/dist/cjs/button-card/index.js +8 -8
  13. package/dist/cjs/button-card/style.scss +19 -13
  14. package/dist/cjs/card/index.js +3 -3
  15. package/dist/cjs/card/style.scss +1 -1
  16. package/dist/cjs/category-autocomplete/index.js +50 -48
  17. package/dist/cjs/category-autocomplete/style.scss +2 -2
  18. package/dist/cjs/color-picker/index.js +7 -7
  19. package/dist/cjs/color-picker/style.scss +3 -3
  20. package/dist/cjs/custom-select-control/index.js +3 -3
  21. package/dist/cjs/custom-select-control/style.scss +11 -10
  22. package/dist/cjs/date-range-picker/index.js +39 -0
  23. package/dist/cjs/date-range-picker/style.scss +148 -0
  24. package/dist/cjs/footer/index.js +19 -17
  25. package/dist/cjs/footer/style.scss +1 -1
  26. package/dist/cjs/form-token-field/index.js +5 -5
  27. package/dist/cjs/form-token-field/style.scss +1 -1
  28. package/dist/cjs/global-notices/index.js +3 -3
  29. package/dist/cjs/grid/style.scss +9 -9
  30. package/dist/cjs/handoff/index.js +72 -69
  31. package/dist/cjs/handoff-message/index.js +5 -3
  32. package/dist/cjs/hooks/useObjectState.js +1 -1
  33. package/dist/cjs/hooks/useObjectState.test.js +9 -9
  34. package/dist/cjs/image-upload/index.js +113 -108
  35. package/dist/cjs/image-upload/index.test.js +13 -6
  36. package/dist/cjs/image-upload/style.scss +5 -5
  37. package/dist/cjs/index.js +15 -1
  38. package/dist/cjs/info-button/index.js +5 -5
  39. package/dist/cjs/modal/index.js +3 -3
  40. package/dist/cjs/modal/style.scss +5 -5
  41. package/dist/cjs/newspack-icon/index.js +4 -4
  42. package/dist/cjs/newspack-icon/style.scss +1 -1
  43. package/dist/cjs/newspack-logo/index.js +4 -4
  44. package/dist/cjs/newspack-logo/style.scss +1 -1
  45. package/dist/cjs/notice/index.js +11 -8
  46. package/dist/cjs/notice/style.scss +11 -11
  47. package/dist/cjs/patrons-logo/index.js +58 -62
  48. package/dist/cjs/plugin-installer/index.js +139 -137
  49. package/dist/cjs/plugin-installer/style.scss +1 -1
  50. package/dist/cjs/plugin-settings/SettingsSection.js +11 -9
  51. package/dist/cjs/plugin-settings/index.js +151 -144
  52. package/dist/cjs/plugin-settings/style.scss +1 -1
  53. package/dist/cjs/plugin-toggle/index.js +159 -155
  54. package/dist/cjs/plugin-toggle/style.scss +1 -1
  55. package/dist/cjs/popover/index.js +3 -3
  56. package/dist/cjs/popover/style.scss +7 -7
  57. package/dist/cjs/position-control/index.js +24 -22
  58. package/dist/cjs/position-control/style.scss +8 -8
  59. package/dist/cjs/progress-bar/index.js +8 -8
  60. package/dist/cjs/progress-bar/index.test.js +12 -11
  61. package/dist/cjs/progress-bar/style.scss +2 -2
  62. package/dist/cjs/proxied-imports/router.js +2 -1
  63. package/dist/cjs/radio-control/index.js +3 -3
  64. package/dist/cjs/radio-control/style.scss +3 -3
  65. package/dist/cjs/section-header/index.js +8 -8
  66. package/dist/cjs/section-header/style.scss +1 -1
  67. package/dist/cjs/select-control/ButtonGroupControl.js +7 -7
  68. package/dist/cjs/select-control/GroupedSelectControl.js +15 -14
  69. package/dist/cjs/select-control/index.js +6 -6
  70. package/dist/cjs/select-control/style.scss +4 -4
  71. package/dist/cjs/settings/MinMaxSetting.js +12 -11
  72. package/dist/cjs/settings/SettingsCard.js +4 -4
  73. package/dist/cjs/settings/SettingsSection.js +6 -6
  74. package/dist/cjs/settings/index.js +1 -1
  75. package/dist/cjs/settings/style.scss +1 -1
  76. package/dist/cjs/sortable-newsletter-list-control/index.js +25 -24
  77. package/dist/cjs/steps-list/index.js +4 -4
  78. package/dist/cjs/steps-list/style.scss +2 -2
  79. package/dist/cjs/steps-list-item/index.js +5 -5
  80. package/dist/cjs/steps-list-item/style.scss +5 -5
  81. package/dist/cjs/style-card/index.js +20 -17
  82. package/dist/cjs/style-card/style.scss +4 -4
  83. package/dist/cjs/style.scss +1 -1
  84. package/dist/cjs/tabbed-navigation/index.js +7 -7
  85. package/dist/cjs/tabbed-navigation/style.scss +4 -4
  86. package/dist/cjs/utils/index.js +2 -2
  87. package/dist/cjs/waiting/index.js +3 -3
  88. package/dist/cjs/web-preview/index.js +107 -104
  89. package/dist/cjs/web-preview/style.scss +5 -5
  90. package/dist/cjs/with-wizard/index.js +250 -239
  91. package/dist/cjs/with-wizard/style.scss +44 -22
  92. package/dist/cjs/with-wizard-screen/index.js +24 -23
  93. package/dist/cjs/with-wizard-screen/style.scss +7 -7
  94. package/dist/cjs/wizard/components/WizardError.js +10 -9
  95. package/dist/cjs/wizard/index.js +30 -27
  96. package/dist/cjs/wizard/store/index.js +1 -1
  97. package/dist/esm/accordion/index.js +42 -0
  98. package/dist/esm/accordion/style.scss +31 -0
  99. package/dist/esm/action-card/index.js +37 -40
  100. package/dist/esm/action-card/style.scss +9 -9
  101. package/dist/esm/autocomplete-tokenfield/index.js +18 -17
  102. package/dist/esm/autocomplete-tokenfield/style.scss +3 -3
  103. package/dist/esm/autocomplete-with-suggestions/index.js +17 -19
  104. package/dist/esm/autocomplete-with-suggestions/style.scss +8 -8
  105. package/dist/esm/button/style.scss +1 -1
  106. package/dist/esm/button-card/index.js +7 -7
  107. package/dist/esm/button-card/style.scss +19 -13
  108. package/dist/esm/card/index.js +2 -2
  109. package/dist/esm/card/style.scss +1 -1
  110. package/dist/esm/category-autocomplete/index.js +49 -47
  111. package/dist/esm/category-autocomplete/style.scss +2 -2
  112. package/dist/esm/color-picker/index.js +6 -6
  113. package/dist/esm/color-picker/style.scss +3 -3
  114. package/dist/esm/custom-select-control/index.js +2 -2
  115. package/dist/esm/custom-select-control/style.scss +11 -10
  116. package/dist/esm/date-range-picker/index.js +31 -0
  117. package/dist/esm/date-range-picker/style.scss +148 -0
  118. package/dist/esm/footer/index.js +10 -11
  119. package/dist/esm/footer/style.scss +1 -1
  120. package/dist/esm/form-token-field/index.js +4 -4
  121. package/dist/esm/form-token-field/style.scss +1 -1
  122. package/dist/esm/global-notices/index.js +3 -3
  123. package/dist/esm/grid/style.scss +9 -9
  124. package/dist/esm/handoff/index.js +66 -67
  125. package/dist/esm/handoff-message/index.js +5 -3
  126. package/dist/esm/hooks/useObjectState.test.js +8 -8
  127. package/dist/esm/image-upload/index.js +109 -108
  128. package/dist/esm/image-upload/index.test.js +10 -4
  129. package/dist/esm/image-upload/style.scss +5 -5
  130. package/dist/esm/index.js +2 -0
  131. package/dist/esm/info-button/index.js +4 -4
  132. package/dist/esm/modal/index.js +2 -2
  133. package/dist/esm/modal/style.scss +5 -5
  134. package/dist/esm/newspack-icon/index.js +3 -3
  135. package/dist/esm/newspack-icon/style.scss +1 -1
  136. package/dist/esm/newspack-logo/index.js +3 -3
  137. package/dist/esm/newspack-logo/style.scss +1 -1
  138. package/dist/esm/notice/index.js +6 -7
  139. package/dist/esm/notice/style.scss +11 -11
  140. package/dist/esm/patrons-logo/index.js +57 -62
  141. package/dist/esm/plugin-installer/index.js +133 -134
  142. package/dist/esm/plugin-installer/style.scss +1 -1
  143. package/dist/esm/plugin-settings/SettingsSection.js +8 -9
  144. package/dist/esm/plugin-settings/index.js +147 -143
  145. package/dist/esm/plugin-settings/style.scss +1 -1
  146. package/dist/esm/plugin-toggle/index.js +156 -153
  147. package/dist/esm/plugin-toggle/style.scss +1 -1
  148. package/dist/esm/popover/index.js +2 -2
  149. package/dist/esm/popover/style.scss +7 -7
  150. package/dist/esm/position-control/index.js +8 -9
  151. package/dist/esm/position-control/style.scss +8 -8
  152. package/dist/esm/progress-bar/index.js +8 -8
  153. package/dist/esm/progress-bar/index.test.js +9 -10
  154. package/dist/esm/progress-bar/style.scss +2 -2
  155. package/dist/esm/radio-control/index.js +2 -2
  156. package/dist/esm/radio-control/style.scss +3 -3
  157. package/dist/esm/section-header/index.js +7 -7
  158. package/dist/esm/section-header/style.scss +1 -1
  159. package/dist/esm/select-control/ButtonGroupControl.js +6 -6
  160. package/dist/esm/select-control/GroupedSelectControl.js +10 -11
  161. package/dist/esm/select-control/index.js +5 -5
  162. package/dist/esm/select-control/style.scss +4 -4
  163. package/dist/esm/settings/MinMaxSetting.js +9 -10
  164. package/dist/esm/settings/SettingsCard.js +3 -3
  165. package/dist/esm/settings/SettingsSection.js +6 -6
  166. package/dist/esm/settings/style.scss +1 -1
  167. package/dist/esm/sortable-newsletter-list-control/index.js +19 -20
  168. package/dist/esm/steps-list/index.js +3 -3
  169. package/dist/esm/steps-list/style.scss +2 -2
  170. package/dist/esm/steps-list-item/index.js +4 -4
  171. package/dist/esm/steps-list-item/style.scss +5 -5
  172. package/dist/esm/style-card/index.js +11 -12
  173. package/dist/esm/style-card/style.scss +4 -4
  174. package/dist/esm/style.scss +1 -1
  175. package/dist/esm/tabbed-navigation/index.js +6 -6
  176. package/dist/esm/tabbed-navigation/style.scss +4 -4
  177. package/dist/esm/utils/index.js +2 -2
  178. package/dist/esm/waiting/index.js +2 -2
  179. package/dist/esm/web-preview/index.js +103 -103
  180. package/dist/esm/web-preview/style.scss +5 -5
  181. package/dist/esm/with-wizard/index.js +248 -239
  182. package/dist/esm/with-wizard/style.scss +44 -22
  183. package/dist/esm/with-wizard-screen/index.js +19 -20
  184. package/dist/esm/with-wizard-screen/style.scss +7 -7
  185. package/dist/esm/wizard/components/WizardError.js +7 -8
  186. package/dist/esm/wizard/index.js +23 -24
  187. package/package.json +21 -15
  188. package/shared/scss/_mixins.scss +2 -2
  189. package/src/accordion/index.js +35 -0
  190. package/src/accordion/style.scss +31 -0
  191. package/src/action-card/style.scss +9 -9
  192. package/src/autocomplete-tokenfield/style.scss +3 -3
  193. package/src/autocomplete-with-suggestions/index.js +46 -44
  194. package/src/autocomplete-with-suggestions/style.scss +8 -8
  195. package/src/button/style.scss +1 -1
  196. package/src/button-card/style.scss +19 -13
  197. package/src/card/style.scss +1 -1
  198. package/src/category-autocomplete/style.scss +2 -2
  199. package/src/color-picker/style.scss +3 -3
  200. package/src/custom-select-control/style.scss +11 -10
  201. package/src/date-range-picker/index.js +31 -0
  202. package/src/date-range-picker/style.scss +148 -0
  203. package/src/footer/style.scss +1 -1
  204. package/src/form-token-field/style.scss +1 -1
  205. package/src/grid/style.scss +9 -9
  206. package/src/handoff-message/index.js +3 -1
  207. package/src/image-upload/index.js +1 -1
  208. package/src/image-upload/index.test.js +6 -1
  209. package/src/image-upload/style.scss +5 -5
  210. package/src/index.js +2 -0
  211. package/src/modal/style.scss +5 -5
  212. package/src/newspack-icon/style.scss +1 -1
  213. package/src/newspack-logo/style.scss +1 -1
  214. package/src/notice/style.scss +11 -11
  215. package/src/plugin-installer/style.scss +1 -1
  216. package/src/plugin-settings/style.scss +1 -1
  217. package/src/plugin-toggle/index.js +6 -7
  218. package/src/plugin-toggle/style.scss +1 -1
  219. package/src/popover/style.scss +7 -7
  220. package/src/position-control/index.js +62 -63
  221. package/src/position-control/style.scss +8 -8
  222. package/src/progress-bar/style.scss +2 -2
  223. package/src/radio-control/style.scss +3 -3
  224. package/src/section-header/style.scss +1 -1
  225. package/src/select-control/style.scss +4 -4
  226. package/src/settings/style.scss +1 -1
  227. package/src/steps-list/style.scss +2 -2
  228. package/src/steps-list-item/style.scss +5 -5
  229. package/src/style-card/style.scss +4 -4
  230. package/src/style.scss +1 -1
  231. package/src/tabbed-navigation/index.js +1 -1
  232. package/src/tabbed-navigation/style.scss +4 -4
  233. package/src/web-preview/style.scss +5 -5
  234. package/src/with-wizard/style.scss +44 -22
  235. package/src/with-wizard-screen/style.scss +7 -7
  236. package/dist/cjs/button/index.js +0 -56
  237. package/dist/cjs/grid/index.js +0 -37
  238. package/dist/cjs/hooks/index.js +0 -25
  239. package/dist/cjs/hooks/usePrompt.js +0 -49
  240. package/dist/cjs/text-control/index.js +0 -61
  241. package/dist/esm/button/index.js +0 -48
  242. package/dist/esm/grid/index.js +0 -29
  243. package/dist/esm/hooks/index.js +0 -17
  244. package/dist/esm/hooks/usePrompt.js +0 -40
  245. package/dist/esm/text-control/index.js +0 -57
@@ -2,8 +2,8 @@
2
2
  * Web Preview
3
3
  */
4
4
 
5
- @use '../../../shared/scss/colors';
6
- @use '~@wordpress/base-styles/colors' as wp-colors;
5
+ @use "../../../shared/scss/colors";
6
+ @use "~@wordpress/base-styles/colors" as wp-colors;
7
7
 
8
8
  .newspack-web-preview {
9
9
  // Color
@@ -14,7 +14,7 @@
14
14
  --wp-admin-theme-color-darker-20: #{colors.$primary-700};
15
15
  --wp-admin-theme-color-darker-20--rgb: #{colors.$primary-700--rgb};
16
16
 
17
- background: rgba( black, 0.7 );
17
+ background: rgba(black, 0.7);
18
18
  box-sizing: border-box;
19
19
  height: 100%;
20
20
  left: 0;
@@ -54,7 +54,7 @@
54
54
 
55
55
  &__content {
56
56
  background: wp-colors.$gray-100;
57
- height: calc( 100% - 49px );
57
+ height: calc(100% - 49px);
58
58
  -webkit-overflow-scrolling: touch;
59
59
  overflow-x: hidden;
60
60
  width: 100%;
@@ -81,7 +81,7 @@
81
81
  margin: -12px 0 0;
82
82
  position: absolute;
83
83
  top: 50%;
84
- transform: translateX( -50% );
84
+ transform: translateX(-50%);
85
85
  }
86
86
 
87
87
  &__toolbar {
@@ -1,10 +1,8 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  /**
3
2
  * WordPress dependencies.
4
3
  */
5
4
  import { Component, createRef, Fragment } from '@wordpress/element';
6
- import { __ as alias__ } from '@wordpress/i18n';
7
- const __ = alias__;
5
+ import { __ } from '@wordpress/i18n';
8
6
  import apiFetch from '@wordpress/api-fetch';
9
7
  import { home } from '@wordpress/icons';
10
8
 
@@ -15,7 +13,7 @@ import { Button, Card, Modal, NewspackIcon, Notice, PluginInstaller } from '../'
15
13
  import Router from '../proxied-imports/router';
16
14
  import Footer from '../footer';
17
15
  import './style.scss';
18
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
16
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
17
  const {
20
18
  Redirect,
21
19
  Route
@@ -28,248 +26,259 @@ export default function withWizard(WrappedComponent, requiredPlugins) {
28
26
  return class WrappedWithWizard extends Component {
29
27
  constructor(props) {
30
28
  super(props);
31
- _defineProperty(this, "componentDidMount", () => {
32
- // If there are no requiredPlugins, fire onWizardReady as soon as component mounts.
33
- if (!requiredPlugins) {
34
- const instance = this.wrappedComponentRef.current;
35
- // eslint-disable-next-line no-unused-expressions
36
- instance && instance.onWizardReady && instance.onWizardReady();
37
- }
38
- });
39
- /**
40
- * Set the error. Called by Wizards when an error occurs.
41
- *
42
- * @return {Promise} Resolved after state update
43
- */
44
- _defineProperty(this, "setError", error => {
45
- return new Promise(resolve => {
46
- this.setState({
47
- error: error || null
48
- }, () => resolve());
49
- });
29
+ this.state = {
30
+ complete: null,
31
+ error: null,
32
+ loading: requiredPlugins && requiredPlugins.length > 0 ? 1 : 0,
33
+ quietLoading: false
34
+ };
35
+ this.wrappedComponentRef = createRef();
36
+ }
37
+ componentDidMount = () => {
38
+ // If there are no requiredPlugins, fire onWizardReady as soon as component mounts.
39
+ if (!requiredPlugins) {
40
+ const instance = this.wrappedComponentRef.current;
41
+ // eslint-disable-next-line no-unused-expressions
42
+ instance && instance.onWizardReady && instance.onWizardReady();
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Set the error. Called by Wizards when an error occurs.
48
+ *
49
+ * @return {Promise} Resolved after state update
50
+ */
51
+ setError = error => {
52
+ return new Promise(resolve => {
53
+ this.setState({
54
+ error: error || null
55
+ }, () => resolve());
50
56
  });
51
- /**
52
- * Render any errors that need rendering.
53
- *
54
- * @return {Component} Error UI
55
- */
56
- _defineProperty(this, "getError", () => {
57
- const {
58
- error
59
- } = this.state;
60
- if (!error) {
61
- return null;
62
- }
63
- const parsedError = this.parseError(error);
64
- const {
65
- level
66
- } = parsedError;
67
- if ('fatal' === level) {
68
- return this.getFatalError(parsedError);
69
- }
70
- return this.getErrorNotice(parsedError);
57
+ };
58
+
59
+ /**
60
+ * Render any errors that need rendering.
61
+ *
62
+ * @return {Component} Error UI
63
+ */
64
+ getError = () => {
65
+ const {
66
+ error
67
+ } = this.state;
68
+ if (!error) {
69
+ return null;
70
+ }
71
+ const parsedError = this.parseError(error);
72
+ const {
73
+ level
74
+ } = parsedError;
75
+ if ('fatal' === level) {
76
+ return this.getFatalError(parsedError);
77
+ }
78
+ return this.getErrorNotice(parsedError);
79
+ };
80
+
81
+ /**
82
+ * Get a notice-level error.
83
+ *
84
+ * @param {Error} error object already parsed by parseError
85
+ * @return {Component} Error notice
86
+ */
87
+ getErrorNotice = error => {
88
+ const {
89
+ message
90
+ } = error;
91
+ return /*#__PURE__*/_jsx(Notice, {
92
+ isError: true,
93
+ className: "newspack-wizard__above-header",
94
+ noticeText: message,
95
+ rawHTML: true
71
96
  });
72
- /**
73
- * Get a notice-level error.
74
- *
75
- * @param {Error} error object already parsed by parseError
76
- * @return {Component} Error notice
77
- */
78
- _defineProperty(this, "getErrorNotice", error => {
79
- const {
80
- message
81
- } = error;
82
- return _jsx(Notice, {
83
- isError: true,
84
- className: "newspack-wizard__above-header",
97
+ };
98
+
99
+ /**
100
+ * Get a fatal-level error.
101
+ *
102
+ * @param {Error} error object already parsed by parseError
103
+ * @return {Component} React object
104
+ */
105
+ getFatalError = error => {
106
+ const fallbackURL = this.getFallbackURL();
107
+ if (!fallbackURL) {
108
+ return null;
109
+ }
110
+ const {
111
+ message
112
+ } = error;
113
+ return /*#__PURE__*/_jsxs(Modal, {
114
+ title: __('Unrecoverable error'),
115
+ onRequestClose: () => window.location = fallbackURL,
116
+ children: [/*#__PURE__*/_jsx(Notice, {
85
117
  noticeText: message,
118
+ isError: true,
86
119
  rawHTML: true
87
- });
88
- });
89
- /**
90
- * Get a fatal-level error.
91
- *
92
- * @param {Error} error object already parsed by parseError
93
- * @return {Component} React object
94
- */
95
- _defineProperty(this, "getFatalError", error => {
96
- const fallbackURL = this.getFallbackURL();
97
- if (!fallbackURL) {
98
- return null;
99
- }
100
- const {
101
- message
102
- } = error;
103
- return _jsxs(Modal, {
104
- title: __('Unrecoverable error'),
105
- onRequestClose: () => window.location = fallbackURL,
106
- children: [_jsx(Notice, {
107
- noticeText: message,
108
- isError: true,
109
- rawHTML: true
110
- }), _jsx(Card, {
111
- buttonsCard: true,
112
- noBorder: true,
113
- className: "justify-end",
114
- children: _jsx(Button, {
115
- isPrimary: true,
116
- href: fallbackURL,
117
- children: __('Return to Dashboard', 'newspack-plugin')
118
- })
119
- })]
120
- });
121
- });
122
- /**
123
- * Get all the relevant info out of a raw API error response.
124
- *
125
- * @param {Object} error error object
126
- * @return {Object} Error object with relevant fields and defaults
127
- */
128
- _defineProperty(this, "parseError", error => {
129
- const {
130
- data,
131
- message,
132
- code
133
- } = error;
134
- let level = 'fatal';
135
- if (!!data && 'level' in data) {
136
- level = data.level;
137
- } else if ('rest_invalid_param' === code) {
138
- level = 'notice';
139
- }
140
- return {
141
- message,
142
- level
143
- };
120
+ }), /*#__PURE__*/_jsx(Card, {
121
+ buttonsCard: true,
122
+ noBorder: true,
123
+ className: "justify-end",
124
+ children: /*#__PURE__*/_jsx(Button, {
125
+ isPrimary: true,
126
+ href: fallbackURL,
127
+ children: __('Return to Dashboard', 'newspack-plugin')
128
+ })
129
+ })]
144
130
  });
145
- /**
146
- * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
147
- */
148
- _defineProperty(this, "pluginInstallationStatus", ({
131
+ };
132
+
133
+ /**
134
+ * Get all the relevant info out of a raw API error response.
135
+ *
136
+ * @param {Object} error error object
137
+ * @return {Object} Error object with relevant fields and defaults
138
+ */
139
+ parseError = error => {
140
+ const {
141
+ data,
142
+ message,
143
+ code
144
+ } = error;
145
+ let level = 'fatal';
146
+ if (!!data && 'level' in data) {
147
+ level = data.level;
148
+ } else if ('rest_invalid_param' === code) {
149
+ level = 'notice';
150
+ }
151
+ return {
152
+ message,
153
+ level
154
+ };
155
+ };
156
+
157
+ /**
158
+ * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
159
+ */
160
+ pluginInstallationStatus = ({
161
+ complete
162
+ }) => {
163
+ if (this.state.loading) {
164
+ this.doneLoading();
165
+ }
166
+ const instance = this.wrappedComponentRef.current;
167
+ this.setState({
149
168
  complete
150
- }) => {
151
- if (this.state.loading) {
152
- this.doneLoading();
153
- }
154
- const instance = this.wrappedComponentRef.current;
155
- this.setState({
156
- complete
157
- }, () => {
158
- // eslint-disable-next-line no-unused-expressions
159
- complete && instance && instance.onWizardReady && instance.onWizardReady();
160
- });
169
+ }, () => {
170
+ // eslint-disable-next-line no-unused-expressions
171
+ complete && instance && instance.onWizardReady && instance.onWizardReady();
161
172
  });
162
- /**
163
- * Begin loading.
164
- */
165
- _defineProperty(this, "startLoading", quiet => {
166
- if (quiet) {
167
- this.setState(state => ({
168
- quietLoading: state.quietLoading + 1
169
- }));
170
- } else {
171
- this.setState(state => ({
172
- loading: state.loading + 1
173
- }));
174
- }
175
- });
176
- /**
177
- * End loading.
178
- */
179
- _defineProperty(this, "doneLoading", 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
- * Replacement for core apiFetch that automatically manages wizard loading UI.
192
- */
193
- _defineProperty(this, "wizardApiFetch", args => {
194
- const {
195
- quiet
196
- } = args;
197
- this.startLoading(quiet);
198
- return new Promise((resolve, reject) => {
199
- apiFetch(args).then(response => {
200
- this.doneLoading(quiet);
201
- resolve(response);
202
- }).catch(error => {
203
- this.doneLoading(quiet);
204
- reject(error);
205
- });
173
+ };
174
+
175
+ /**
176
+ * Begin loading.
177
+ */
178
+ startLoading = quiet => {
179
+ if (quiet) {
180
+ this.setState(state => ({
181
+ quietLoading: state.quietLoading + 1
182
+ }));
183
+ } else {
184
+ this.setState(state => ({
185
+ loading: state.loading + 1
186
+ }));
187
+ }
188
+ };
189
+
190
+ /**
191
+ * End loading.
192
+ */
193
+ doneLoading = quiet => {
194
+ if (quiet) {
195
+ this.setState(state => ({
196
+ quietLoading: state.quietLoading - 1
197
+ }));
198
+ } else {
199
+ this.setState(state => ({
200
+ loading: state.loading - 1
201
+ }));
202
+ }
203
+ };
204
+
205
+ /**
206
+ * Replacement for core apiFetch that automatically manages wizard loading UI.
207
+ */
208
+ wizardApiFetch = args => {
209
+ const {
210
+ quiet
211
+ } = args;
212
+ this.startLoading(quiet);
213
+ return new Promise((resolve, reject) => {
214
+ apiFetch(args).then(response => {
215
+ this.doneLoading(quiet);
216
+ resolve(response);
217
+ }).catch(error => {
218
+ this.doneLoading(quiet);
219
+ reject(error);
206
220
  });
207
221
  });
208
- /**
209
- * Render a Route that checks for plugin installation requirements, and redirects to '/' when all are done.
210
- *
211
- * @return {void}
212
- */
213
- _defineProperty(this, "pluginRequirements", () => {
214
- const {
215
- complete
216
- } = this.state;
217
- /* After all plugins are loaded, redirect to / (this could be configurable) */
218
- if (complete) {
219
- return _jsx(Redirect, {
220
- from: "/plugin-requirements",
221
- to: "/"
222
- });
223
- }
224
- return _jsx(Route, {
225
- path: "/",
226
- render: () => _jsxs(Fragment, {
227
- children: [complete !== null && _jsx("div", {
228
- className: "newspack-wizard__header",
229
- children: _jsx("div", {
230
- className: "newspack-wizard__header__inner",
231
- children: _jsxs("div", {
232
- className: "newspack-wizard__title",
233
- children: [_jsx(Button, {
234
- isLink: true,
235
- href: newspack_urls.dashboard,
236
- label: __('Return to Dashboard', 'newspack-plugin'),
237
- showTooltip: true,
238
- icon: home,
239
- iconSize: 36,
240
- children: _jsx(NewspackIcon, {
241
- size: 36
242
- })
243
- }), _jsx("div", {
244
- children: _jsx("h2", {
245
- children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack-plugin') : __('Required plugin', 'newspack-plugin')
246
- })
247
- })]
248
- })
249
- })
250
- }), _jsx("div", {
251
- className: "newspack-wizard newspack-wizard__content",
252
- children: _jsx(PluginInstaller, {
253
- plugins: requiredPlugins,
254
- onStatus: status => this.pluginInstallationStatus(status)
255
- })
256
- })]
257
- })
222
+ };
223
+
224
+ /**
225
+ * Render a Route that checks for plugin installation requirements, and redirects to '/' when all are done.
226
+ *
227
+ * @return {void}
228
+ */
229
+ pluginRequirements = () => {
230
+ const {
231
+ complete
232
+ } = this.state;
233
+ /* After all plugins are loaded, redirect to / (this could be configurable) */
234
+ if (complete) {
235
+ return /*#__PURE__*/_jsx(Redirect, {
236
+ from: "/plugin-requirements",
237
+ to: "/"
258
238
  });
239
+ }
240
+ return /*#__PURE__*/_jsx(Route, {
241
+ path: "/",
242
+ render: () => /*#__PURE__*/_jsxs(Fragment, {
243
+ children: [complete !== null && /*#__PURE__*/_jsx("div", {
244
+ className: "newspack-wizard__header",
245
+ children: /*#__PURE__*/_jsx("div", {
246
+ className: "newspack-wizard__header__inner",
247
+ children: /*#__PURE__*/_jsxs("div", {
248
+ className: "newspack-wizard__title",
249
+ children: [/*#__PURE__*/_jsx(Button, {
250
+ isLink: true,
251
+ href: newspack_urls.dashboard,
252
+ label: __('Return to Dashboard', 'newspack-plugin'),
253
+ showTooltip: true,
254
+ icon: home,
255
+ iconSize: 36,
256
+ children: /*#__PURE__*/_jsx(NewspackIcon, {
257
+ size: 36
258
+ })
259
+ }), /*#__PURE__*/_jsx("div", {
260
+ children: /*#__PURE__*/_jsx("h2", {
261
+ children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack-plugin') : __('Required plugin', 'newspack-plugin')
262
+ })
263
+ })]
264
+ })
265
+ })
266
+ }), /*#__PURE__*/_jsx("div", {
267
+ className: "newspack-wizard newspack-wizard__content",
268
+ children: /*#__PURE__*/_jsx(PluginInstaller, {
269
+ plugins: requiredPlugins,
270
+ onStatus: status => this.pluginInstallationStatus(status)
271
+ })
272
+ })]
273
+ })
259
274
  });
260
- _defineProperty(this, "getFallbackURL", () => {
261
- if (typeof newspack_urls !== 'undefined') {
262
- return newspack_urls.dashboard;
263
- }
264
- });
265
- this.state = {
266
- complete: null,
267
- error: null,
268
- loading: requiredPlugins && requiredPlugins.length > 0 ? 1 : 0,
269
- quietLoading: false
270
- };
271
- this.wrappedComponentRef = createRef();
272
- }
275
+ };
276
+ getFallbackURL = () => {
277
+ if (typeof newspack_urls !== 'undefined') {
278
+ return newspack_urls.dashboard;
279
+ }
280
+ };
281
+
273
282
  /**
274
283
  * Render.
275
284
  */
@@ -286,10 +295,10 @@ export default function withWizard(WrappedComponent, requiredPlugins) {
286
295
  if (quietLoading) {
287
296
  loadingClasses.push('newspack-wizard__is-loading-quiet');
288
297
  }
289
- return _jsxs(Fragment, {
290
- children: [this.getError(), _jsx("div", {
298
+ return /*#__PURE__*/_jsxs(Fragment, {
299
+ children: [this.getError(), /*#__PURE__*/_jsx("div", {
291
300
  className: loadingClasses.join(' '),
292
- children: _jsx(WrappedComponent, {
301
+ children: /*#__PURE__*/_jsx(WrappedComponent, {
293
302
  pluginRequirements: requiredPlugins && this.pluginRequirements(),
294
303
  clearError: this.clearError,
295
304
  getError: this.getError,
@@ -302,7 +311,7 @@ export default function withWizard(WrappedComponent, requiredPlugins) {
302
311
  ref: this.wrappedComponentRef,
303
312
  ...this.props
304
313
  })
305
- }), !loading && _jsx(Footer, {
314
+ }), !loading && /*#__PURE__*/_jsx(Footer, {
306
315
  simple: simpleFooter
307
316
  })]
308
317
  });