newspack-components 2.0.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/copy-styles.js +1 -1
  2. package/dist/cjs/accordion/index.js +46 -0
  3. package/dist/cjs/accordion/style.scss +27 -0
  4. package/dist/cjs/action-card/index.js +72 -40
  5. package/dist/cjs/action-card/style.scss +143 -41
  6. package/dist/cjs/autocomplete-tokenfield/index.js +13 -41
  7. package/dist/cjs/autocomplete-tokenfield/style.scss +6 -6
  8. package/dist/cjs/autocomplete-with-suggestions/index.js +33 -53
  9. package/dist/cjs/autocomplete-with-suggestions/style.scss +27 -27
  10. package/dist/cjs/button/index.js +1 -20
  11. package/dist/cjs/button/style.scss +3 -344
  12. package/dist/cjs/button-card/index.js +11 -15
  13. package/dist/cjs/button-card/style.scss +65 -35
  14. package/dist/cjs/card/index.js +4 -9
  15. package/dist/cjs/card/style.scss +47 -63
  16. package/dist/cjs/category-autocomplete/index.js +66 -47
  17. package/dist/cjs/category-autocomplete/style.scss +20 -24
  18. package/dist/cjs/color-picker/index.js +16 -48
  19. package/dist/cjs/color-picker/style.scss +20 -163
  20. package/dist/cjs/consts.js +5 -3
  21. package/dist/cjs/custom-select-control/index.js +1 -9
  22. package/dist/cjs/custom-select-control/style.scss +14 -45
  23. package/dist/cjs/date-range-picker/index.js +1 -10
  24. package/dist/cjs/date-range-picker/style.scss +12 -12
  25. package/dist/cjs/footer/index.js +24 -22
  26. package/dist/cjs/footer/style.scss +13 -14
  27. package/dist/cjs/form-token-field/index.js +3 -11
  28. package/dist/cjs/form-token-field/style.scss +9 -105
  29. package/dist/cjs/global-notices/index.js +3 -9
  30. package/dist/cjs/grid/index.js +1 -8
  31. package/dist/cjs/grid/style.scss +19 -6
  32. package/dist/cjs/handoff/index.js +15 -24
  33. package/dist/cjs/handoff-message/index.js +50 -0
  34. package/dist/cjs/hooks/index.js +1 -7
  35. package/dist/cjs/hooks/useObjectState.js +7 -13
  36. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  37. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  38. package/dist/cjs/hooks/usePrompt.js +1 -13
  39. package/dist/cjs/image-upload/index.js +22 -20
  40. package/dist/cjs/image-upload/index.test.js +0 -5
  41. package/dist/cjs/image-upload/style.scss +12 -17
  42. package/dist/cjs/index.js +31 -93
  43. package/dist/cjs/info-button/index.js +3 -11
  44. package/dist/cjs/info-button/style.scss +1 -3
  45. package/dist/cjs/modal/index.js +1 -12
  46. package/dist/cjs/modal/style.scss +20 -132
  47. package/dist/cjs/newspack-icon/index.js +5 -11
  48. package/dist/cjs/newspack-icon/style.scss +17 -2
  49. package/dist/cjs/newspack-logo/index.js +1 -9
  50. package/dist/cjs/newspack-logo/style.scss +3 -3
  51. package/dist/cjs/notice/index.js +8 -16
  52. package/dist/cjs/notice/style.scss +60 -19
  53. package/dist/cjs/patrons-logo/index.js +3 -11
  54. package/dist/cjs/plugin-installer/index.js +37 -37
  55. package/dist/cjs/plugin-installer/style.scss +5 -5
  56. package/dist/cjs/plugin-settings/SettingsSection.js +71 -59
  57. package/dist/cjs/plugin-settings/index.js +71 -50
  58. package/dist/cjs/plugin-settings/style.scss +7 -0
  59. package/dist/cjs/plugin-toggle/index.js +60 -32
  60. package/dist/cjs/plugin-toggle/style.scss +2 -2
  61. package/dist/cjs/popover/index.js +1 -11
  62. package/dist/cjs/popover/style.scss +20 -17
  63. package/dist/cjs/position-control/index.js +113 -0
  64. package/dist/cjs/position-control/style.scss +66 -0
  65. package/dist/cjs/progress-bar/index.js +2 -9
  66. package/dist/cjs/progress-bar/index.test.js +2 -7
  67. package/dist/cjs/progress-bar/style.scss +4 -4
  68. package/dist/cjs/proxied-imports/router.js +0 -3
  69. package/dist/cjs/radio-control/index.js +1 -11
  70. package/dist/cjs/radio-control/style.scss +10 -11
  71. package/dist/cjs/section-header/index.js +47 -19
  72. package/dist/cjs/section-header/style.scss +22 -1
  73. package/dist/cjs/select-control/ButtonGroupControl.js +11 -20
  74. package/dist/cjs/select-control/GroupedSelectControl.js +42 -45
  75. package/dist/cjs/select-control/index.js +6 -14
  76. package/dist/cjs/select-control/style.scss +47 -88
  77. package/dist/cjs/settings/MinMaxSetting.js +6 -8
  78. package/dist/cjs/settings/SettingsCard.js +9 -8
  79. package/dist/cjs/settings/SettingsSection.js +5 -8
  80. package/dist/cjs/settings/index.js +0 -6
  81. package/dist/cjs/settings/style.scss +32 -4
  82. package/dist/cjs/steps-list/index.js +52 -0
  83. package/dist/cjs/steps-list/style.scss +11 -0
  84. package/dist/cjs/steps-list-item/index.js +56 -0
  85. package/dist/cjs/steps-list-item/style.scss +47 -0
  86. package/dist/cjs/style-card/index.js +15 -18
  87. package/dist/cjs/style-card/style.scss +19 -18
  88. package/dist/cjs/style.scss +43 -0
  89. package/dist/cjs/tabbed-navigation/index.js +27 -31
  90. package/dist/cjs/tabbed-navigation/style.scss +58 -37
  91. package/dist/cjs/text-control/index.js +6 -19
  92. package/dist/cjs/text-control/style.scss +0 -126
  93. package/dist/cjs/utils/index.js +10 -5
  94. package/dist/cjs/waiting/index.js +9 -33
  95. package/dist/cjs/waiting/style.scss +9 -20
  96. package/dist/cjs/web-preview/index.js +30 -57
  97. package/dist/cjs/web-preview/style.scss +41 -34
  98. package/dist/cjs/with-wizard/index.js +55 -33
  99. package/dist/cjs/with-wizard/style.scss +77 -124
  100. package/dist/cjs/with-wizard-screen/index.js +28 -38
  101. package/dist/cjs/with-wizard-screen/style.scss +75 -125
  102. package/dist/cjs/wizard/components/WizardError.js +74 -0
  103. package/dist/cjs/wizard/index.js +131 -0
  104. package/dist/cjs/wizard/store/index.js +165 -0
  105. package/dist/cjs/wizard/store/utils.js +26 -0
  106. package/dist/cjs/wizard/style.scss +148 -0
  107. package/dist/esm/accordion/index.js +38 -0
  108. package/dist/esm/accordion/style.scss +27 -0
  109. package/dist/esm/action-card/index.js +75 -37
  110. package/dist/esm/action-card/style.scss +143 -41
  111. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  112. package/dist/esm/autocomplete-tokenfield/style.scss +6 -6
  113. package/dist/esm/autocomplete-with-suggestions/index.js +31 -43
  114. package/dist/esm/autocomplete-with-suggestions/style.scss +27 -27
  115. package/dist/esm/button/index.js +2 -14
  116. package/dist/esm/button/style.scss +3 -344
  117. package/dist/esm/button-card/index.js +12 -11
  118. package/dist/esm/button-card/style.scss +65 -35
  119. package/dist/esm/card/index.js +5 -6
  120. package/dist/esm/card/style.scss +47 -63
  121. package/dist/esm/category-autocomplete/index.js +68 -41
  122. package/dist/esm/category-autocomplete/style.scss +20 -24
  123. package/dist/esm/color-picker/index.js +17 -38
  124. package/dist/esm/color-picker/style.scss +20 -163
  125. package/dist/esm/consts.js +3 -2
  126. package/dist/esm/custom-select-control/index.js +2 -5
  127. package/dist/esm/custom-select-control/style.scss +14 -45
  128. package/dist/esm/date-range-picker/index.js +1 -3
  129. package/dist/esm/date-range-picker/style.scss +12 -12
  130. package/dist/esm/footer/index.js +22 -16
  131. package/dist/esm/footer/style.scss +13 -14
  132. package/dist/esm/form-token-field/index.js +4 -7
  133. package/dist/esm/form-token-field/style.scss +9 -105
  134. package/dist/esm/global-notices/index.js +3 -7
  135. package/dist/esm/grid/index.js +2 -5
  136. package/dist/esm/grid/style.scss +19 -6
  137. package/dist/esm/handoff/index.js +10 -21
  138. package/dist/esm/handoff-message/index.js +45 -0
  139. package/dist/esm/hooks/index.js +0 -2
  140. package/dist/esm/hooks/useObjectState.js +3 -8
  141. package/dist/esm/hooks/useObjectState.test.js +0 -3
  142. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  143. package/dist/esm/hooks/usePrompt.js +1 -8
  144. package/dist/esm/image-upload/index.js +18 -17
  145. package/dist/esm/image-upload/style.scss +12 -17
  146. package/dist/esm/index.js +7 -8
  147. package/dist/esm/info-button/index.js +4 -6
  148. package/dist/esm/info-button/style.scss +1 -3
  149. package/dist/esm/modal/index.js +2 -8
  150. package/dist/esm/modal/style.scss +20 -132
  151. package/dist/esm/newspack-icon/index.js +6 -7
  152. package/dist/esm/newspack-icon/style.scss +17 -2
  153. package/dist/esm/newspack-logo/index.js +2 -5
  154. package/dist/esm/newspack-logo/style.scss +3 -3
  155. package/dist/esm/notice/index.js +11 -10
  156. package/dist/esm/notice/style.scss +60 -19
  157. package/dist/esm/patrons-logo/index.js +3 -5
  158. package/dist/esm/plugin-installer/index.js +37 -40
  159. package/dist/esm/plugin-installer/style.scss +5 -5
  160. package/dist/esm/plugin-settings/SettingsSection.js +71 -56
  161. package/dist/esm/plugin-settings/index.js +70 -52
  162. package/dist/esm/plugin-settings/style.scss +7 -0
  163. package/dist/esm/plugin-toggle/index.js +59 -34
  164. package/dist/esm/plugin-toggle/style.scss +2 -2
  165. package/dist/esm/popover/index.js +3 -6
  166. package/dist/esm/popover/style.scss +20 -17
  167. package/dist/esm/position-control/index.js +109 -0
  168. package/dist/esm/position-control/style.scss +66 -0
  169. package/dist/esm/progress-bar/index.js +2 -7
  170. package/dist/esm/progress-bar/index.test.js +2 -1
  171. package/dist/esm/progress-bar/style.scss +4 -4
  172. package/dist/esm/proxied-imports/router.js +1 -0
  173. package/dist/esm/radio-control/index.js +3 -6
  174. package/dist/esm/radio-control/style.scss +10 -11
  175. package/dist/esm/section-header/index.js +47 -16
  176. package/dist/esm/section-header/style.scss +22 -1
  177. package/dist/esm/select-control/ButtonGroupControl.js +12 -14
  178. package/dist/esm/select-control/GroupedSelectControl.js +38 -36
  179. package/dist/esm/select-control/index.js +7 -8
  180. package/dist/esm/select-control/style.scss +47 -88
  181. package/dist/esm/settings/MinMaxSetting.js +4 -5
  182. package/dist/esm/settings/SettingsCard.js +9 -5
  183. package/dist/esm/settings/SettingsSection.js +5 -7
  184. package/dist/esm/settings/style.scss +32 -4
  185. package/dist/esm/steps-list/index.js +43 -0
  186. package/dist/esm/steps-list/style.scss +11 -0
  187. package/dist/esm/steps-list-item/index.js +48 -0
  188. package/dist/esm/steps-list-item/style.scss +47 -0
  189. package/dist/esm/style-card/index.js +13 -13
  190. package/dist/esm/style-card/style.scss +19 -18
  191. package/dist/esm/style.scss +43 -0
  192. package/dist/esm/tabbed-navigation/index.js +30 -28
  193. package/dist/esm/tabbed-navigation/style.scss +58 -37
  194. package/dist/esm/text-control/index.js +2 -12
  195. package/dist/esm/text-control/style.scss +0 -126
  196. package/dist/esm/utils/index.js +9 -3
  197. package/dist/esm/waiting/index.js +11 -27
  198. package/dist/esm/waiting/style.scss +9 -20
  199. package/dist/esm/web-preview/index.js +21 -49
  200. package/dist/esm/web-preview/style.scss +41 -34
  201. package/dist/esm/with-wizard/index.js +53 -36
  202. package/dist/esm/with-wizard/style.scss +77 -124
  203. package/dist/esm/with-wizard-screen/index.js +26 -32
  204. package/dist/esm/with-wizard-screen/style.scss +75 -125
  205. package/dist/esm/wizard/components/WizardError.js +69 -0
  206. package/dist/esm/wizard/index.js +126 -0
  207. package/dist/esm/wizard/store/index.js +155 -0
  208. package/dist/esm/wizard/store/utils.js +17 -0
  209. package/dist/esm/wizard/style.scss +148 -0
  210. package/package.json +4 -4
  211. package/src/accordion/index.js +32 -0
  212. package/src/accordion/style.scss +27 -0
  213. package/src/action-card/index.js +70 -25
  214. package/src/action-card/style.scss +143 -41
  215. package/src/autocomplete-tokenfield/index.js +1 -1
  216. package/src/autocomplete-tokenfield/style.scss +6 -6
  217. package/src/autocomplete-with-suggestions/index.js +4 -2
  218. package/src/autocomplete-with-suggestions/style.scss +27 -27
  219. package/src/button/index.js +2 -9
  220. package/src/button/style.scss +3 -344
  221. package/src/button-card/index.js +19 -5
  222. package/src/button-card/style.scss +65 -35
  223. package/src/card/index.js +4 -0
  224. package/src/card/style.scss +47 -63
  225. package/src/category-autocomplete/index.js +53 -18
  226. package/src/category-autocomplete/style.scss +20 -24
  227. package/src/color-picker/index.js +16 -22
  228. package/src/color-picker/style.scss +20 -163
  229. package/src/consts.js +2 -1
  230. package/src/custom-select-control/style.scss +14 -45
  231. package/src/date-range-picker/style.scss +12 -12
  232. package/src/footer/index.js +20 -9
  233. package/src/footer/style.scss +13 -14
  234. package/src/form-token-field/index.js +3 -8
  235. package/src/form-token-field/style.scss +9 -105
  236. package/src/global-notices/index.js +1 -1
  237. package/src/grid/style.scss +19 -6
  238. package/src/handoff/index.js +10 -15
  239. package/src/handoff-message/index.js +39 -0
  240. package/src/hooks/useObjectState.js +2 -1
  241. package/src/image-upload/index.js +9 -3
  242. package/src/image-upload/style.scss +12 -17
  243. package/src/index.js +7 -7
  244. package/src/info-button/style.scss +1 -3
  245. package/src/modal/index.js +2 -5
  246. package/src/modal/style.scss +20 -132
  247. package/src/newspack-icon/index.js +7 -2
  248. package/src/newspack-icon/style.scss +17 -2
  249. package/src/newspack-logo/style.scss +3 -3
  250. package/src/notice/index.js +9 -1
  251. package/src/notice/style.scss +60 -19
  252. package/src/plugin-installer/index.js +17 -4
  253. package/src/plugin-installer/style.scss +5 -5
  254. package/src/plugin-settings/SettingsSection.js +59 -27
  255. package/src/plugin-settings/index.js +29 -8
  256. package/src/plugin-settings/style.scss +7 -0
  257. package/src/plugin-toggle/index.js +37 -12
  258. package/src/plugin-toggle/style.scss +2 -2
  259. package/src/popover/style.scss +20 -17
  260. package/src/position-control/index.js +122 -0
  261. package/src/position-control/style.scss +66 -0
  262. package/src/progress-bar/style.scss +4 -4
  263. package/src/radio-control/style.scss +10 -11
  264. package/src/section-header/index.js +41 -5
  265. package/src/section-header/style.scss +22 -1
  266. package/src/select-control/ButtonGroupControl.js +15 -5
  267. package/src/select-control/GroupedSelectControl.js +28 -25
  268. package/src/select-control/index.js +6 -3
  269. package/src/select-control/style.scss +47 -88
  270. package/src/settings/MinMaxSetting.js +2 -1
  271. package/src/settings/SettingsCard.js +9 -7
  272. package/src/settings/SettingsSection.js +4 -4
  273. package/src/settings/style.scss +32 -4
  274. package/src/steps-list/index.js +39 -0
  275. package/src/steps-list/style.scss +11 -0
  276. package/src/steps-list-item/index.js +40 -0
  277. package/src/steps-list-item/style.scss +47 -0
  278. package/src/style-card/index.js +16 -27
  279. package/src/style-card/style.scss +19 -18
  280. package/src/style.scss +43 -0
  281. package/src/tabbed-navigation/index.js +20 -24
  282. package/src/tabbed-navigation/style.scss +58 -37
  283. package/src/text-control/index.js +1 -2
  284. package/src/text-control/style.scss +0 -126
  285. package/src/utils/index.js +9 -0
  286. package/src/waiting/index.js +7 -18
  287. package/src/waiting/style.scss +9 -20
  288. package/src/web-preview/index.js +13 -34
  289. package/src/web-preview/style.scss +41 -34
  290. package/src/with-wizard/index.js +7 -5
  291. package/src/with-wizard/style.scss +77 -124
  292. package/src/with-wizard-screen/index.js +17 -17
  293. package/src/with-wizard-screen/style.scss +75 -125
  294. package/src/wizard/components/WizardError.js +57 -0
  295. package/src/wizard/index.js +145 -0
  296. package/src/wizard/store/index.js +132 -0
  297. package/src/wizard/store/utils.js +16 -0
  298. package/dist/cjs/wizard-pagination/index.js +0 -71
  299. package/dist/cjs/wizard-pagination/style.scss +0 -74
  300. package/dist/esm/wizard-pagination/index.js +0 -57
  301. package/dist/esm/wizard-pagination/style.scss +0 -74
  302. package/src/button-group/index.js +0 -35
  303. package/src/button-group/style.scss +0 -73
  304. package/src/checkbox-control/index.js +0 -38
  305. package/src/checkbox-control/style.scss +0 -78
  306. package/src/preview-box/index.js +0 -18
  307. package/src/preview-box/style.scss +0 -18
  308. package/src/textarea-control/index.js +0 -32
  309. package/src/textarea-control/style.scss +0 -76
  310. package/src/toggle-control/index.js +0 -38
  311. package/src/toggle-control/style.scss +0 -74
  312. package/src/toggle-group/index.js +0 -43
  313. package/src/toggle-group/style.scss +0 -28
  314. package/src/wizard-pagination/index.js +0 -59
  315. package/src/wizard-pagination/style.scss +0 -74
@@ -1,54 +1,50 @@
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 = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _classnames = _interopRequireDefault(require("classnames"));
13
-
14
10
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
15
-
16
11
  var _element = require("@wordpress/element");
17
-
18
12
  var _i18n = require("@wordpress/i18n");
19
-
20
13
  var _ = require("../");
21
-
22
14
  var _SettingsSection = _interopRequireDefault(require("./SettingsSection"));
23
-
24
15
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
25
-
26
16
  /**
27
17
  * External dependencies
28
18
  */
29
-
30
19
  /**
31
20
  * WordPress dependencies.
32
21
  */
22
+ /**
23
+ * Internal dependencies.
24
+ */
33
25
  const __ = _i18n.__;
34
-
35
26
  class PluginSettings extends _element.Component {
36
27
  constructor() {
37
28
  super(...arguments);
38
29
  (0, _defineProperty2.default)(this, "fetchSettings", () => {
39
30
  const {
40
- pluginSlug
31
+ afterFetch,
32
+ pluginSlug,
33
+ isWizard
41
34
  } = this.props;
42
35
  this.setState({
43
36
  inFlight: true
44
37
  });
45
38
  (0, _apiFetch.default)({
46
- path: `/${pluginSlug}/v1/settings`
39
+ path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`
47
40
  }).then(settings => {
48
41
  this.setState({
49
42
  settings,
50
43
  error: null
51
44
  });
45
+ if ('function' === typeof afterFetch) {
46
+ afterFetch(settings);
47
+ }
52
48
  }).catch(error => {
53
49
  this.setState({
54
50
  error
@@ -60,12 +56,10 @@ class PluginSettings extends _element.Component {
60
56
  });
61
57
  });
62
58
  (0, _defineProperty2.default)(this, "getSettingsValues", sectionKey => {
63
- var _this$state$settings$;
64
-
65
- return ((_this$state$settings$ = this.state.settings[sectionKey]) === null || _this$state$settings$ === void 0 ? void 0 : _this$state$settings$.reduce((map, setting) => {
59
+ return this.state.settings[sectionKey]?.reduce((map, setting) => {
66
60
  map[setting.key] = setting.value;
67
61
  return map;
68
- }, {})) || {};
62
+ }, {}) || {};
69
63
  });
70
64
  (0, _defineProperty2.default)(this, "handleSettingChange", sectionKey => (key, value) => {
71
65
  const sectionSettings = [...this.state.settings[sectionKey]];
@@ -75,20 +69,23 @@ class PluginSettings extends _element.Component {
75
69
  }
76
70
  });
77
71
  this.setState({
78
- settings: { ...this.state.settings,
72
+ settings: {
73
+ ...this.state.settings,
79
74
  [sectionKey]: sectionSettings
80
75
  }
81
76
  });
82
77
  });
83
78
  (0, _defineProperty2.default)(this, "handleSectionUpdate", sectionKey => data => {
84
79
  const {
85
- pluginSlug
80
+ afterUpdate,
81
+ pluginSlug,
82
+ isWizard
86
83
  } = this.props;
87
84
  this.setState({
88
85
  inFlight: true
89
86
  });
90
87
  (0, _apiFetch.default)({
91
- path: `/${pluginSlug}/v1/settings`,
88
+ path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`,
92
89
  method: 'POST',
93
90
  data: {
94
91
  section: sectionKey,
@@ -96,9 +93,15 @@ class PluginSettings extends _element.Component {
96
93
  }
97
94
  }).then(settings => {
98
95
  this.setState({
99
- settings,
96
+ settings: {
97
+ ...this.state.settings,
98
+ [sectionKey]: settings[sectionKey]
99
+ },
100
100
  error: null
101
101
  });
102
+ if ('function' === typeof afterUpdate) {
103
+ afterUpdate(settings);
104
+ }
102
105
  }).catch(error => {
103
106
  this.setState({
104
107
  error
@@ -109,39 +112,57 @@ class PluginSettings extends _element.Component {
109
112
  });
110
113
  });
111
114
  });
115
+ /**
116
+ * Get the section setting containing section information.
117
+ *
118
+ * @param {string} sectionKey The section name.
119
+ * @return {Object} The section setting.
120
+ */
112
121
  (0, _defineProperty2.default)(this, "getSectionInfo", sectionKey => {
113
- var _this$state$settings$2;
114
-
115
- return (_this$state$settings$2 = this.state.settings[sectionKey]) === null || _this$state$settings$2 === void 0 ? void 0 : _this$state$settings$2.find(setting => !setting.key || setting.key === 'active');
122
+ return this.state.settings[sectionKey]?.find(setting => !setting.key || setting.key === 'active');
116
123
  });
124
+ /**
125
+ * Get the section title.
126
+ *
127
+ * @param {string} sectionKey The section name.
128
+ * @return {string} The section title.
129
+ */
117
130
  (0, _defineProperty2.default)(this, "getSectionTitle", sectionKey => {
118
- var _this$getSectionInfo;
119
-
120
- return (_this$getSectionInfo = this.getSectionInfo(sectionKey)) === null || _this$getSectionInfo === void 0 ? void 0 : _this$getSectionInfo.description;
131
+ return this.getSectionInfo(sectionKey)?.description;
121
132
  });
133
+ /**
134
+ * Get the section description.
135
+ *
136
+ * @param {string} sectionKey The section name.
137
+ * @return {string} The section description.
138
+ */
122
139
  (0, _defineProperty2.default)(this, "getSectionDescription", sectionKey => {
123
- var _this$getSectionInfo2;
124
-
125
- return (_this$getSectionInfo2 = this.getSectionInfo(sectionKey)) === null || _this$getSectionInfo2 === void 0 ? void 0 : _this$getSectionInfo2.help;
140
+ return this.getSectionInfo(sectionKey)?.help;
126
141
  });
142
+ /**
143
+ * Get whether a section is active.
144
+ *
145
+ * @param {string} sectionKey The section name.
146
+ * @return {?boolean} Whether the section is active or not. Null if the section is not found or does not support activation.
147
+ */
127
148
  (0, _defineProperty2.default)(this, "isSectionActive", sectionKey => {
128
- var _settings$sectionKey;
129
-
130
149
  const {
131
150
  settings
132
151
  } = this.state;
133
- const activation = (_settings$sectionKey = settings[sectionKey]) === null || _settings$sectionKey === void 0 ? void 0 : _settings$sectionKey.find(setting => setting.key === 'active');
134
-
152
+ const activation = settings[sectionKey]?.find(setting => setting.key === 'active');
135
153
  if (!activation) {
136
154
  return null;
137
155
  }
138
-
139
156
  return activation.value;
140
157
  });
158
+ /**
159
+ * Get list of section field settings.
160
+ *
161
+ * @param {string} sectionKey The section name.
162
+ * @return {?Array} List of section fields.
163
+ */
141
164
  (0, _defineProperty2.default)(this, "getSectionFields", sectionKey => {
142
- var _this$state$settings$3;
143
-
144
- return (_this$state$settings$3 = this.state.settings[sectionKey]) === null || _this$state$settings$3 === void 0 ? void 0 : _this$state$settings$3.filter(setting => setting.key && setting.key !== 'active');
165
+ return this.state.settings[sectionKey]?.filter(setting => setting.key && setting.key !== 'active');
145
166
  });
146
167
  this.state = {
147
168
  inFlight: false,
@@ -149,18 +170,18 @@ class PluginSettings extends _element.Component {
149
170
  error: null
150
171
  };
151
172
  }
152
-
153
173
  componentDidMount() {
154
174
  this.fetchSettings();
155
175
  }
156
-
157
176
  /**
158
177
  * Render.
159
178
  */
160
179
  render() {
161
180
  const {
162
181
  title,
163
- description
182
+ description,
183
+ hasGreyHeader,
184
+ children
164
185
  } = this.props;
165
186
  const {
166
187
  settings,
@@ -168,31 +189,31 @@ class PluginSettings extends _element.Component {
168
189
  error
169
190
  } = this.state;
170
191
  return (0, _jsxRuntime.jsxs)(_element.Fragment, {
171
- children: [(0, _jsxRuntime.jsx)(_.SectionHeader, {
192
+ children: [title && (0, _jsxRuntime.jsx)(_.SectionHeader, {
172
193
  title: title,
173
194
  description: description
174
195
  }), error && (0, _jsxRuntime.jsx)(_.Notice, {
175
196
  isError: true,
176
197
  noticeText: error.message
177
- }), (0, _jsxRuntime.jsx)("div", {
178
- className: (0, _classnames.default)({
198
+ }), (0, _jsxRuntime.jsxs)("div", {
199
+ className: (0, _classnames.default)('newspack-plugin-settings', {
179
200
  'newspack-wizard-section__is-loading': inFlight && !Object.keys(settings).length
180
201
  }),
181
- children: Object.keys(settings).map(sectionKey => (0, _jsxRuntime.jsx)(_SettingsSection.default, {
202
+ children: [Object.keys(settings).map(sectionKey => (0, _jsxRuntime.jsx)(_SettingsSection.default, {
182
203
  disabled: inFlight,
204
+ sectionKey: sectionKey,
183
205
  title: this.getSectionTitle(sectionKey),
184
206
  description: this.getSectionDescription(sectionKey),
185
207
  active: this.isSectionActive(sectionKey),
186
208
  fields: this.getSectionFields(sectionKey),
187
209
  onChange: this.handleSettingChange(sectionKey),
188
- onUpdate: this.handleSectionUpdate(sectionKey)
189
- }, sectionKey))
210
+ onUpdate: this.handleSectionUpdate(sectionKey),
211
+ hasGreyHeader: hasGreyHeader
212
+ }, sectionKey)), children]
190
213
  })]
191
214
  });
192
215
  }
193
-
194
216
  }
195
-
196
217
  PluginSettings.defaultProps = {
197
218
  title: __('General Settings', 'newspack')
198
219
  };
@@ -0,0 +1,7 @@
1
+ .newspack-card:not( .newspack-settings__no-border ) {
2
+ .newspack-action-card__region-children {
3
+ > .newspack-grid {
4
+ margin: 32px 0 0 !important;
5
+ }
6
+ }
7
+ }
@@ -1,31 +1,24 @@
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 = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
13
-
14
10
  var _element = require("@wordpress/element");
15
-
16
11
  var _i18n = require("@wordpress/i18n");
17
-
18
12
  var _ = require("../");
19
-
20
13
  require("./style.scss");
21
-
22
14
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
23
-
24
15
  /**
25
16
  * WordPress dependencies.
26
17
  */
18
+ /**
19
+ * Internal dependencies.
20
+ */
27
21
  const __ = _i18n.__;
28
-
29
22
  /**
30
23
  * Plugin toggle group component.
31
24
  */
@@ -38,6 +31,9 @@ class PluginToggle extends _element.Component {
38
31
  (0, _defineProperty2.default)(this, "componentDidMount", () => {
39
32
  this.retrievePluginInfo();
40
33
  });
34
+ /**
35
+ * Retrieve complete data about Newspack plugins.
36
+ */
41
37
  (0, _defineProperty2.default)(this, "retrievePluginInfo", () => {
42
38
  return new Promise(() => {
43
39
  (0, _apiFetch.default)({
@@ -47,6 +43,9 @@ class PluginToggle extends _element.Component {
47
43
  }));
48
44
  });
49
45
  });
46
+ /**
47
+ * Install/activate or remove a plugin.
48
+ */
50
49
  (0, _defineProperty2.default)(this, "managePlugin", (plugin, value) => {
51
50
  const {
52
51
  plugins
@@ -60,8 +59,10 @@ class PluginToggle extends _element.Component {
60
59
  method: 'post'
61
60
  };
62
61
  this.setState({
63
- pluginInfo: { ...pluginInfo,
64
- [plugin]: { ...pluginInfo[plugin],
62
+ pluginInfo: {
63
+ ...pluginInfo,
64
+ [plugin]: {
65
+ ...pluginInfo[plugin],
65
66
  inFlight: action
66
67
  }
67
68
  }
@@ -75,31 +76,50 @@ class PluginToggle extends _element.Component {
75
76
  pluginInfo: currentPluginInfo
76
77
  } = _ref;
77
78
  return {
78
- pluginInfo: { ...currentPluginInfo,
79
+ pluginInfo: {
80
+ ...currentPluginInfo,
79
81
  [plugin]: response
80
82
  }
81
83
  };
82
84
  }, () => shouldRefreshAfterUpdate && location.reload());
85
+ }).catch(e => {
86
+ this.setState({
87
+ pluginInfo: {
88
+ ...pluginInfo,
89
+ [plugin]: {
90
+ ...pluginInfo[plugin],
91
+ error: e.message || __('There was an error managing this plugin.', 'newspack')
92
+ }
93
+ }
94
+ });
83
95
  });
84
96
  });
85
97
  });
86
- (0, _defineProperty2.default)(this, "prepareDataForRender", (pluginsFromProps, pluginsFromAPI) => Object.keys(pluginsFromProps).map(pluginSlug => pluginsFromAPI[pluginSlug] ? Object.keys(pluginsFromAPI[pluginSlug]).reduce((accumulator, key) => ({ ...accumulator,
98
+ /**
99
+ * Prepare plugins data for render. Change all keys to camelCase, merge API-fetched data with prop.
100
+ */
101
+ (0, _defineProperty2.default)(this, "prepareDataForRender", (pluginsFromProps, pluginsFromAPI) => Object.keys(pluginsFromProps).map(pluginSlug => pluginsFromAPI[pluginSlug] ? Object.keys(pluginsFromAPI[pluginSlug]).reduce((accumulator, key) => ({
102
+ ...accumulator,
87
103
  [key.charAt(0).toLowerCase() + key.slice(1)]: pluginsFromAPI[pluginSlug][key]
88
104
  }), {}) : {}).map(plugin => Object.assign(plugin, pluginsFromProps[plugin.slug])));
105
+ /**
106
+ * Generate a classname for the ActionCard based on plugin state. Applies 'in-flight' class if an API is underway and 'loading' if the plugin data is not yet available.
107
+ */
89
108
  (0, _defineProperty2.default)(this, "classNameForPlugin", plugin => {
90
109
  const {
91
110
  status,
92
111
  inFlight
93
112
  } = plugin;
94
-
95
113
  if (inFlight) {
96
114
  return 'in-flight';
97
115
  }
98
-
99
116
  if (!status) {
100
117
  return 'loading';
101
118
  }
102
119
  });
120
+ /**
121
+ * Generate the ActionCard action text for a plugin.
122
+ */
103
123
  (0, _defineProperty2.default)(this, "actionTextForPlugin", plugin => {
104
124
  const {
105
125
  actionText,
@@ -107,8 +127,8 @@ class PluginToggle extends _element.Component {
107
127
  href,
108
128
  inFlight,
109
129
  name
110
- } = plugin; // Show spinner when plugin data is unavailable, or when an API call is in flight.
111
-
130
+ } = plugin;
131
+ // Show spinner when plugin data is unavailable, or when an API call is in flight.
112
132
  if ('configure' === inFlight) {
113
133
  return (0, _jsxRuntime.jsxs)(_element.Fragment, {
114
134
  children: [__('Installing…', 'newspack'), " ", (0, _jsxRuntime.jsx)(_.Waiting, {
@@ -116,7 +136,6 @@ class PluginToggle extends _element.Component {
116
136
  })]
117
137
  });
118
138
  }
119
-
120
139
  if ('deactivate' === inFlight) {
121
140
  return (0, _jsxRuntime.jsxs)(_element.Fragment, {
122
141
  children: [__('Deactivating…', 'newspack'), " ", (0, _jsxRuntime.jsx)(_.Waiting, {
@@ -124,24 +143,36 @@ class PluginToggle extends _element.Component {
124
143
  })]
125
144
  });
126
145
  }
127
-
128
146
  if (!name) {
129
147
  return (0, _jsxRuntime.jsxs)(_element.Fragment, {
130
148
  children: [__('Loading…', 'newspack'), " ", (0, _jsxRuntime.jsx)(_.Waiting, {
131
149
  isRight: true
132
150
  })]
133
151
  });
134
- } // No action button at all if the plugin isn't installed and active.
135
-
136
-
152
+ }
153
+ // No action button at all if the plugin isn't installed and active.
137
154
  if (!this.isPluginInstalledAndActive(plugin)) {
138
155
  return null;
139
156
  }
140
-
141
157
  if (href || editPath) {
142
158
  return actionText ? actionText : __('Configure', 'newspack');
143
159
  }
144
160
  });
161
+ /**
162
+ * Get error message for this plugin.
163
+ */
164
+ (0, _defineProperty2.default)(this, "errorForPlugin", plugin => {
165
+ const {
166
+ slug
167
+ } = plugin;
168
+ const {
169
+ pluginInfo
170
+ } = this.state;
171
+ return pluginInfo[slug]?.error || null;
172
+ });
173
+ /**
174
+ * Get installation/activation status for a plugin.
175
+ */
145
176
  (0, _defineProperty2.default)(this, "isPluginInstalledAndActive", plugin => {
146
177
  const {
147
178
  status
@@ -149,7 +180,6 @@ class PluginToggle extends _element.Component {
149
180
  return status === 'active';
150
181
  });
151
182
  }
152
-
153
183
  /**
154
184
  * Render.
155
185
  */
@@ -170,6 +200,7 @@ class PluginToggle extends _element.Component {
170
200
  } = plugin;
171
201
  const pluginStatus = this.isPluginInstalledAndActive(plugin);
172
202
  const handoff = !href && pluginStatus && editPath ? slug : null;
203
+ const error = this.errorForPlugin(plugin);
173
204
  return (0, _jsxRuntime.jsx)(_.ActionCard, {
174
205
  className: this.classNameForPlugin(plugin),
175
206
  title: name,
@@ -179,16 +210,13 @@ class PluginToggle extends _element.Component {
179
210
  href: href,
180
211
  toggle: true,
181
212
  toggleChecked: this.isPluginInstalledAndActive(plugin),
182
- toggleOnChange: value => this.managePlugin(slug, value)
213
+ toggleOnChange: value => this.managePlugin(slug, value),
214
+ notification: error,
215
+ notificationHTML: error,
216
+ notificationLevel: "error"
183
217
  }, index);
184
218
  });
185
219
  }
186
- /**
187
- * Prepare plugins data for render. Change all keys to camelCase, merge API-fetched data with prop.
188
- */
189
-
190
-
191
220
  }
192
-
193
221
  var _default = PluginToggle;
194
222
  exports.default = _default;
@@ -2,7 +2,7 @@
2
2
  * Plugin Toggle
3
3
  */
4
4
 
5
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
6
6
 
7
7
  .newspack-action-card {
8
8
  &.in-flight,
@@ -11,7 +11,7 @@
11
11
 
12
12
  .newspack-action-card__region-right {
13
13
  .newspack-button {
14
- color: $gray-700;
14
+ color: wp-colors.$gray-700;
15
15
  pointer-events: none;
16
16
  text-decoration: none;
17
17
  }
@@ -1,22 +1,15 @@
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 = void 0;
9
-
10
8
  var _components = require("@wordpress/components");
11
-
12
9
  var _element = require("@wordpress/element");
13
-
14
10
  require("./style.scss");
15
-
16
11
  var _classnames = _interopRequireDefault(require("classnames"));
17
-
18
12
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
19
-
20
13
  /**
21
14
  * WordPress dependencies
22
15
  */
@@ -31,8 +24,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
31
24
 
32
25
  /**
33
26
  * Popover
34
- */
35
- class Popover extends _element.Component {
27
+ */class Popover extends _element.Component {
36
28
  /**
37
29
  * Render
38
30
  */
@@ -48,9 +40,7 @@ class Popover extends _element.Component {
48
40
  ...otherProps
49
41
  });
50
42
  }
51
-
52
43
  }
53
-
54
44
  Popover.defaultProps = {
55
45
  padding: false
56
46
  };
@@ -2,48 +2,47 @@
2
2
  * Popover
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
- @import '~@wordpress/base-styles/colors';
5
+ @use '../../../shared/scss/colors';
6
+ @use '~@wordpress/base-styles/colors' as wp-colors;
7
7
 
8
8
  .newspack-popover {
9
9
  .components-popover__content {
10
- border: 1px solid $gray-300;
11
- border-radius: 3px;
12
- box-shadow: 0 4px 8px rgba( black, 0.08 );
13
10
  min-width: 238px;
14
11
 
15
12
  .newspack-button {
16
- color: $gray-700;
13
+ color: wp-colors.$gray-700;
17
14
  display: flex;
18
15
  font-weight: normal;
19
16
  padding: 6px 8px;
20
17
 
21
18
  &:hover {
19
+ color: colors.$primary-500;
20
+
22
21
  .components-menu-items__item-icon {
23
- fill: currentColor;
22
+ fill: currentcolor;
24
23
  }
25
24
  }
26
25
 
27
26
  &:focus:not( :disabled ) {
28
- box-shadow: inset 0 0 0 2px $primary-500;
27
+ box-shadow: inset 0 0 0 2px colors.$primary-500;
29
28
  position: relative;
30
29
  z-index: 1;
31
30
  }
32
31
 
33
32
  &.is-link {
34
- border-radius: 3px;
33
+ border-radius: 2px;
35
34
  padding: 6px 8px;
36
35
  text-decoration: none;
37
36
 
38
37
  &:not( .is-destructive ) {
39
- color: $gray-700;
38
+ color: wp-colors.$gray-700;
40
39
 
41
40
  &:active,
42
41
  &:active:enabled,
43
42
  &:focus,
44
43
  &:focus:enabled &:hover,
45
- &:not( :disabled ):not( [aria-disabled='true'] ):not( .is-default ):hover {
46
- color: $primary-500;
44
+ &:not( :disabled, [aria-disabled='true'], .is-default ):hover {
45
+ color: colors.$primary-500;
47
46
  }
48
47
  }
49
48
 
@@ -53,8 +52,12 @@
53
52
  }
54
53
  }
55
54
 
55
+ &.is-destructive:not( :focus ) {
56
+ box-shadow: none !important;
57
+ }
58
+
56
59
  .components-menu-items__item-icon {
57
- fill: $gray-900;
60
+ fill: wp-colors.$gray-900;
58
61
  }
59
62
 
60
63
  .components-menu-item__item {
@@ -64,7 +67,7 @@
64
67
  }
65
68
 
66
69
  .components-menu-group__label {
67
- color: $gray-900;
70
+ color: wp-colors.$gray-900;
68
71
  font-size: 12px;
69
72
  font-weight: bold;
70
73
  line-height: 16px;
@@ -86,8 +89,8 @@
86
89
  min-height: 36px;
87
90
 
88
91
  &:focus ~ div.components-input-control__backdrop {
89
- border-color: $primary-500;
90
- box-shadow: inset 0 0 0 1px $primary-500;
92
+ border-color: colors.$primary-500;
93
+ box-shadow: inset 0 0 0 1px colors.$primary-500;
91
94
  }
92
95
  }
93
96
 
@@ -129,7 +132,7 @@
129
132
  }
130
133
 
131
134
  &:not( .is-without-arrow )::before {
132
- border-color: $gray-300;
135
+ border-color: wp-colors.$gray-300;
133
136
  }
134
137
 
135
138
  &.is-from-bottom {