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