newspack-components 2.1.0 → 2.2.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 (268) hide show
  1. package/dist/cjs/accordion/index.js +46 -0
  2. package/dist/cjs/accordion/style.scss +27 -0
  3. package/dist/cjs/action-card/index.js +48 -25
  4. package/dist/cjs/action-card/style.scss +100 -23
  5. package/dist/cjs/autocomplete-tokenfield/index.js +13 -41
  6. package/dist/cjs/autocomplete-tokenfield/style.scss +2 -2
  7. package/dist/cjs/autocomplete-with-suggestions/index.js +30 -51
  8. package/dist/cjs/autocomplete-with-suggestions/style.scss +16 -15
  9. package/dist/cjs/button/index.js +5 -13
  10. package/dist/cjs/button-card/index.js +1 -10
  11. package/dist/cjs/button-card/style.scss +13 -13
  12. package/dist/cjs/card/index.js +1 -8
  13. package/dist/cjs/card/style.scss +25 -8
  14. package/dist/cjs/category-autocomplete/index.js +18 -38
  15. package/dist/cjs/category-autocomplete/style.scss +0 -2
  16. package/dist/cjs/color-picker/index.js +1 -15
  17. package/dist/cjs/color-picker/style.scss +0 -3
  18. package/dist/cjs/consts.js +5 -3
  19. package/dist/cjs/custom-select-control/index.js +1 -9
  20. package/dist/cjs/custom-select-control/style.scss +6 -7
  21. package/dist/cjs/date-range-picker/index.js +1 -10
  22. package/dist/cjs/date-range-picker/style.scss +12 -12
  23. package/dist/cjs/footer/index.js +5 -17
  24. package/dist/cjs/footer/style.scss +5 -5
  25. package/dist/cjs/form-token-field/index.js +1 -9
  26. package/dist/cjs/form-token-field/style.scss +2 -3
  27. package/dist/cjs/global-notices/index.js +1 -8
  28. package/dist/cjs/grid/index.js +1 -8
  29. package/dist/cjs/grid/style.scss +5 -5
  30. package/dist/cjs/handoff/index.js +8 -17
  31. package/dist/cjs/handoff-message/index.js +50 -0
  32. package/dist/cjs/hooks/index.js +1 -7
  33. package/dist/cjs/hooks/useObjectState.js +7 -13
  34. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  35. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  36. package/dist/cjs/hooks/usePrompt.js +1 -13
  37. package/dist/cjs/image-upload/index.js +21 -19
  38. package/dist/cjs/image-upload/index.test.js +0 -5
  39. package/dist/cjs/image-upload/style.scss +5 -9
  40. package/dist/cjs/index.js +28 -44
  41. package/dist/cjs/info-button/index.js +3 -11
  42. package/dist/cjs/info-button/style.scss +1 -3
  43. package/dist/cjs/modal/index.js +1 -9
  44. package/dist/cjs/modal/style.scss +8 -8
  45. package/dist/cjs/newspack-icon/index.js +1 -9
  46. package/dist/cjs/newspack-icon/style.scss +4 -4
  47. package/dist/cjs/newspack-logo/index.js +1 -9
  48. package/dist/cjs/newspack-logo/style.scss +3 -3
  49. package/dist/cjs/notice/index.js +8 -15
  50. package/dist/cjs/notice/style.scss +28 -15
  51. package/dist/cjs/patrons-logo/index.js +3 -11
  52. package/dist/cjs/plugin-installer/index.js +36 -36
  53. package/dist/cjs/plugin-installer/style.scss +5 -5
  54. package/dist/cjs/plugin-settings/SettingsSection.js +9 -28
  55. package/dist/cjs/plugin-settings/index.js +39 -22
  56. package/dist/cjs/plugin-toggle/index.js +40 -33
  57. package/dist/cjs/plugin-toggle/style.scss +2 -2
  58. package/dist/cjs/popover/index.js +1 -11
  59. package/dist/cjs/popover/style.scss +19 -16
  60. package/dist/cjs/position-control/index.js +113 -0
  61. package/dist/cjs/position-control/style.scss +66 -0
  62. package/dist/cjs/progress-bar/index.js +2 -9
  63. package/dist/cjs/progress-bar/index.test.js +2 -7
  64. package/dist/cjs/progress-bar/style.scss +4 -4
  65. package/dist/cjs/proxied-imports/router.js +0 -3
  66. package/dist/cjs/radio-control/index.js +1 -11
  67. package/dist/cjs/radio-control/style.scss +9 -9
  68. package/dist/cjs/section-header/index.js +44 -29
  69. package/dist/cjs/section-header/style.scss +2 -2
  70. package/dist/cjs/select-control/ButtonGroupControl.js +4 -13
  71. package/dist/cjs/select-control/GroupedSelectControl.js +9 -15
  72. package/dist/cjs/select-control/index.js +5 -12
  73. package/dist/cjs/select-control/style.scss +2 -2
  74. package/dist/cjs/settings/MinMaxSetting.js +3 -7
  75. package/dist/cjs/settings/SettingsCard.js +3 -7
  76. package/dist/cjs/settings/SettingsSection.js +1 -4
  77. package/dist/cjs/settings/index.js +0 -6
  78. package/dist/cjs/settings/style.scss +1 -1
  79. package/dist/cjs/steps-list/index.js +52 -0
  80. package/dist/cjs/steps-list/style.scss +11 -0
  81. package/dist/cjs/steps-list-item/index.js +56 -0
  82. package/dist/cjs/steps-list-item/style.scss +47 -0
  83. package/dist/cjs/style-card/index.js +6 -13
  84. package/dist/cjs/style-card/style.scss +9 -12
  85. package/dist/cjs/style.scss +5 -6
  86. package/dist/cjs/tabbed-navigation/index.js +19 -16
  87. package/dist/cjs/tabbed-navigation/style.scss +3 -4
  88. package/dist/cjs/text-control/index.js +6 -16
  89. package/dist/cjs/utils/index.js +10 -5
  90. package/dist/cjs/waiting/index.js +1 -9
  91. package/dist/cjs/web-preview/index.js +13 -28
  92. package/dist/cjs/web-preview/style.scss +14 -14
  93. package/dist/cjs/with-wizard/index.js +51 -31
  94. package/dist/cjs/with-wizard/style.scss +35 -37
  95. package/dist/cjs/with-wizard-screen/index.js +11 -17
  96. package/dist/cjs/with-wizard-screen/style.scss +14 -17
  97. package/dist/cjs/wizard/components/WizardError.js +3 -15
  98. package/dist/cjs/wizard/index.js +10 -24
  99. package/dist/cjs/wizard/store/index.js +42 -55
  100. package/dist/cjs/wizard/store/utils.js +1 -6
  101. package/dist/esm/accordion/index.js +38 -0
  102. package/dist/esm/accordion/style.scss +27 -0
  103. package/dist/esm/action-card/index.js +50 -21
  104. package/dist/esm/action-card/style.scss +100 -23
  105. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  106. package/dist/esm/autocomplete-tokenfield/style.scss +2 -2
  107. package/dist/esm/autocomplete-with-suggestions/index.js +28 -41
  108. package/dist/esm/autocomplete-with-suggestions/style.scss +16 -15
  109. package/dist/esm/button/index.js +5 -7
  110. package/dist/esm/button-card/index.js +2 -5
  111. package/dist/esm/button-card/style.scss +13 -13
  112. package/dist/esm/card/index.js +2 -5
  113. package/dist/esm/card/style.scss +25 -8
  114. package/dist/esm/category-autocomplete/index.js +17 -30
  115. package/dist/esm/category-autocomplete/style.scss +0 -2
  116. package/dist/esm/color-picker/index.js +2 -4
  117. package/dist/esm/color-picker/style.scss +0 -3
  118. package/dist/esm/consts.js +3 -2
  119. package/dist/esm/custom-select-control/index.js +2 -5
  120. package/dist/esm/custom-select-control/style.scss +6 -7
  121. package/dist/esm/date-range-picker/index.js +1 -3
  122. package/dist/esm/date-range-picker/style.scss +12 -12
  123. package/dist/esm/footer/index.js +3 -11
  124. package/dist/esm/footer/style.scss +5 -5
  125. package/dist/esm/form-token-field/index.js +2 -5
  126. package/dist/esm/form-token-field/style.scss +2 -3
  127. package/dist/esm/global-notices/index.js +1 -6
  128. package/dist/esm/grid/index.js +2 -5
  129. package/dist/esm/grid/style.scss +5 -5
  130. package/dist/esm/handoff/index.js +3 -14
  131. package/dist/esm/handoff-message/index.js +45 -0
  132. package/dist/esm/hooks/index.js +0 -2
  133. package/dist/esm/hooks/useObjectState.js +3 -8
  134. package/dist/esm/hooks/useObjectState.test.js +0 -3
  135. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  136. package/dist/esm/hooks/usePrompt.js +1 -8
  137. package/dist/esm/image-upload/index.js +17 -16
  138. package/dist/esm/image-upload/style.scss +5 -9
  139. package/dist/esm/index.js +4 -0
  140. package/dist/esm/info-button/index.js +4 -6
  141. package/dist/esm/info-button/style.scss +1 -3
  142. package/dist/esm/modal/index.js +2 -5
  143. package/dist/esm/modal/style.scss +8 -8
  144. package/dist/esm/newspack-icon/index.js +2 -5
  145. package/dist/esm/newspack-icon/style.scss +4 -4
  146. package/dist/esm/newspack-logo/index.js +2 -5
  147. package/dist/esm/newspack-logo/style.scss +3 -3
  148. package/dist/esm/notice/index.js +4 -8
  149. package/dist/esm/notice/style.scss +28 -15
  150. package/dist/esm/patrons-logo/index.js +3 -5
  151. package/dist/esm/plugin-installer/index.js +35 -39
  152. package/dist/esm/plugin-installer/style.scss +5 -5
  153. package/dist/esm/plugin-settings/SettingsSection.js +8 -21
  154. package/dist/esm/plugin-settings/index.js +38 -24
  155. package/dist/esm/plugin-toggle/index.js +39 -36
  156. package/dist/esm/plugin-toggle/style.scss +2 -2
  157. package/dist/esm/popover/index.js +3 -6
  158. package/dist/esm/popover/style.scss +19 -16
  159. package/dist/esm/position-control/index.js +109 -0
  160. package/dist/esm/position-control/style.scss +66 -0
  161. package/dist/esm/progress-bar/index.js +2 -7
  162. package/dist/esm/progress-bar/index.test.js +2 -1
  163. package/dist/esm/progress-bar/style.scss +4 -4
  164. package/dist/esm/proxied-imports/router.js +1 -0
  165. package/dist/esm/radio-control/index.js +3 -6
  166. package/dist/esm/radio-control/style.scss +9 -9
  167. package/dist/esm/section-header/index.js +44 -25
  168. package/dist/esm/section-header/style.scss +2 -2
  169. package/dist/esm/select-control/ButtonGroupControl.js +5 -7
  170. package/dist/esm/select-control/GroupedSelectControl.js +5 -6
  171. package/dist/esm/select-control/index.js +6 -6
  172. package/dist/esm/select-control/style.scss +2 -2
  173. package/dist/esm/settings/MinMaxSetting.js +1 -3
  174. package/dist/esm/settings/SettingsCard.js +3 -4
  175. package/dist/esm/settings/SettingsSection.js +0 -2
  176. package/dist/esm/settings/style.scss +1 -1
  177. package/dist/esm/steps-list/index.js +43 -0
  178. package/dist/esm/steps-list/style.scss +11 -0
  179. package/dist/esm/steps-list-item/index.js +48 -0
  180. package/dist/esm/steps-list-item/style.scss +47 -0
  181. package/dist/esm/style-card/index.js +2 -5
  182. package/dist/esm/style-card/style.scss +9 -12
  183. package/dist/esm/style.scss +5 -6
  184. package/dist/esm/tabbed-navigation/index.js +20 -10
  185. package/dist/esm/tabbed-navigation/style.scss +3 -4
  186. package/dist/esm/text-control/index.js +2 -9
  187. package/dist/esm/utils/index.js +9 -3
  188. package/dist/esm/waiting/index.js +2 -5
  189. package/dist/esm/web-preview/index.js +9 -24
  190. package/dist/esm/web-preview/style.scss +14 -14
  191. package/dist/esm/with-wizard/index.js +49 -34
  192. package/dist/esm/with-wizard/style.scss +35 -37
  193. package/dist/esm/with-wizard-screen/index.js +9 -11
  194. package/dist/esm/with-wizard-screen/style.scss +14 -17
  195. package/dist/esm/wizard/components/WizardError.js +1 -10
  196. package/dist/esm/wizard/index.js +10 -12
  197. package/dist/esm/wizard/store/index.js +40 -46
  198. package/dist/esm/wizard/store/utils.js +1 -1
  199. package/package.json +4 -4
  200. package/shared/js/button-props.js +3 -1
  201. package/shared/scss/_mixins.scss +12 -0
  202. package/src/accordion/index.js +32 -0
  203. package/src/accordion/style.scss +27 -0
  204. package/src/action-card/index.js +43 -8
  205. package/src/action-card/style.scss +100 -23
  206. package/src/autocomplete-tokenfield/index.js +1 -1
  207. package/src/autocomplete-tokenfield/style.scss +2 -2
  208. package/src/autocomplete-with-suggestions/style.scss +16 -15
  209. package/src/button-card/style.scss +13 -13
  210. package/src/card/style.scss +25 -8
  211. package/src/category-autocomplete/index.js +3 -1
  212. package/src/category-autocomplete/style.scss +0 -2
  213. package/src/color-picker/style.scss +0 -3
  214. package/src/consts.js +2 -1
  215. package/src/custom-select-control/style.scss +6 -7
  216. package/src/date-range-picker/style.scss +12 -12
  217. package/src/footer/index.js +2 -2
  218. package/src/footer/style.scss +5 -5
  219. package/src/form-token-field/index.js +2 -7
  220. package/src/form-token-field/style.scss +2 -3
  221. package/src/grid/style.scss +5 -5
  222. package/src/handoff/index.js +3 -8
  223. package/src/handoff-message/index.js +39 -0
  224. package/src/hooks/useObjectState.js +2 -1
  225. package/src/image-upload/index.js +9 -3
  226. package/src/image-upload/style.scss +5 -9
  227. package/src/index.js +4 -0
  228. package/src/info-button/style.scss +1 -3
  229. package/src/modal/style.scss +8 -8
  230. package/src/newspack-icon/style.scss +4 -4
  231. package/src/newspack-logo/style.scss +3 -3
  232. package/src/notice/index.js +2 -0
  233. package/src/notice/style.scss +28 -15
  234. package/src/plugin-installer/index.js +15 -2
  235. package/src/plugin-installer/style.scss +5 -5
  236. package/src/plugin-settings/SettingsSection.js +7 -13
  237. package/src/plugin-settings/index.js +7 -2
  238. package/src/plugin-toggle/index.js +2 -3
  239. package/src/plugin-toggle/style.scss +2 -2
  240. package/src/popover/style.scss +19 -16
  241. package/src/position-control/index.js +122 -0
  242. package/src/position-control/style.scss +66 -0
  243. package/src/progress-bar/style.scss +4 -4
  244. package/src/radio-control/style.scss +9 -9
  245. package/src/section-header/index.js +32 -15
  246. package/src/section-header/style.scss +2 -2
  247. package/src/select-control/ButtonGroupControl.js +3 -0
  248. package/src/select-control/GroupedSelectControl.js +2 -1
  249. package/src/select-control/index.js +6 -2
  250. package/src/select-control/style.scss +2 -2
  251. package/src/settings/style.scss +1 -1
  252. package/src/steps-list/index.js +39 -0
  253. package/src/steps-list/style.scss +11 -0
  254. package/src/steps-list-item/index.js +40 -0
  255. package/src/steps-list-item/style.scss +47 -0
  256. package/src/style-card/index.js +2 -11
  257. package/src/style-card/style.scss +9 -12
  258. package/src/style.scss +5 -6
  259. package/src/tabbed-navigation/index.js +12 -4
  260. package/src/tabbed-navigation/style.scss +3 -4
  261. package/src/utils/index.js +9 -0
  262. package/src/web-preview/index.js +1 -1
  263. package/src/web-preview/style.scss +14 -14
  264. package/src/with-wizard/style.scss +35 -37
  265. package/src/with-wizard-screen/index.js +4 -1
  266. package/src/with-wizard-screen/style.scss +14 -17
  267. package/src/wizard/index.js +15 -3
  268. package/src/wizard/store/index.js +8 -2
@@ -1,44 +1,32 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.default = void 0;
11
-
12
9
  var _classnames = _interopRequireDefault(require("classnames"));
13
-
14
10
  var _data = require("@wordpress/data");
15
-
16
11
  var _element = require("@wordpress/element");
17
-
18
12
  var _i18n = require("@wordpress/i18n");
19
-
20
13
  var _icons = require("@wordpress/icons");
21
-
22
14
  var _ = require("../");
23
-
24
15
  var _router = _interopRequireDefault(require("../proxied-imports/router"));
25
-
26
16
  var _store = _interopRequireWildcard(require("./store"));
27
-
28
17
  var _utils = require("./store/utils");
29
-
30
18
  var _WizardError = _interopRequireDefault(require("./components/WizardError"));
31
-
32
19
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
33
-
34
20
  /**
35
21
  * External dependencies.
36
22
  */
37
-
38
23
  /**
39
24
  * WordPress dependencies.
40
25
  */
41
26
  const __ = _i18n.__;
27
+ /**
28
+ * Internal dependencies
29
+ */
42
30
  (0, _store.default)();
43
31
  const {
44
32
  HashRouter,
@@ -46,7 +34,6 @@ const {
46
34
  Route,
47
35
  Switch
48
36
  } = _router.default;
49
-
50
37
  const Wizard = _ref => {
51
38
  let {
52
39
  sections = [],
@@ -59,13 +46,13 @@ const Wizard = _ref => {
59
46
  requiredPlugins = []
60
47
  } = _ref;
61
48
  const isLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isLoading());
62
- const isQuietLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isQuietLoading()); // Trigger initial data fetch. Some sections might not use the wizard data,
63
- // but for consistency, fetching is triggered regardless of the section.
49
+ const isQuietLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isQuietLoading());
64
50
 
51
+ // Trigger initial data fetch. Some sections might not use the wizard data,
52
+ // but for consistency, fetching is triggered regardless of the section.
65
53
  (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).getWizardAPIData(apiSlug));
66
54
  let displayedSections = sections.filter(section => !section.isHidden);
67
55
  const [pluginRequirementsSatisfied, setPluginRequirementsSatisfied] = (0, _element.useState)(requiredPlugins.length === 0);
68
-
69
56
  if (!pluginRequirementsSatisfied) {
70
57
  headerText = requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack');
71
58
  displayedSections = [{
@@ -81,9 +68,8 @@ const Wizard = _ref => {
81
68
  })
82
69
  }];
83
70
  }
84
-
85
71
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
86
- children: [(0, _jsxRuntime.jsx)(_WizardError.default, {}), (0, _jsxRuntime.jsx)("div", {
72
+ children: [(0, _jsxRuntime.jsx)("div", {
87
73
  className: (0, _classnames.default)(isLoading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded', {
88
74
  'newspack-wizard__is-loading-quiet': isQuietLoading
89
75
  }),
@@ -117,8 +103,9 @@ const Wizard = _ref => {
117
103
  })
118
104
  })
119
105
  }), displayedSections.length > 1 && (0, _jsxRuntime.jsx)(_.TabbedNavigation, {
120
- items: displayedSections
121
- }), (0, _jsxRuntime.jsxs)(Switch, {
106
+ items: displayedSections,
107
+ children: (0, _jsxRuntime.jsx)(_WizardError.default, {})
108
+ }), (0, _jsxRuntime.jsx)(_.HandoffMessage, {}), (0, _jsxRuntime.jsxs)(Switch, {
122
109
  children: [displayedSections.map((section, index) => {
123
110
  const SectionComponent = section.render;
124
111
  return (0, _jsxRuntime.jsx)(Route, {
@@ -138,7 +125,6 @@ const Wizard = _ref => {
138
125
  })]
139
126
  });
140
127
  };
141
-
142
128
  Wizard.useWizardData = _utils.useWizardData;
143
129
  Wizard.STORE_NAMESPACE = _store.WIZARD_STORE_NAMESPACE;
144
130
  var _default = Wizard;
@@ -1,20 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.WIZARD_STORE_NAMESPACE = void 0;
9
-
10
- var _lodash = require("lodash");
11
-
8
+ var _set = _interopRequireDefault(require("lodash/set"));
9
+ var _get = _interopRequireDefault(require("lodash/get"));
10
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
12
11
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
13
-
14
12
  var _data = require("@wordpress/data");
15
-
16
13
  var _utils = require("./utils.js");
17
-
18
14
  /**
19
15
  * External dependencies.
20
16
  */
@@ -22,6 +18,7 @@ var _utils = require("./utils.js");
22
18
  /**
23
19
  * WordPress dependencies.
24
20
  */
21
+
25
22
  const WIZARD_STORE_NAMESPACE = 'newspack/wizards';
26
23
  exports.WIZARD_STORE_NAMESPACE = WIZARD_STORE_NAMESPACE;
27
24
  const DEFAULT_STATE = {
@@ -30,55 +27,50 @@ const DEFAULT_STATE = {
30
27
  apiData: {},
31
28
  error: null
32
29
  };
30
+
33
31
  /**
34
32
  * wordpress/data does not trigger a component re-render
35
33
  * on deep state change (via lodash's set function)
36
34
  * unless the state was cloned first.
37
35
  */
38
-
39
36
  const clone = objectToClone => JSON.parse(JSON.stringify(objectToClone));
40
-
41
37
  const reducer = function () {
42
38
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
43
39
  let {
44
40
  type,
45
41
  payload = {}
46
42
  } = arguments.length > 1 ? arguments[1] : undefined;
47
-
48
43
  switch (type) {
49
44
  case 'START_LOADING_DATA':
50
45
  if (payload.isQuietLoading) {
51
- return { ...state,
46
+ return {
47
+ ...state,
52
48
  isQuietLoading: true
53
49
  };
54
50
  }
55
-
56
- return { ...state,
51
+ return {
52
+ ...state,
57
53
  isLoading: true
58
54
  };
59
-
60
55
  case 'FINISH_LOADING_DATA':
61
- return { ...state,
56
+ return {
57
+ ...state,
62
58
  isLoading: false,
63
59
  isQuietLoading: false
64
60
  };
65
-
66
61
  case 'SET_API_DATA':
67
- return (0, _lodash.set)(clone(state), ['apiData', payload.slug], payload.data);
68
-
62
+ return (0, _set.default)(clone(state), ['apiData', payload.slug], payload.data);
69
63
  case 'UPDATE_WIZARD_SETTINGS':
70
- return (0, _lodash.set)(clone(state), ['apiData', payload.slug, ...payload.path], payload.value);
71
-
64
+ return (0, _set.default)(clone(state), ['apiData', payload.slug, ...payload.path], payload.value);
72
65
  case 'SET_ERROR':
73
- return { ...state,
66
+ return {
67
+ ...state,
74
68
  error: payload
75
69
  };
76
-
77
70
  default:
78
71
  return state;
79
72
  }
80
73
  };
81
-
82
74
  const actions = {
83
75
  // Regular actions.
84
76
  startLoadingData: (0, _utils.createAction)('START_LOADING_DATA'),
@@ -87,47 +79,43 @@ const actions = {
87
79
  setAPIDataForWizard: (0, _utils.createAction)('SET_API_DATA'),
88
80
  updateWizardSettings: (0, _utils.createAction)('UPDATE_WIZARD_SETTINGS'),
89
81
  setError: (0, _utils.createAction)('SET_ERROR'),
90
-
91
82
  // Async actions. These will not show up in Redux devtools.
92
- *saveWizardSettings(_ref) {
83
+ saveWizardSettings(_ref) {
93
84
  let {
94
85
  slug,
95
86
  section = '',
96
87
  payloadPath = false,
97
88
  updatePayload = null
98
89
  } = _ref;
99
-
100
- // Optionally data can be updated before saving - an immediate update case
101
- // (without an explicit "save" action).
102
- if (updatePayload) {
103
- yield actions.updateWizardSettings({
104
- slug,
105
- ...updatePayload
106
- });
107
- }
108
-
109
- const wizardState = (0, _data.select)(WIZARD_STORE_NAMESPACE).getWizardAPIData(slug);
110
- const updatedData = yield actions.fetchFromAPI({
111
- path: `/newspack/v1/wizard/${slug}/${section}`,
112
- method: 'POST',
113
- data: payloadPath ? (0, _lodash.get)(wizardState, payloadPath) : wizardState,
114
- isQuietFetch: true
115
- });
116
-
117
- if (!(0, _lodash.isEmpty)(updatedData)) {
118
- return actions.setAPIDataForWizard({
119
- slug,
120
- data: updatedData
90
+ return function* () {
91
+ // Optionally data can be updated before saving - an immediate update case
92
+ // (without an explicit "save" action).
93
+ if (updatePayload) {
94
+ yield actions.updateWizardSettings({
95
+ slug,
96
+ ...updatePayload
97
+ });
98
+ }
99
+ const wizardState = (0, _data.select)(WIZARD_STORE_NAMESPACE).getWizardAPIData(slug);
100
+ const updatedData = yield actions.fetchFromAPI({
101
+ path: `/newspack/v1/wizard/${slug}/${section}`,
102
+ method: 'POST',
103
+ data: payloadPath ? (0, _get.default)(wizardState, payloadPath) : wizardState,
104
+ isQuietFetch: true
121
105
  });
122
- }
106
+ if (!(0, _isEmpty.default)(updatedData) && !updatedData.error) {
107
+ return actions.setAPIDataForWizard({
108
+ slug,
109
+ data: updatedData
110
+ });
111
+ }
112
+ }();
123
113
  },
124
-
125
114
  *wizardApiFetch(fetchConfig) {
126
115
  // Just a proxy to fetchFromAPI, but it has to be a generator.
127
116
  const result = yield actions.fetchFromAPI(fetchConfig);
128
117
  return result;
129
118
  }
130
-
131
119
  };
132
120
  const selectors = {
133
121
  isLoading: state => state.isLoading,
@@ -144,7 +132,10 @@ const store = (0, _data.createReduxStore)(WIZARD_STORE_NAMESPACE, {
144
132
  (0, _data.dispatch)(WIZARD_STORE_NAMESPACE).startLoadingData({
145
133
  isQuietLoading: Boolean(action.payload.isQuietFetch)
146
134
  });
147
- return (0, _apiFetch.default)(action.payload).catch(error => {
135
+ return (0, _apiFetch.default)(action.payload).then(data => {
136
+ (0, _data.dispatch)(WIZARD_STORE_NAMESPACE).setError(null);
137
+ return data;
138
+ }).catch(error => {
148
139
  (0, _data.dispatch)(WIZARD_STORE_NAMESPACE).setError(error);
149
140
  return {
150
141
  error
@@ -166,13 +157,9 @@ const store = (0, _data.createReduxStore)(WIZARD_STORE_NAMESPACE, {
166
157
  data
167
158
  });
168
159
  }
169
-
170
160
  return actions.finishLoadingData();
171
161
  }
172
-
173
162
  }
174
163
  });
175
-
176
164
  var _default = () => (0, _data.register)(store);
177
-
178
165
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useWizardData = exports.createAction = void 0;
7
-
8
7
  var _data = require("@wordpress/data");
9
-
10
8
  var _ = require(".");
11
-
12
9
  /**
13
10
  * WordPress dependencies.
14
11
  */
@@ -16,16 +13,14 @@ var _ = require(".");
16
13
  /**
17
14
  * Internal dependencies
18
15
  */
16
+
19
17
  const createAction = type => payload => ({
20
18
  type,
21
19
  payload
22
20
  });
23
-
24
21
  exports.createAction = createAction;
25
-
26
22
  const useWizardData = function (wizardName) {
27
23
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28
24
  return (0, _data.useSelect)(select => select(_.WIZARD_STORE_NAMESPACE).getWizardAPIData(`newspack-${wizardName}-wizard`)) || defaultValue;
29
25
  };
30
-
31
26
  exports.useWizardData = useWizardData;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useState } from '@wordpress/element';
5
+ import { Icon, chevronRight } from '@wordpress/icons';
6
+
7
+ /**
8
+ * External dependencies
9
+ */
10
+ import classNames from 'classnames';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import './style.scss';
16
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
17
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
18
+ const Accordion = _ref => {
19
+ let {
20
+ children,
21
+ title
22
+ } = _ref;
23
+ const [isOpen, setIsOpen] = useState(false);
24
+ return _jsxs("details", {
25
+ className: classNames('newspack-accordion', {
26
+ 'newspack-accordion--is-open': isOpen
27
+ }),
28
+ children: [_jsxs("summary", {
29
+ onClick: () => setIsOpen(!isOpen),
30
+ children: [title, _jsx(Icon, {
31
+ className: "newspack-accordion__icon",
32
+ icon: chevronRight,
33
+ size: 24
34
+ })]
35
+ }), children]
36
+ });
37
+ };
38
+ export default Accordion;
@@ -0,0 +1,27 @@
1
+ @use '~@wordpress/base-styles/colors' as wp-colors;
2
+
3
+ .newspack-accordion {
4
+ border: 1px solid wp-colors.$gray-300;
5
+
6
+ &__icon {
7
+ transition: transform 200ms ease-out;
8
+ transform: rotate( 90deg );
9
+ }
10
+
11
+ &--is-open {
12
+ .newspack-accordion {
13
+ &__icon {
14
+ transform: rotate( -90deg );
15
+ }
16
+ }
17
+ }
18
+ summary {
19
+ padding: 16px 32px;
20
+ display: flex;
21
+ align-items: center;
22
+ justify-content: space-between;
23
+ cursor: pointer;
24
+ font-size: 14px;
25
+ font-weight: bold;
26
+ }
27
+ }
@@ -1,5 +1,4 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
2
  /**
4
3
  * Action Card
5
4
  */
@@ -9,34 +8,40 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
8
  */
10
9
  import { Component } from '@wordpress/element';
11
10
  import { ExternalLink, ToggleControl } from '@wordpress/components';
12
- import { Icon, check } from '@wordpress/icons';
11
+ import { Icon, check, chevronDown, chevronUp } from '@wordpress/icons';
12
+
13
13
  /**
14
14
  * Internal dependencies
15
15
  */
16
-
17
16
  import { Button, Card, Grid, Handoff, Notice, Waiting } from '../';
18
17
  import './style.scss';
18
+
19
19
  /**
20
20
  * External dependencies
21
21
  */
22
-
23
22
  import classnames from 'classnames';
24
23
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
25
24
  import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
26
-
27
25
  class ActionCard extends Component {
28
26
  constructor() {
29
27
  super(...arguments);
30
-
31
- _defineProperty(this, "backgroundImageStyles", url => {
32
- return url ? {
33
- backgroundImage: `url(${url})`
34
- } : {};
28
+ _defineProperty(this, "state", {
29
+ expanded: false
35
30
  });
36
31
  }
32
+ /**
33
+ * When the collapse prop is updated to true, collapse the card if already expanded.
34
+ */
35
+ componentDidUpdate(prevProps) {
36
+ if (!prevProps.collapse && this.props.collapse && this.state.expanded) {
37
+ this.setState({
38
+ expanded: false
39
+ });
40
+ }
41
+ }
37
42
 
38
43
  /**
39
- * Render
44
+ * Render.
40
45
  */
41
46
  render() {
42
47
  const {
@@ -70,10 +75,20 @@ class ActionCard extends Component {
70
75
  toggleChecked,
71
76
  toggleOnChange,
72
77
  hasGreyHeader,
73
- isPending
78
+ hasWhiteHeader,
79
+ isPending,
80
+ expandable = false
74
81
  } = this.props;
82
+ const {
83
+ expanded
84
+ } = this.state;
75
85
  const hasChildren = notification || children;
76
- const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasChildren && 'newspack-card--has-children', indent && 'newspack-card--indent', isSmall && 'is-small', isMedium && 'is-medium', className);
86
+ const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasWhiteHeader && 'newspack-card--has-white-header', hasChildren && 'newspack-card--has-children', indent && 'newspack-card--indent', isSmall && 'is-small', isMedium && 'is-medium', checkbox && 'has-checkbox', expandable && 'is-expandable', actionContent && 'has-action-content', className);
87
+ const backgroundImageStyles = url => {
88
+ return url ? {
89
+ backgroundImage: `url(${url})`
90
+ } : {};
91
+ };
77
92
  const titleProps = toggleOnChange && !titleLink && !disabled ? {
78
93
  onClick: () => toggleOnChange(!toggleChecked),
79
94
  tabIndex: '0'
@@ -96,7 +111,7 @@ class ActionCard extends Component {
96
111
  href: imageLink,
97
112
  children: _jsx("div", {
98
113
  className: "newspack-action-card__image",
99
- style: this.backgroundImageStyles(image)
114
+ style: backgroundImageStyles(image)
100
115
  })
101
116
  })
102
117
  }), checkbox && !toggleOnChange && _jsx("div", {
@@ -114,13 +129,19 @@ class ActionCard extends Component {
114
129
  gutter: 8,
115
130
  noMargin: true,
116
131
  children: [_jsxs("h2", {
117
- children: [_jsx("span", {
132
+ children: [_jsxs("span", {
118
133
  className: "newspack-action-card__title",
119
134
  ...titleProps,
120
- children: titleLink ? _jsx("a", {
135
+ children: [titleLink && _jsx("a", {
121
136
  href: titleLink,
122
137
  children: title
123
- }) : title
138
+ }), !titleLink && expandable && _jsx(Button, {
139
+ isLink: true,
140
+ onClick: () => this.setState({
141
+ expanded: !expanded
142
+ }),
143
+ children: title
144
+ }), !titleLink && !expandable && title]
124
145
  }), badges?.length && badges.map((badgeText, i) => _jsx("span", {
125
146
  className: "newspack-action-card__badge",
126
147
  children: badgeText
@@ -129,7 +150,7 @@ class ActionCard extends Component {
129
150
  children: [typeof description === 'string' && description, typeof description === 'function' && description()]
130
151
  })]
131
152
  })
132
- }), (actionText || isDisplayingSecondaryAction || actionContent) && _jsxs("div", {
153
+ }), !expandable && (actionText || isDisplayingSecondaryAction || actionContent) && _jsxs("div", {
133
154
  className: "newspack-action-card__region newspack-action-card__region-right",
134
155
  children: [actionContent && actionContent, actionText && (handoff ? _jsx(Handoff, {
135
156
  plugin: handoff,
@@ -138,6 +159,7 @@ class ActionCard extends Component {
138
159
  isLink: true,
139
160
  children: actionText
140
161
  }) : onClick || hasInternalLink ? _jsx(Button, {
162
+ disabled: disabled,
141
163
  isLink: true,
142
164
  href: href,
143
165
  onClick: onClick,
@@ -159,6 +181,15 @@ class ActionCard extends Component {
159
181
  isDestructive: secondaryDestructive,
160
182
  children: secondaryActionText
161
183
  })]
184
+ }), expandable && _jsx(Button, {
185
+ onClick: () => this.setState({
186
+ expanded: !expanded
187
+ }),
188
+ children: _jsx(Icon, {
189
+ icon: expanded ? chevronUp : chevronDown,
190
+ height: 24,
191
+ width: 24
192
+ })
162
193
  })]
163
194
  }), notification && _jsxs("div", {
164
195
  className: "newspack-action-card__notification newspack-action-card__region-children",
@@ -178,15 +209,13 @@ class ActionCard extends Component {
178
209
  isWarning: true,
179
210
  rawHTML: notificationHTML
180
211
  })]
181
- }), children && _jsx("div", {
212
+ }), children && (expandable && expanded || !expandable) && _jsx("div", {
182
213
  className: "newspack-action-card__region-children",
183
214
  children: children
184
215
  })]
185
216
  });
186
217
  }
187
-
188
218
  }
189
-
190
219
  ActionCard.defaultProps = {
191
220
  toggleChecked: false
192
221
  };