newspack-components 2.2.1 → 3.0.0-alpha.2

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 (308) hide show
  1. package/babel.config.js +25 -0
  2. package/copy-styles.js +2 -10
  3. package/dist/{cjs/accordion → accordion}/index.js +17 -13
  4. package/dist/{cjs/accordion → accordion}/style.scss +7 -3
  5. package/dist/{cjs/action-card → action-card}/index.js +39 -43
  6. package/dist/{esm/action-card → action-card}/style.scss +9 -9
  7. package/dist/{cjs/autocomplete-tokenfield → autocomplete-tokenfield}/index.js +67 -29
  8. package/dist/{esm/autocomplete-tokenfield → autocomplete-tokenfield}/style.scss +14 -8
  9. package/dist/{cjs/autocomplete-with-suggestions → autocomplete-with-suggestions}/index.js +61 -73
  10. package/dist/{esm/autocomplete-with-suggestions → autocomplete-with-suggestions}/style.scss +9 -17
  11. package/dist/button/index.js +51 -0
  12. package/{src/button/index.js → dist/button/index.tsx} +12 -5
  13. package/dist/{cjs/button → button}/style.scss +1 -1
  14. package/dist/{cjs/button-card → button-card}/index.js +9 -10
  15. package/dist/{cjs/button-card → button-card}/style.scss +19 -13
  16. package/dist/{cjs/card → card}/index.js +4 -5
  17. package/dist/{esm/card → card}/style.scss +1 -1
  18. package/dist/{cjs/category-autocomplete → category-autocomplete}/index.js +51 -53
  19. package/dist/{esm/category-autocomplete → category-autocomplete}/style.scss +2 -2
  20. package/dist/{cjs/color-picker → color-picker}/index.js +14 -16
  21. package/dist/{cjs/color-picker → color-picker}/style.scss +3 -3
  22. package/dist/consts.js +7 -0
  23. package/dist/{cjs/custom-select-control → custom-select-control}/index.js +4 -5
  24. package/dist/{cjs/custom-select-control → custom-select-control}/style.scss +11 -10
  25. package/dist/{cjs/date-range-picker → date-range-picker}/index.js +9 -11
  26. package/dist/{cjs/date-range-picker → date-range-picker}/style.scss +6 -6
  27. package/dist/{cjs/footer → footer}/index.js +33 -36
  28. package/dist/{cjs/footer → footer}/style.scss +1 -1
  29. package/dist/{cjs/form-token-field → form-token-field}/index.js +6 -7
  30. package/dist/{esm/form-token-field → form-token-field}/style.scss +1 -1
  31. package/dist/{cjs/global-notices → global-notices}/index.js +4 -5
  32. package/dist/grid/index.js +44 -0
  33. package/dist/grid/index.tsx +34 -0
  34. package/dist/{cjs/grid → grid}/style.scss +9 -9
  35. package/dist/{cjs/handoff → handoff}/index.js +73 -71
  36. package/dist/{cjs/handoff-message → handoff-message}/index.js +5 -3
  37. package/dist/hooks/index.js +29 -0
  38. package/{src/hooks/index.js → dist/hooks/index.ts} +1 -1
  39. package/dist/{cjs/hooks → hooks}/useObjectState.js +2 -3
  40. package/dist/{cjs/hooks → hooks}/useObjectState.test.js +9 -9
  41. package/dist/{cjs/hooks → hooks}/useOnClickOutside.js +1 -2
  42. package/dist/hooks/usePrompt.js +47 -0
  43. package/{src/hooks/usePrompt.js → dist/hooks/usePrompt.ts} +4 -8
  44. package/dist/image-upload/index.js +148 -0
  45. package/dist/{cjs/image-upload → image-upload}/index.test.js +13 -6
  46. package/dist/{esm/image-upload → image-upload}/style.scss +5 -5
  47. package/dist/{cjs/index.js → index.js} +1 -1
  48. package/dist/{cjs/info-button → info-button}/index.js +6 -7
  49. package/dist/{cjs/modal → modal}/index.js +4 -5
  50. package/dist/{esm/modal → modal}/style.scss +5 -5
  51. package/dist/{cjs/newspack-icon → newspack-icon}/index.js +5 -6
  52. package/dist/{cjs/newspack-icon → newspack-icon}/style.scss +1 -1
  53. package/dist/{cjs/newspack-logo → newspack-logo}/index.js +5 -6
  54. package/dist/{cjs/newspack-logo → newspack-logo}/style.scss +1 -1
  55. package/dist/{cjs/notice → notice}/index.js +12 -10
  56. package/dist/{cjs/notice → notice}/style.scss +11 -11
  57. package/dist/patrons-logo/index.js +77 -0
  58. package/dist/plugin-installer/index.js +297 -0
  59. package/dist/{cjs/plugin-installer → plugin-installer}/style.scss +1 -1
  60. package/dist/{cjs/plugin-settings → plugin-settings}/SettingsSection.js +13 -13
  61. package/dist/plugin-settings/index.js +228 -0
  62. package/dist/{cjs/plugin-settings → plugin-settings}/style.scss +1 -1
  63. package/dist/plugin-toggle/README.md +53 -0
  64. package/dist/plugin-toggle/index.js +222 -0
  65. package/dist/{esm/plugin-toggle → plugin-toggle}/style.scss +1 -1
  66. package/dist/{cjs/popover → popover}/index.js +4 -5
  67. package/dist/{cjs/popover → popover}/style.scss +7 -7
  68. package/dist/{cjs/position-control → position-control}/index.js +33 -32
  69. package/dist/{cjs/position-control → position-control}/style.scss +8 -8
  70. package/dist/{cjs/progress-bar → progress-bar}/index.js +9 -10
  71. package/dist/{cjs/progress-bar → progress-bar}/index.test.js +16 -16
  72. package/dist/{cjs/progress-bar → progress-bar}/style.scss +2 -2
  73. package/dist/proxied-imports/router.js +15 -0
  74. package/dist/{cjs/radio-control → radio-control}/index.js +4 -5
  75. package/dist/{cjs/radio-control → radio-control}/style.scss +3 -3
  76. package/dist/{cjs/section-header → section-header}/index.js +20 -21
  77. package/dist/{esm/section-header → section-header}/style.scss +5 -1
  78. package/dist/{cjs/select-control → select-control}/ButtonGroupControl.js +17 -19
  79. package/dist/{cjs/select-control → select-control}/GroupedSelectControl.js +32 -35
  80. package/dist/{cjs/select-control → select-control}/index.js +7 -8
  81. package/dist/{cjs/select-control → select-control}/style.scss +4 -4
  82. package/dist/settings/MinMaxSetting.js +60 -0
  83. package/dist/{cjs/settings → settings}/SettingsCard.js +14 -16
  84. package/dist/settings/SettingsSection.js +33 -0
  85. package/dist/{cjs/settings → settings}/index.js +3 -4
  86. package/dist/{cjs/settings → settings}/style.scss +15 -2
  87. package/dist/sortable-newsletter-list-control/index.js +135 -0
  88. package/dist/sortable-newsletter-list-control/style.scss +45 -0
  89. package/dist/{cjs/steps-list → steps-list}/index.js +5 -6
  90. package/dist/{esm/steps-list → steps-list}/style.scss +2 -2
  91. package/dist/{cjs/steps-list-item → steps-list-item}/index.js +6 -7
  92. package/dist/{cjs/steps-list-item → steps-list-item}/style.scss +5 -5
  93. package/dist/{cjs/style-card → style-card}/index.js +21 -19
  94. package/dist/{esm/style-card → style-card}/style.scss +4 -4
  95. package/dist/{esm/style.scss → style.scss} +14 -2
  96. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/index.js +16 -19
  97. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/style.scss +4 -4
  98. package/dist/text-control/index.js +76 -0
  99. package/dist/text-control/index.tsx +71 -0
  100. package/dist/utils/index.js +36 -0
  101. package/dist/{cjs/waiting → waiting}/index.js +4 -5
  102. package/dist/web-preview/index.js +191 -0
  103. package/dist/{cjs/web-preview → web-preview}/style.scss +5 -5
  104. package/dist/with-wizard/index.js +328 -0
  105. package/dist/{esm/with-wizard → with-wizard}/style.scss +44 -22
  106. package/dist/{cjs/with-wizard-screen → with-wizard-screen}/index.js +40 -43
  107. package/dist/{esm/with-wizard-screen → with-wizard-screen}/style.scss +7 -7
  108. package/dist/{cjs/wizard → wizard}/components/WizardError.js +16 -17
  109. package/dist/{cjs/wizard → wizard}/index.js +44 -46
  110. package/dist/{cjs/wizard → wizard}/store/index.js +37 -38
  111. package/dist/{cjs/wizard → wizard}/store/utils.js +1 -4
  112. package/package.json +16 -14
  113. package/shared/scss/_mixins.scss +2 -2
  114. package/src/accordion/index.js +4 -1
  115. package/src/accordion/style.scss +7 -3
  116. package/src/action-card/style.scss +9 -9
  117. package/src/autocomplete-tokenfield/index.js +48 -15
  118. package/src/autocomplete-tokenfield/style.scss +14 -8
  119. package/src/autocomplete-with-suggestions/index.js +59 -62
  120. package/src/autocomplete-with-suggestions/style.scss +9 -17
  121. package/src/button/index.tsx +48 -0
  122. package/src/button/style.scss +1 -1
  123. package/src/button-card/style.scss +19 -13
  124. package/src/card/style.scss +1 -1
  125. package/src/category-autocomplete/style.scss +2 -2
  126. package/src/color-picker/style.scss +3 -3
  127. package/src/consts.js +0 -2
  128. package/src/custom-select-control/style.scss +11 -10
  129. package/src/date-range-picker/style.scss +6 -6
  130. package/src/footer/index.js +7 -7
  131. package/src/footer/style.scss +1 -1
  132. package/src/form-token-field/style.scss +1 -1
  133. package/src/grid/index.tsx +34 -0
  134. package/src/grid/style.scss +9 -9
  135. package/src/handoff/index.js +7 -6
  136. package/src/handoff-message/index.js +3 -1
  137. package/src/hooks/index.ts +15 -0
  138. package/src/hooks/usePrompt.ts +46 -0
  139. package/src/image-upload/index.js +5 -5
  140. package/src/image-upload/index.test.js +6 -1
  141. package/src/image-upload/style.scss +5 -5
  142. package/src/modal/style.scss +5 -5
  143. package/src/newspack-icon/style.scss +1 -1
  144. package/src/newspack-logo/style.scss +1 -1
  145. package/src/notice/index.js +1 -1
  146. package/src/notice/style.scss +11 -11
  147. package/src/patrons-logo/index.js +4 -1
  148. package/src/plugin-installer/index.js +7 -7
  149. package/src/plugin-installer/style.scss +1 -1
  150. package/src/plugin-settings/index.js +1 -1
  151. package/src/plugin-settings/style.scss +1 -1
  152. package/src/plugin-toggle/index.js +13 -12
  153. package/src/plugin-toggle/style.scss +1 -1
  154. package/src/popover/style.scss +7 -7
  155. package/src/position-control/index.js +63 -64
  156. package/src/position-control/style.scss +8 -8
  157. package/src/progress-bar/style.scss +2 -2
  158. package/src/radio-control/style.scss +3 -3
  159. package/src/section-header/index.js +3 -3
  160. package/src/section-header/style.scss +5 -1
  161. package/src/select-control/GroupedSelectControl.js +1 -1
  162. package/src/select-control/style.scss +4 -4
  163. package/src/settings/MinMaxSetting.js +8 -6
  164. package/src/settings/style.scss +15 -2
  165. package/src/sortable-newsletter-list-control/index.js +137 -0
  166. package/src/sortable-newsletter-list-control/style.scss +45 -0
  167. package/src/steps-list/style.scss +2 -2
  168. package/src/steps-list-item/style.scss +5 -5
  169. package/src/style-card/index.js +11 -5
  170. package/src/style-card/style.scss +4 -4
  171. package/src/style.scss +14 -2
  172. package/src/tabbed-navigation/style.scss +4 -4
  173. package/src/text-control/index.tsx +65 -0
  174. package/src/web-preview/index.js +6 -6
  175. package/src/web-preview/style.scss +5 -5
  176. package/src/with-wizard/index.js +4 -4
  177. package/src/with-wizard/style.scss +44 -22
  178. package/src/with-wizard-screen/index.js +1 -1
  179. package/src/with-wizard-screen/style.scss +7 -7
  180. package/src/wizard/components/WizardError.js +1 -1
  181. package/src/wizard/index.js +3 -3
  182. package/src/wizard/store/index.js +9 -2
  183. package/dist/cjs/action-card/style.scss +0 -483
  184. package/dist/cjs/autocomplete-tokenfield/style.scss +0 -43
  185. package/dist/cjs/autocomplete-with-suggestions/style.scss +0 -171
  186. package/dist/cjs/button/index.js +0 -57
  187. package/dist/cjs/card/style.scss +0 -168
  188. package/dist/cjs/category-autocomplete/style.scss +0 -34
  189. package/dist/cjs/consts.js +0 -12
  190. package/dist/cjs/form-token-field/style.scss +0 -37
  191. package/dist/cjs/grid/index.js +0 -54
  192. package/dist/cjs/hooks/index.js +0 -26
  193. package/dist/cjs/hooks/usePrompt.js +0 -52
  194. package/dist/cjs/image-upload/index.js +0 -144
  195. package/dist/cjs/image-upload/style.scss +0 -103
  196. package/dist/cjs/modal/style.scss +0 -56
  197. package/dist/cjs/patrons-logo/index.js +0 -82
  198. package/dist/cjs/plugin-installer/index.js +0 -299
  199. package/dist/cjs/plugin-settings/index.js +0 -222
  200. package/dist/cjs/plugin-toggle/index.js +0 -222
  201. package/dist/cjs/plugin-toggle/style.scss +0 -20
  202. package/dist/cjs/proxied-imports/router.js +0 -15
  203. package/dist/cjs/section-header/style.scss +0 -41
  204. package/dist/cjs/settings/MinMaxSetting.js +0 -57
  205. package/dist/cjs/settings/SettingsSection.js +0 -37
  206. package/dist/cjs/steps-list/style.scss +0 -11
  207. package/dist/cjs/style-card/style.scss +0 -94
  208. package/dist/cjs/style.scss +0 -43
  209. package/dist/cjs/text-control/index.js +0 -71
  210. package/dist/cjs/utils/index.js +0 -40
  211. package/dist/cjs/web-preview/index.js +0 -189
  212. package/dist/cjs/with-wizard/index.js +0 -318
  213. package/dist/cjs/with-wizard/style.scss +0 -260
  214. package/dist/cjs/with-wizard-screen/style.scss +0 -160
  215. package/dist/esm/accordion/index.js +0 -38
  216. package/dist/esm/accordion/style.scss +0 -27
  217. package/dist/esm/action-card/index.js +0 -222
  218. package/dist/esm/autocomplete-tokenfield/index.js +0 -223
  219. package/dist/esm/autocomplete-with-suggestions/index.js +0 -289
  220. package/dist/esm/button/index.js +0 -48
  221. package/dist/esm/button/style.scss +0 -11
  222. package/dist/esm/button-card/index.js +0 -65
  223. package/dist/esm/button-card/style.scss +0 -174
  224. package/dist/esm/card/index.js +0 -43
  225. package/dist/esm/category-autocomplete/index.js +0 -185
  226. package/dist/esm/color-picker/index.js +0 -61
  227. package/dist/esm/color-picker/style.scss +0 -37
  228. package/dist/esm/consts.js +0 -3
  229. package/dist/esm/custom-select-control/index.js +0 -37
  230. package/dist/esm/custom-select-control/style.scss +0 -92
  231. package/dist/esm/date-range-picker/index.js +0 -32
  232. package/dist/esm/date-range-picker/style.scss +0 -148
  233. package/dist/esm/footer/index.js +0 -105
  234. package/dist/esm/footer/style.scss +0 -82
  235. package/dist/esm/form-token-field/index.js +0 -50
  236. package/dist/esm/global-notices/index.js +0 -30
  237. package/dist/esm/grid/index.js +0 -45
  238. package/dist/esm/grid/style.scss +0 -166
  239. package/dist/esm/handoff/index.js +0 -177
  240. package/dist/esm/handoff-message/index.js +0 -45
  241. package/dist/esm/hooks/index.js +0 -17
  242. package/dist/esm/hooks/useObjectState.js +0 -31
  243. package/dist/esm/hooks/useObjectState.test.js +0 -83
  244. package/dist/esm/hooks/useOnClickOutside.js +0 -31
  245. package/dist/esm/hooks/usePrompt.js +0 -43
  246. package/dist/esm/image-upload/index.js +0 -141
  247. package/dist/esm/image-upload/index.test.js +0 -28
  248. package/dist/esm/index.js +0 -47
  249. package/dist/esm/info-button/index.js +0 -42
  250. package/dist/esm/info-button/style.scss +0 -18
  251. package/dist/esm/modal/index.js +0 -39
  252. package/dist/esm/newspack-icon/index.js +0 -50
  253. package/dist/esm/newspack-icon/style.scss +0 -26
  254. package/dist/esm/newspack-logo/index.js +0 -46
  255. package/dist/esm/newspack-logo/style.scss +0 -30
  256. package/dist/esm/notice/index.js +0 -67
  257. package/dist/esm/notice/style.scss +0 -111
  258. package/dist/esm/patrons-logo/index.js +0 -76
  259. package/dist/esm/plugin-installer/index.js +0 -295
  260. package/dist/esm/plugin-installer/style.scss +0 -72
  261. package/dist/esm/plugin-settings/SettingsSection.js +0 -136
  262. package/dist/esm/plugin-settings/index.js +0 -217
  263. package/dist/esm/plugin-settings/style.scss +0 -7
  264. package/dist/esm/plugin-toggle/index.js +0 -217
  265. package/dist/esm/popover/index.js +0 -41
  266. package/dist/esm/popover/style.scss +0 -161
  267. package/dist/esm/position-control/index.js +0 -109
  268. package/dist/esm/position-control/style.scss +0 -66
  269. package/dist/esm/progress-bar/index.js +0 -69
  270. package/dist/esm/progress-bar/index.test.js +0 -110
  271. package/dist/esm/progress-bar/style.scss +0 -42
  272. package/dist/esm/proxied-imports/router.js +0 -8
  273. package/dist/esm/radio-control/index.js +0 -37
  274. package/dist/esm/radio-control/style.scss +0 -92
  275. package/dist/esm/section-header/index.js +0 -68
  276. package/dist/esm/select-control/ButtonGroupControl.js +0 -54
  277. package/dist/esm/select-control/GroupedSelectControl.js +0 -84
  278. package/dist/esm/select-control/index.js +0 -51
  279. package/dist/esm/select-control/style.scss +0 -108
  280. package/dist/esm/settings/MinMaxSetting.js +0 -53
  281. package/dist/esm/settings/SettingsCard.js +0 -39
  282. package/dist/esm/settings/SettingsSection.js +0 -30
  283. package/dist/esm/settings/index.js +0 -9
  284. package/dist/esm/settings/style.scss +0 -106
  285. package/dist/esm/steps-list/index.js +0 -43
  286. package/dist/esm/steps-list-item/index.js +0 -48
  287. package/dist/esm/steps-list-item/style.scss +0 -47
  288. package/dist/esm/style-card/index.js +0 -76
  289. package/dist/esm/tabbed-navigation/index.js +0 -56
  290. package/dist/esm/tabbed-navigation/style.scss +0 -86
  291. package/dist/esm/text-control/index.js +0 -66
  292. package/dist/esm/text-control/style.scss +0 -32
  293. package/dist/esm/utils/index.js +0 -32
  294. package/dist/esm/waiting/index.js +0 -44
  295. package/dist/esm/waiting/style.scss +0 -27
  296. package/dist/esm/web-preview/index.js +0 -184
  297. package/dist/esm/web-preview/style.scss +0 -155
  298. package/dist/esm/with-wizard/index.js +0 -313
  299. package/dist/esm/with-wizard-screen/index.js +0 -116
  300. package/dist/esm/wizard/components/WizardError.js +0 -69
  301. package/dist/esm/wizard/index.js +0 -126
  302. package/dist/esm/wizard/store/index.js +0 -155
  303. package/dist/esm/wizard/store/utils.js +0 -17
  304. package/src/grid/index.js +0 -44
  305. package/src/text-control/index.js +0 -56
  306. /package/dist/{cjs/info-button → info-button}/style.scss +0 -0
  307. /package/dist/{cjs/text-control → text-control}/style.scss +0 -0
  308. /package/dist/{cjs/waiting → waiting}/style.scss +0 -0
@@ -1,313 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /**
3
- * WordPress dependencies.
4
- */
5
- import { Component, createRef, Fragment } from '@wordpress/element';
6
- import { __ as alias__ } from '@wordpress/i18n';
7
- const __ = alias__;
8
- import apiFetch from '@wordpress/api-fetch';
9
- import { home } from '@wordpress/icons';
10
-
11
- /**
12
- * Internal dependencies.
13
- */
14
- import { Button, Card, Modal, NewspackIcon, Notice, PluginInstaller } from '../';
15
- import Router from '../proxied-imports/router';
16
- import Footer from '../footer';
17
- import './style.scss';
18
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
19
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
20
- const {
21
- Redirect,
22
- Route
23
- } = Router;
24
-
25
- /**
26
- * Higher-Order Component to provide plugin management and error handling to Newspack Wizards.
27
- */
28
- export default function withWizard(WrappedComponent, requiredPlugins) {
29
- return class WrappedWithWizard extends Component {
30
- constructor(props) {
31
- super(props);
32
- _defineProperty(this, "componentDidMount", () => {
33
- // If there are no requiredPlugins, fire onWizardReady as soon as component mounts.
34
- if (!requiredPlugins) {
35
- const instance = this.wrappedComponentRef.current;
36
- // eslint-disable-next-line no-unused-expressions
37
- instance && instance.onWizardReady && instance.onWizardReady();
38
- }
39
- });
40
- /**
41
- * Set the error. Called by Wizards when an error occurs.
42
- *
43
- * @return {Promise} Resolved after state update
44
- */
45
- _defineProperty(this, "setError", error => {
46
- return new Promise(resolve => {
47
- this.setState({
48
- error: error || null
49
- }, () => resolve());
50
- });
51
- });
52
- /**
53
- * Render any errors that need rendering.
54
- *
55
- * @return {Component} Error UI
56
- */
57
- _defineProperty(this, "getError", () => {
58
- const {
59
- error
60
- } = this.state;
61
- if (!error) {
62
- return null;
63
- }
64
- const parsedError = this.parseError(error);
65
- const {
66
- level
67
- } = parsedError;
68
- if ('fatal' === level) {
69
- return this.getFatalError(parsedError);
70
- }
71
- return this.getErrorNotice(parsedError);
72
- });
73
- /**
74
- * Get a notice-level error.
75
- *
76
- * @param {Error} error object already parsed by parseError
77
- * @return {Component} Error notice
78
- */
79
- _defineProperty(this, "getErrorNotice", error => {
80
- const {
81
- message
82
- } = error;
83
- return _jsx(Notice, {
84
- isError: true,
85
- className: "newspack-wizard__above-header",
86
- noticeText: message,
87
- rawHTML: true
88
- });
89
- });
90
- /**
91
- * Get a fatal-level error.
92
- *
93
- * @param {Error} error object already parsed by parseError
94
- * @return {Component} React object
95
- */
96
- _defineProperty(this, "getFatalError", error => {
97
- const fallbackURL = this.getFallbackURL();
98
- if (!fallbackURL) {
99
- return null;
100
- }
101
- const {
102
- message
103
- } = error;
104
- return _jsxs(Modal, {
105
- title: __('Unrecoverable error'),
106
- onRequestClose: () => window.location = fallbackURL,
107
- children: [_jsx(Notice, {
108
- noticeText: message,
109
- isError: true,
110
- rawHTML: true
111
- }), _jsx(Card, {
112
- buttonsCard: true,
113
- noBorder: true,
114
- className: "justify-end",
115
- children: _jsx(Button, {
116
- isPrimary: true,
117
- href: fallbackURL,
118
- children: __('Return to Dashboard', 'newspack')
119
- })
120
- })]
121
- });
122
- });
123
- /**
124
- * Get all the relevant info out of a raw API error response.
125
- *
126
- * @param {Object} error error object
127
- * @return {Object} Error object with relevant fields and defaults
128
- */
129
- _defineProperty(this, "parseError", error => {
130
- const {
131
- data,
132
- message,
133
- code
134
- } = error;
135
- let level = 'fatal';
136
- if (!!data && 'level' in data) {
137
- level = data.level;
138
- } else if ('rest_invalid_param' === code) {
139
- level = 'notice';
140
- }
141
- return {
142
- message,
143
- level
144
- };
145
- });
146
- /**
147
- * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
148
- */
149
- _defineProperty(this, "pluginInstallationStatus", _ref => {
150
- let {
151
- complete
152
- } = _ref;
153
- if (this.state.loading) {
154
- this.doneLoading();
155
- }
156
- const instance = this.wrappedComponentRef.current;
157
- this.setState({
158
- complete
159
- }, () => {
160
- // eslint-disable-next-line no-unused-expressions
161
- complete && instance && instance.onWizardReady && instance.onWizardReady();
162
- });
163
- });
164
- /**
165
- * Begin loading.
166
- */
167
- _defineProperty(this, "startLoading", quiet => {
168
- if (quiet) {
169
- this.setState(state => ({
170
- quietLoading: state.quietLoading + 1
171
- }));
172
- } else {
173
- this.setState(state => ({
174
- loading: state.loading + 1
175
- }));
176
- }
177
- });
178
- /**
179
- * End loading.
180
- */
181
- _defineProperty(this, "doneLoading", quiet => {
182
- if (quiet) {
183
- this.setState(state => ({
184
- quietLoading: state.quietLoading - 1
185
- }));
186
- } else {
187
- this.setState(state => ({
188
- loading: state.loading - 1
189
- }));
190
- }
191
- });
192
- /**
193
- * Replacement for core apiFetch that automatically manages wizard loading UI.
194
- */
195
- _defineProperty(this, "wizardApiFetch", args => {
196
- const {
197
- quiet
198
- } = args;
199
- this.startLoading(quiet);
200
- return new Promise((resolve, reject) => {
201
- apiFetch(args).then(response => {
202
- this.doneLoading(quiet);
203
- resolve(response);
204
- }).catch(error => {
205
- this.doneLoading(quiet);
206
- reject(error);
207
- });
208
- });
209
- });
210
- /**
211
- * Render a Route that checks for plugin installation requirements, and redirects to '/' when all are done.
212
- *
213
- * @return {void}
214
- */
215
- _defineProperty(this, "pluginRequirements", () => {
216
- const {
217
- complete
218
- } = this.state;
219
- /* After all plugins are loaded, redirect to / (this could be configurable) */
220
- if (complete) {
221
- return _jsx(Redirect, {
222
- from: "/plugin-requirements",
223
- to: "/"
224
- });
225
- }
226
- return _jsx(Route, {
227
- path: "/",
228
- render: () => _jsxs(Fragment, {
229
- children: [complete !== null && _jsx("div", {
230
- className: "newspack-wizard__header",
231
- children: _jsx("div", {
232
- className: "newspack-wizard__header__inner",
233
- children: _jsxs("div", {
234
- className: "newspack-wizard__title",
235
- children: [_jsx(Button, {
236
- isLink: true,
237
- href: newspack_urls.dashboard,
238
- label: __('Return to Dashboard', 'newspack'),
239
- showTooltip: true,
240
- icon: home,
241
- iconSize: 36,
242
- children: _jsx(NewspackIcon, {
243
- size: 36
244
- })
245
- }), _jsx("div", {
246
- children: _jsx("h2", {
247
- children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack')
248
- })
249
- })]
250
- })
251
- })
252
- }), _jsx("div", {
253
- className: "newspack-wizard newspack-wizard__content",
254
- children: _jsx(PluginInstaller, {
255
- plugins: requiredPlugins,
256
- onStatus: status => this.pluginInstallationStatus(status)
257
- })
258
- })]
259
- })
260
- });
261
- });
262
- _defineProperty(this, "getFallbackURL", () => {
263
- if (typeof newspack_urls !== 'undefined') {
264
- return newspack_urls.dashboard;
265
- }
266
- });
267
- this.state = {
268
- complete: null,
269
- error: null,
270
- loading: requiredPlugins && requiredPlugins.length > 0 ? 1 : 0,
271
- quietLoading: false
272
- };
273
- this.wrappedComponentRef = createRef();
274
- }
275
- /**
276
- * Render.
277
- */
278
- render() {
279
- const {
280
- simpleFooter
281
- } = this.props;
282
- const {
283
- loading,
284
- quietLoading,
285
- error
286
- } = this.state;
287
- const loadingClasses = [loading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded'];
288
- if (quietLoading) {
289
- loadingClasses.push('newspack-wizard__is-loading-quiet');
290
- }
291
- return _jsxs(Fragment, {
292
- children: [this.getError(), _jsx("div", {
293
- className: loadingClasses.join(' '),
294
- children: _jsx(WrappedComponent, {
295
- pluginRequirements: requiredPlugins && this.pluginRequirements(),
296
- clearError: this.clearError,
297
- getError: this.getError,
298
- errorData: error,
299
- setError: this.setError,
300
- isLoading: loading,
301
- startLoading: this.startLoading,
302
- doneLoading: this.doneLoading,
303
- wizardApiFetch: this.wizardApiFetch,
304
- ref: this.wrappedComponentRef,
305
- ...this.props
306
- })
307
- }), !loading && _jsx(Footer, {
308
- simple: simpleFooter
309
- })]
310
- });
311
- }
312
- };
313
- }
@@ -1,116 +0,0 @@
1
- /**
2
- * WordPress dependencies.
3
- */
4
- import { __ as alias__ } from '@wordpress/i18n';
5
- const __ = alias__;
6
- import { category } from '@wordpress/icons';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { Button, Handoff, NewspackIcon, Notice, HandoffMessage, TabbedNavigation } from '../';
12
- import { buttonProps } from '../../../shared/js/';
13
- import './style.scss';
14
-
15
- /**
16
- * External dependencies
17
- */
18
- import classnames from 'classnames';
19
-
20
- /**
21
- * Higher-Order Component to provide plugin management and error handling to Newspack Wizards.
22
- */
23
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
24
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
25
- import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
26
- export default function withWizardScreen(WrappedComponent) {
27
- let {
28
- hidePrimaryButton
29
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
30
- const WrappedWithWizardScreen = props => {
31
- const {
32
- className,
33
- buttonText,
34
- buttonAction,
35
- buttonDisabled,
36
- headerText,
37
- subHeaderText,
38
- tabbedNavigation,
39
- secondaryButtonText,
40
- secondaryButtonAction,
41
- renderAboveContent,
42
- disableUpcomingInTabbedNavigation
43
- } = props;
44
- const retrievedButtonProps = buttonProps(buttonAction);
45
- const retrievedSecondaryButtonProps = buttonProps(secondaryButtonAction);
46
- const SecondaryCTAComponent = retrievedSecondaryButtonProps.plugin ? Handoff : Button;
47
- const shouldRenderPrimaryButton = buttonText && buttonAction;
48
- const shouldRenderSecondaryButton = secondaryButtonText && secondaryButtonAction;
49
- const renderPrimaryButton = function () {
50
- let overridingProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
51
- return retrievedButtonProps.plugin ? _jsx(Handoff, {
52
- isPrimary: true,
53
- ...retrievedButtonProps,
54
- ...overridingProps,
55
- children: buttonText
56
- }) : _jsx(Button, {
57
- isPrimary: !buttonDisabled,
58
- isSecondary: !!buttonDisabled,
59
- disabled: buttonDisabled
60
- // Allow overridingProps to set children.
61
- // eslint-disable-next-line react/no-children-prop
62
- ,
63
- children: buttonText,
64
- ...retrievedButtonProps,
65
- ...overridingProps
66
- });
67
- };
68
- return _jsxs(_Fragment, {
69
- children: [newspack_aux_data.is_debug_mode && _jsx(Notice, {
70
- debugMode: true
71
- }), _jsx("div", {
72
- className: "newspack-wizard__header",
73
- children: _jsx("div", {
74
- className: "newspack-wizard__header__inner",
75
- children: _jsxs("div", {
76
- className: "newspack-wizard__title",
77
- children: [_jsx(Button, {
78
- isLink: true,
79
- href: newspack_urls.dashboard,
80
- label: __('Return to Dashboard', 'newspack'),
81
- showTooltip: true,
82
- icon: category,
83
- iconSize: 36,
84
- children: _jsx(NewspackIcon, {
85
- size: 36
86
- })
87
- }), _jsxs("div", {
88
- children: [headerText && _jsx("h2", {
89
- children: headerText
90
- }), subHeaderText && _jsx("span", {
91
- children: subHeaderText
92
- })]
93
- })]
94
- })
95
- })
96
- }), tabbedNavigation && _jsx(TabbedNavigation, {
97
- disableUpcoming: disableUpcomingInTabbedNavigation,
98
- items: tabbedNavigation.filter(item => !item.isHiddenInNav)
99
- }), _jsx(HandoffMessage, {}), _jsxs("div", {
100
- className: classnames('newspack-wizard newspack-wizard__content', className),
101
- children: [typeof renderAboveContent === 'function' ? renderAboveContent() : null, _jsx(WrappedComponent, {
102
- ...props,
103
- renderPrimaryButton: renderPrimaryButton
104
- }), (shouldRenderPrimaryButton || shouldRenderSecondaryButton) && _jsxs("div", {
105
- className: "newspack-buttons-card",
106
- children: [shouldRenderPrimaryButton && !hidePrimaryButton && renderPrimaryButton(), shouldRenderSecondaryButton && _jsx(SecondaryCTAComponent, {
107
- isSecondary: true,
108
- ...retrievedSecondaryButtonProps,
109
- children: secondaryButtonText
110
- })]
111
- })]
112
- })]
113
- });
114
- };
115
- return WrappedWithWizardScreen;
116
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * WordPress dependencies.
3
- */
4
- import { __ as alias__ } from '@wordpress/i18n';
5
- const __ = alias__;
6
- import { useSelect } from '@wordpress/data';
7
-
8
- /**
9
- * Internal dependencies.
10
- */
11
- import { Button, Card, Modal, Notice } from '../..';
12
- import { WIZARD_STORE_NAMESPACE } from '../store';
13
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
14
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
15
- const parseError = _ref => {
16
- let {
17
- data,
18
- message,
19
- code
20
- } = _ref;
21
- let level = 'fatal';
22
- if (!!data && 'level' in data) {
23
- level = data.level;
24
- } else if ('rest_invalid_param' === code) {
25
- level = 'notice';
26
- }
27
- return {
28
- message,
29
- level
30
- };
31
- };
32
- const WizardError = () => {
33
- const error = useSelect(select => select(WIZARD_STORE_NAMESPACE).getError());
34
- if (!error) {
35
- return null;
36
- }
37
- const {
38
- level,
39
- message
40
- } = parseError(error);
41
- if ('fatal' === level) {
42
- const fallbackURL = typeof newspack_urls !== 'undefined' && newspack_urls.dashboard;
43
- return _jsxs(Modal, {
44
- title: __('Unrecoverable error'),
45
- onRequestClose: fallbackURL ? () => window.location = fallbackURL : undefined,
46
- children: [_jsx(Notice, {
47
- noticeText: message,
48
- isError: true,
49
- rawHTML: true
50
- }), fallbackURL && _jsx(Card, {
51
- buttonsCard: true,
52
- noBorder: true,
53
- className: "justify-end",
54
- children: _jsx(Button, {
55
- isPrimary: true,
56
- href: fallbackURL,
57
- children: __('Return to Dashboard', 'newspack')
58
- })
59
- })]
60
- });
61
- }
62
- return _jsx(Notice, {
63
- isError: true,
64
- className: "newspack-wizard__above-header",
65
- noticeText: message,
66
- rawHTML: true
67
- });
68
- };
69
- export default WizardError;
@@ -1,126 +0,0 @@
1
- /**
2
- * External dependencies.
3
- */
4
- import classnames from 'classnames';
5
-
6
- /**
7
- * WordPress dependencies.
8
- */
9
- import { useSelect } from '@wordpress/data';
10
- import { useState } from '@wordpress/element';
11
- import { __ as alias__ } from '@wordpress/i18n';
12
- const __ = alias__;
13
- import { category } from '@wordpress/icons';
14
-
15
- /**
16
- * Internal dependencies
17
- */
18
- import { Footer, Notice, Button, NewspackIcon, TabbedNavigation, PluginInstaller, HandoffMessage } from '../';
19
- import Router from '../proxied-imports/router';
20
- import registerStore, { WIZARD_STORE_NAMESPACE } from './store';
21
- import { useWizardData } from './store/utils';
22
- import WizardError from './components/WizardError';
23
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
24
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
25
- import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
26
- registerStore();
27
- const {
28
- HashRouter,
29
- Redirect,
30
- Route,
31
- Switch
32
- } = Router;
33
- const Wizard = _ref => {
34
- let {
35
- sections = [],
36
- apiSlug,
37
- headerText,
38
- subHeaderText,
39
- hasSimpleFooter,
40
- className,
41
- renderAboveSections,
42
- requiredPlugins = []
43
- } = _ref;
44
- const isLoading = useSelect(select => select(WIZARD_STORE_NAMESPACE).isLoading());
45
- const isQuietLoading = useSelect(select => select(WIZARD_STORE_NAMESPACE).isQuietLoading());
46
-
47
- // Trigger initial data fetch. Some sections might not use the wizard data,
48
- // but for consistency, fetching is triggered regardless of the section.
49
- useSelect(select => select(WIZARD_STORE_NAMESPACE).getWizardAPIData(apiSlug));
50
- let displayedSections = sections.filter(section => !section.isHidden);
51
- const [pluginRequirementsSatisfied, setPluginRequirementsSatisfied] = useState(requiredPlugins.length === 0);
52
- if (!pluginRequirementsSatisfied) {
53
- headerText = requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack');
54
- displayedSections = [{
55
- path: '/',
56
- render: () => _jsx(PluginInstaller, {
57
- plugins: requiredPlugins,
58
- onStatus: _ref2 => {
59
- let {
60
- complete
61
- } = _ref2;
62
- return setPluginRequirementsSatisfied(complete);
63
- }
64
- })
65
- }];
66
- }
67
- return _jsxs(_Fragment, {
68
- children: [_jsx("div", {
69
- className: classnames(isLoading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded', {
70
- 'newspack-wizard__is-loading-quiet': isQuietLoading
71
- }),
72
- children: _jsxs(HashRouter, {
73
- hashType: "slash",
74
- children: [newspack_aux_data.is_debug_mode && _jsx(Notice, {
75
- debugMode: true
76
- }), _jsx("div", {
77
- className: "bg-white",
78
- children: _jsx("div", {
79
- className: "newspack-wizard__header__inner",
80
- children: _jsxs("div", {
81
- className: "newspack-wizard__title",
82
- children: [_jsx(Button, {
83
- isLink: true,
84
- href: newspack_urls.dashboard,
85
- label: __('Return to Dashboard', 'newspack'),
86
- showTooltip: true,
87
- icon: category,
88
- iconSize: 36,
89
- children: _jsx(NewspackIcon, {
90
- size: 36
91
- })
92
- }), _jsxs("div", {
93
- children: [headerText && _jsx("h2", {
94
- children: headerText
95
- }), subHeaderText && _jsx("span", {
96
- children: subHeaderText
97
- })]
98
- })]
99
- })
100
- })
101
- }), displayedSections.length > 1 && _jsx(TabbedNavigation, {
102
- items: displayedSections,
103
- children: _jsx(WizardError, {})
104
- }), _jsx(HandoffMessage, {}), _jsxs(Switch, {
105
- children: [displayedSections.map((section, index) => {
106
- const SectionComponent = section.render;
107
- return _jsx(Route, {
108
- path: section.path,
109
- children: _jsxs("div", {
110
- className: classnames('newspack-wizard newspack-wizard__content', className),
111
- children: ['function' === typeof renderAboveSections ? renderAboveSections() : null, _jsx(SectionComponent, {})]
112
- })
113
- }, index);
114
- }), _jsx(Redirect, {
115
- to: displayedSections[0].path
116
- })]
117
- })]
118
- })
119
- }), !isLoading && _jsx(Footer, {
120
- simple: hasSimpleFooter
121
- })]
122
- });
123
- };
124
- Wizard.useWizardData = useWizardData;
125
- Wizard.STORE_NAMESPACE = WIZARD_STORE_NAMESPACE;
126
- export default Wizard;