newspack-components 2.1.0 → 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 (293) 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/button-group/index.js +57 -0
  13. package/dist/cjs/button-group/style.scss +73 -0
  14. package/dist/cjs/card/index.js +1 -8
  15. package/dist/cjs/card/style.scss +25 -8
  16. package/dist/cjs/category-autocomplete/index.js +18 -38
  17. package/dist/cjs/category-autocomplete/style.scss +0 -2
  18. package/dist/cjs/checkbox-control/index.js +63 -0
  19. package/dist/cjs/checkbox-control/style.scss +78 -0
  20. package/dist/cjs/color-picker/index.js +1 -15
  21. package/dist/cjs/color-picker/style.scss +0 -3
  22. package/dist/cjs/consts.js +5 -3
  23. package/dist/cjs/custom-select-control/index.js +1 -9
  24. package/dist/cjs/custom-select-control/style.scss +6 -7
  25. package/dist/cjs/date-range-picker/index.js +1 -10
  26. package/dist/cjs/date-range-picker/style.scss +12 -12
  27. package/dist/cjs/footer/index.js +5 -17
  28. package/dist/cjs/footer/style.scss +5 -5
  29. package/dist/cjs/form-token-field/index.js +1 -9
  30. package/dist/cjs/form-token-field/style.scss +2 -3
  31. package/dist/cjs/global-notices/index.js +1 -8
  32. package/dist/cjs/grid/index.js +1 -8
  33. package/dist/cjs/grid/style.scss +5 -5
  34. package/dist/cjs/handoff/index.js +8 -17
  35. package/dist/cjs/handoff-message/index.js +50 -0
  36. package/dist/cjs/hooks/index.js +1 -7
  37. package/dist/cjs/hooks/useObjectState.js +7 -13
  38. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  39. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  40. package/dist/cjs/hooks/usePrompt.js +1 -13
  41. package/dist/cjs/image-upload/index.js +21 -19
  42. package/dist/cjs/image-upload/index.test.js +0 -5
  43. package/dist/cjs/image-upload/style.scss +5 -9
  44. package/dist/cjs/index.js +28 -44
  45. package/dist/cjs/info-button/index.js +3 -11
  46. package/dist/cjs/info-button/style.scss +1 -3
  47. package/dist/cjs/modal/index.js +1 -9
  48. package/dist/cjs/modal/style.scss +8 -8
  49. package/dist/cjs/newspack-icon/index.js +1 -9
  50. package/dist/cjs/newspack-icon/style.scss +4 -4
  51. package/dist/cjs/newspack-logo/index.js +1 -9
  52. package/dist/cjs/newspack-logo/style.scss +3 -3
  53. package/dist/cjs/notice/index.js +8 -15
  54. package/dist/cjs/notice/style.scss +28 -15
  55. package/dist/cjs/patrons-logo/index.js +3 -11
  56. package/dist/cjs/plugin-installer/index.js +36 -36
  57. package/dist/cjs/plugin-installer/style.scss +5 -5
  58. package/dist/cjs/plugin-settings/SettingsSection.js +9 -28
  59. package/dist/cjs/plugin-settings/index.js +39 -22
  60. package/dist/cjs/plugin-toggle/index.js +40 -33
  61. package/dist/cjs/plugin-toggle/style.scss +2 -2
  62. package/dist/cjs/popover/index.js +1 -11
  63. package/dist/cjs/popover/style.scss +19 -16
  64. package/dist/cjs/position-control/index.js +113 -0
  65. package/dist/cjs/position-control/style.scss +66 -0
  66. package/dist/cjs/preview-box/index.js +36 -0
  67. package/dist/cjs/preview-box/style.scss +18 -0
  68. package/dist/cjs/progress-bar/index.js +2 -9
  69. package/dist/cjs/progress-bar/index.test.js +2 -7
  70. package/dist/cjs/progress-bar/style.scss +4 -4
  71. package/dist/cjs/proxied-imports/router.js +0 -3
  72. package/dist/cjs/radio-control/index.js +1 -11
  73. package/dist/cjs/radio-control/style.scss +9 -9
  74. package/dist/cjs/section-header/index.js +44 -29
  75. package/dist/cjs/section-header/style.scss +2 -2
  76. package/dist/cjs/select-control/ButtonGroupControl.js +4 -13
  77. package/dist/cjs/select-control/GroupedSelectControl.js +9 -15
  78. package/dist/cjs/select-control/index.js +5 -12
  79. package/dist/cjs/select-control/style.scss +2 -2
  80. package/dist/cjs/settings/MinMaxSetting.js +3 -7
  81. package/dist/cjs/settings/SettingsCard.js +3 -7
  82. package/dist/cjs/settings/SettingsSection.js +1 -4
  83. package/dist/cjs/settings/index.js +0 -6
  84. package/dist/cjs/settings/style.scss +1 -1
  85. package/dist/cjs/steps-list/index.js +52 -0
  86. package/dist/cjs/steps-list/style.scss +11 -0
  87. package/dist/cjs/steps-list-item/index.js +56 -0
  88. package/dist/cjs/steps-list-item/style.scss +47 -0
  89. package/dist/cjs/style-card/index.js +6 -13
  90. package/dist/cjs/style-card/style.scss +9 -12
  91. package/dist/cjs/style.scss +5 -6
  92. package/dist/cjs/tabbed-navigation/index.js +19 -16
  93. package/dist/cjs/tabbed-navigation/style.scss +3 -4
  94. package/dist/cjs/text-control/index.js +6 -16
  95. package/dist/cjs/textarea-control/index.js +54 -0
  96. package/dist/cjs/textarea-control/style.scss +76 -0
  97. package/dist/cjs/toggle-control/index.js +58 -0
  98. package/dist/cjs/toggle-control/style.scss +74 -0
  99. package/dist/cjs/toggle-group/index.js +71 -0
  100. package/dist/cjs/toggle-group/style.scss +28 -0
  101. package/dist/cjs/utils/index.js +10 -5
  102. package/dist/cjs/waiting/index.js +1 -9
  103. package/dist/cjs/web-preview/index.js +13 -28
  104. package/dist/cjs/web-preview/style.scss +14 -14
  105. package/dist/cjs/with-wizard/index.js +51 -31
  106. package/dist/cjs/with-wizard/style.scss +35 -37
  107. package/dist/cjs/with-wizard-screen/index.js +11 -17
  108. package/dist/cjs/with-wizard-screen/style.scss +14 -17
  109. package/dist/cjs/wizard/components/WizardError.js +3 -15
  110. package/dist/cjs/wizard/index.js +10 -24
  111. package/dist/cjs/wizard/store/index.js +42 -55
  112. package/dist/cjs/wizard/store/utils.js +1 -6
  113. package/dist/cjs/wizard/style.scss +148 -0
  114. package/dist/esm/accordion/index.js +38 -0
  115. package/dist/esm/accordion/style.scss +27 -0
  116. package/dist/esm/action-card/index.js +50 -21
  117. package/dist/esm/action-card/style.scss +100 -23
  118. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  119. package/dist/esm/autocomplete-tokenfield/style.scss +2 -2
  120. package/dist/esm/autocomplete-with-suggestions/index.js +28 -41
  121. package/dist/esm/autocomplete-with-suggestions/style.scss +16 -15
  122. package/dist/esm/button/index.js +5 -7
  123. package/dist/esm/button-card/index.js +2 -5
  124. package/dist/esm/button-card/style.scss +13 -13
  125. package/dist/esm/button-group/index.js +43 -0
  126. package/dist/esm/button-group/style.scss +73 -0
  127. package/dist/esm/card/index.js +2 -5
  128. package/dist/esm/card/style.scss +25 -8
  129. package/dist/esm/category-autocomplete/index.js +17 -30
  130. package/dist/esm/category-autocomplete/style.scss +0 -2
  131. package/dist/esm/checkbox-control/index.js +49 -0
  132. package/dist/esm/checkbox-control/style.scss +78 -0
  133. package/dist/esm/color-picker/index.js +2 -4
  134. package/dist/esm/color-picker/style.scss +0 -3
  135. package/dist/esm/consts.js +3 -2
  136. package/dist/esm/custom-select-control/index.js +2 -5
  137. package/dist/esm/custom-select-control/style.scss +6 -7
  138. package/dist/esm/date-range-picker/index.js +1 -3
  139. package/dist/esm/date-range-picker/style.scss +12 -12
  140. package/dist/esm/footer/index.js +3 -11
  141. package/dist/esm/footer/style.scss +5 -5
  142. package/dist/esm/form-token-field/index.js +2 -5
  143. package/dist/esm/form-token-field/style.scss +2 -3
  144. package/dist/esm/global-notices/index.js +1 -6
  145. package/dist/esm/grid/index.js +2 -5
  146. package/dist/esm/grid/style.scss +5 -5
  147. package/dist/esm/handoff/index.js +3 -14
  148. package/dist/esm/handoff-message/index.js +45 -0
  149. package/dist/esm/hooks/index.js +0 -2
  150. package/dist/esm/hooks/useObjectState.js +3 -8
  151. package/dist/esm/hooks/useObjectState.test.js +0 -3
  152. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  153. package/dist/esm/hooks/usePrompt.js +1 -8
  154. package/dist/esm/image-upload/index.js +17 -16
  155. package/dist/esm/image-upload/style.scss +5 -9
  156. package/dist/esm/index.js +4 -0
  157. package/dist/esm/info-button/index.js +4 -6
  158. package/dist/esm/info-button/style.scss +1 -3
  159. package/dist/esm/modal/index.js +2 -5
  160. package/dist/esm/modal/style.scss +8 -8
  161. package/dist/esm/newspack-icon/index.js +2 -5
  162. package/dist/esm/newspack-icon/style.scss +4 -4
  163. package/dist/esm/newspack-logo/index.js +2 -5
  164. package/dist/esm/newspack-logo/style.scss +3 -3
  165. package/dist/esm/notice/index.js +4 -8
  166. package/dist/esm/notice/style.scss +28 -15
  167. package/dist/esm/patrons-logo/index.js +3 -5
  168. package/dist/esm/plugin-installer/index.js +35 -39
  169. package/dist/esm/plugin-installer/style.scss +5 -5
  170. package/dist/esm/plugin-settings/SettingsSection.js +8 -21
  171. package/dist/esm/plugin-settings/index.js +38 -24
  172. package/dist/esm/plugin-toggle/index.js +39 -36
  173. package/dist/esm/plugin-toggle/style.scss +2 -2
  174. package/dist/esm/popover/index.js +3 -6
  175. package/dist/esm/popover/style.scss +19 -16
  176. package/dist/esm/position-control/index.js +109 -0
  177. package/dist/esm/position-control/style.scss +66 -0
  178. package/dist/esm/preview-box/index.js +30 -0
  179. package/dist/esm/preview-box/style.scss +18 -0
  180. package/dist/esm/progress-bar/index.js +2 -7
  181. package/dist/esm/progress-bar/index.test.js +2 -1
  182. package/dist/esm/progress-bar/style.scss +4 -4
  183. package/dist/esm/proxied-imports/router.js +1 -0
  184. package/dist/esm/radio-control/index.js +3 -6
  185. package/dist/esm/radio-control/style.scss +9 -9
  186. package/dist/esm/section-header/index.js +44 -25
  187. package/dist/esm/section-header/style.scss +2 -2
  188. package/dist/esm/select-control/ButtonGroupControl.js +5 -7
  189. package/dist/esm/select-control/GroupedSelectControl.js +5 -6
  190. package/dist/esm/select-control/index.js +6 -6
  191. package/dist/esm/select-control/style.scss +2 -2
  192. package/dist/esm/settings/MinMaxSetting.js +1 -3
  193. package/dist/esm/settings/SettingsCard.js +3 -4
  194. package/dist/esm/settings/SettingsSection.js +0 -2
  195. package/dist/esm/settings/style.scss +1 -1
  196. package/dist/esm/steps-list/index.js +43 -0
  197. package/dist/esm/steps-list/style.scss +11 -0
  198. package/dist/esm/steps-list-item/index.js +48 -0
  199. package/dist/esm/steps-list-item/style.scss +47 -0
  200. package/dist/esm/style-card/index.js +2 -5
  201. package/dist/esm/style-card/style.scss +9 -12
  202. package/dist/esm/style.scss +5 -6
  203. package/dist/esm/tabbed-navigation/index.js +20 -10
  204. package/dist/esm/tabbed-navigation/style.scss +3 -4
  205. package/dist/esm/text-control/index.js +2 -9
  206. package/dist/esm/textarea-control/index.js +40 -0
  207. package/dist/esm/textarea-control/style.scss +76 -0
  208. package/dist/esm/toggle-control/index.js +44 -0
  209. package/dist/esm/toggle-control/style.scss +74 -0
  210. package/dist/esm/toggle-group/index.js +58 -0
  211. package/dist/esm/toggle-group/style.scss +28 -0
  212. package/dist/esm/utils/index.js +9 -3
  213. package/dist/esm/waiting/index.js +2 -5
  214. package/dist/esm/web-preview/index.js +9 -24
  215. package/dist/esm/web-preview/style.scss +14 -14
  216. package/dist/esm/with-wizard/index.js +49 -34
  217. package/dist/esm/with-wizard/style.scss +35 -37
  218. package/dist/esm/with-wizard-screen/index.js +9 -11
  219. package/dist/esm/with-wizard-screen/style.scss +14 -17
  220. package/dist/esm/wizard/components/WizardError.js +1 -10
  221. package/dist/esm/wizard/index.js +10 -12
  222. package/dist/esm/wizard/store/index.js +40 -46
  223. package/dist/esm/wizard/store/utils.js +1 -1
  224. package/dist/esm/wizard/style.scss +148 -0
  225. package/package.json +4 -4
  226. package/shared/scss/_colors.scss +0 -15
  227. package/src/accordion/index.js +32 -0
  228. package/src/accordion/style.scss +27 -0
  229. package/src/action-card/index.js +43 -8
  230. package/src/action-card/style.scss +100 -23
  231. package/src/autocomplete-tokenfield/index.js +1 -1
  232. package/src/autocomplete-tokenfield/style.scss +2 -2
  233. package/src/autocomplete-with-suggestions/style.scss +16 -15
  234. package/src/button-card/style.scss +13 -13
  235. package/src/card/style.scss +25 -8
  236. package/src/category-autocomplete/index.js +3 -1
  237. package/src/category-autocomplete/style.scss +0 -2
  238. package/src/color-picker/style.scss +0 -3
  239. package/src/consts.js +2 -1
  240. package/src/custom-select-control/style.scss +6 -7
  241. package/src/date-range-picker/style.scss +12 -12
  242. package/src/footer/index.js +2 -2
  243. package/src/footer/style.scss +5 -5
  244. package/src/form-token-field/index.js +2 -7
  245. package/src/form-token-field/style.scss +2 -3
  246. package/src/grid/style.scss +5 -5
  247. package/src/handoff/index.js +3 -8
  248. package/src/handoff-message/index.js +39 -0
  249. package/src/hooks/useObjectState.js +2 -1
  250. package/src/image-upload/index.js +9 -3
  251. package/src/image-upload/style.scss +5 -9
  252. package/src/index.js +4 -0
  253. package/src/info-button/style.scss +1 -3
  254. package/src/modal/style.scss +8 -8
  255. package/src/newspack-icon/style.scss +4 -4
  256. package/src/newspack-logo/style.scss +3 -3
  257. package/src/notice/index.js +2 -0
  258. package/src/notice/style.scss +28 -15
  259. package/src/plugin-installer/index.js +15 -2
  260. package/src/plugin-installer/style.scss +5 -5
  261. package/src/plugin-settings/SettingsSection.js +7 -13
  262. package/src/plugin-settings/index.js +7 -2
  263. package/src/plugin-toggle/index.js +2 -3
  264. package/src/plugin-toggle/style.scss +2 -2
  265. package/src/popover/style.scss +19 -16
  266. package/src/position-control/index.js +122 -0
  267. package/src/position-control/style.scss +66 -0
  268. package/src/progress-bar/style.scss +4 -4
  269. package/src/radio-control/style.scss +9 -9
  270. package/src/section-header/index.js +32 -15
  271. package/src/section-header/style.scss +2 -2
  272. package/src/select-control/ButtonGroupControl.js +3 -0
  273. package/src/select-control/GroupedSelectControl.js +2 -1
  274. package/src/select-control/index.js +6 -2
  275. package/src/select-control/style.scss +2 -2
  276. package/src/settings/style.scss +1 -1
  277. package/src/steps-list/index.js +39 -0
  278. package/src/steps-list/style.scss +11 -0
  279. package/src/steps-list-item/index.js +40 -0
  280. package/src/steps-list-item/style.scss +47 -0
  281. package/src/style-card/index.js +2 -11
  282. package/src/style-card/style.scss +9 -12
  283. package/src/style.scss +5 -6
  284. package/src/tabbed-navigation/index.js +12 -4
  285. package/src/tabbed-navigation/style.scss +3 -4
  286. package/src/utils/index.js +9 -0
  287. package/src/web-preview/index.js +1 -1
  288. package/src/web-preview/style.scss +14 -14
  289. package/src/with-wizard/style.scss +35 -37
  290. package/src/with-wizard-screen/index.js +4 -1
  291. package/src/with-wizard-screen/style.scss +14 -17
  292. package/src/wizard/index.js +15 -3
  293. package/src/wizard/store/index.js +8 -2
@@ -2,7 +2,7 @@
2
2
  * Plugin Installer
3
3
  */
4
4
 
5
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
6
6
 
7
7
  .newspack-card {
8
8
  .newspack-plugin-installer__status {
@@ -35,10 +35,10 @@
35
35
  }
36
36
 
37
37
  &.newspack-plugin-installer__status-active {
38
- box-shadow: inset 4px 0 0 $alert-green;
38
+ box-shadow: inset 4px 0 0 wp-colors.$alert-green;
39
39
 
40
40
  .newspack-plugin-installer__checkbox {
41
- background: $alert-green;
41
+ background: wp-colors.$alert-green;
42
42
  box-shadow: none;
43
43
  }
44
44
 
@@ -48,12 +48,12 @@
48
48
  }
49
49
 
50
50
  &.newspack-plugin-installer__status-error {
51
- box-shadow: inset 4px 0 0 $alert-red;
51
+ box-shadow: inset 4px 0 0 wp-colors.$alert-red;
52
52
  }
53
53
 
54
54
  &.newspack-plugin-installer__status-installing,
55
55
  &.newspack-plugin-installer__status-none {
56
- box-shadow: inset 4px 0 0 $gray-100;
56
+ box-shadow: inset 4px 0 0 wp-colors.$gray-100;
57
57
  }
58
58
 
59
59
  // Is Small
@@ -5,39 +5,34 @@
5
5
  /**
6
6
  * WordPress dependencies
7
7
  */
8
- import { Fragment } from '@wordpress/element';
8
+ import { Fragment, useState } from '@wordpress/element';
9
9
  import { applyFilters } from '@wordpress/hooks';
10
10
  import { __ as alias__ } from '@wordpress/i18n';
11
11
  const __ = alias__;
12
12
  import { CheckboxControl } from '@wordpress/components';
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
16
-
17
17
  import { ActionCard, Button, Grid, Notice, SelectControl, TextControl } from '../';
18
18
  import './style.scss';
19
19
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
20
20
  import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
21
-
22
21
  const isSelectControl = setting => {
23
22
  return Array.isArray(setting.options) && setting.options.length;
24
23
  };
25
-
26
24
  const getControlComponent = setting => {
27
25
  if (isSelectControl(setting)) {
28
26
  return SelectControl;
29
27
  }
30
-
31
28
  switch (setting.type) {
32
29
  case 'checkbox':
33
30
  case 'boolean':
34
31
  return CheckboxControl;
35
-
36
32
  default:
37
33
  return TextControl;
38
34
  }
39
35
  };
40
-
41
36
  const getControlType = setting => {
42
37
  switch (setting.type) {
43
38
  case 'int':
@@ -45,24 +40,20 @@ const getControlType = setting => {
45
40
  case 'float':
46
41
  case 'number':
47
42
  return 'number';
48
-
49
43
  case 'string':
50
44
  case 'text':
51
45
  return 'text';
52
-
53
46
  case 'password':
54
47
  return 'password';
55
-
56
48
  case 'boolean':
57
49
  case 'checkbox':
58
50
  return 'checkbox';
59
-
60
51
  default:
61
52
  return null;
62
53
  }
63
54
  };
64
-
65
55
  const SettingsSection = props => {
56
+ const [saveDisabled, setSaveDisabled] = useState(true);
66
57
  const {
67
58
  error,
68
59
  sectionKey,
@@ -74,7 +65,6 @@ const SettingsSection = props => {
74
65
  onChange,
75
66
  onUpdate
76
67
  } = props;
77
-
78
68
  const getControlProps = setting => ({
79
69
  disabled,
80
70
  name: `${setting.section}_${setting.key}`,
@@ -90,22 +80,19 @@ const SettingsSection = props => {
90
80
  checked: setting.type === 'boolean' ? !!setting.value : null,
91
81
  onChange: value => {
92
82
  onChange(setting.key, value);
83
+ setSaveDisabled(false);
93
84
  }
94
85
  });
95
-
96
86
  const createFilter = function (name) {
97
87
  let defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
98
88
  return applyFilters(`newspack.settingSection.${sectionKey}.${name}`, defaultComponent, props);
99
89
  };
100
-
101
90
  let columns = 2;
102
-
103
91
  if (fields.length % 3 === 0) {
104
92
  columns = 3;
105
93
  } else if (fields.length === 1) {
106
94
  columns = 1;
107
95
  }
108
-
109
96
  return _jsx(ActionCard, {
110
97
  isMedium: true,
111
98
  disabled: disabled,
@@ -118,9 +105,10 @@ const SettingsSection = props => {
118
105
  }) : null,
119
106
  actionContent: (active || null === active) && createFilter('buttons', _jsx(Button, {
120
107
  variant: "primary",
121
- disabled: disabled,
108
+ disabled: disabled || saveDisabled,
122
109
  onClick: () => {
123
110
  onUpdate();
111
+ setSaveDisabled(true);
124
112
  },
125
113
  children: __('Save Settings', 'newspack')
126
114
  })),
@@ -133,8 +121,8 @@ const SettingsSection = props => {
133
121
  gutter: 32,
134
122
  children: fields.map(setting => {
135
123
  const Control = getControlComponent(setting); // eslint-disable-line @wordpress/no-unused-vars-before-return, no-unused-vars
136
-
137
- return applyFilters(`newspack.settingsSection.${sectionKey}.control`, _jsx(Control, { ...getControlProps(setting)
124
+ return applyFilters(`newspack.settingsSection.${sectionKey}.control`, _jsx(Control, {
125
+ ...getControlProps(setting)
138
126
  }, setting.key), {
139
127
  sectionKey,
140
128
  setting,
@@ -145,5 +133,4 @@ const SettingsSection = props => {
145
133
  })
146
134
  });
147
135
  };
148
-
149
136
  export default SettingsSection;
@@ -1,30 +1,27 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
2
  /**
4
3
  * External dependencies
5
4
  */
6
5
  import classnames from 'classnames';
6
+
7
7
  /**
8
8
  * WordPress dependencies.
9
9
  */
10
-
11
10
  import apiFetch from '@wordpress/api-fetch';
12
11
  import { Component, Fragment } from '@wordpress/element';
13
12
  import { __ as alias__ } from '@wordpress/i18n';
13
+
14
14
  /**
15
15
  * Internal dependencies.
16
16
  */
17
-
18
17
  const __ = alias__;
19
18
  import { SectionHeader, Notice } from '../';
20
19
  import SettingsSection from './SettingsSection';
21
20
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
22
21
  import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
23
-
24
22
  class PluginSettings extends Component {
25
23
  constructor() {
26
24
  super(...arguments);
27
-
28
25
  _defineProperty(this, "fetchSettings", () => {
29
26
  const {
30
27
  afterFetch,
@@ -41,7 +38,6 @@ class PluginSettings extends Component {
41
38
  settings,
42
39
  error: null
43
40
  });
44
-
45
41
  if ('function' === typeof afterFetch) {
46
42
  afterFetch(settings);
47
43
  }
@@ -55,14 +51,12 @@ class PluginSettings extends Component {
55
51
  });
56
52
  });
57
53
  });
58
-
59
54
  _defineProperty(this, "getSettingsValues", sectionKey => {
60
55
  return this.state.settings[sectionKey]?.reduce((map, setting) => {
61
56
  map[setting.key] = setting.value;
62
57
  return map;
63
58
  }, {}) || {};
64
59
  });
65
-
66
60
  _defineProperty(this, "handleSettingChange", sectionKey => (key, value) => {
67
61
  const sectionSettings = [...this.state.settings[sectionKey]];
68
62
  sectionSettings.forEach(setting => {
@@ -71,12 +65,12 @@ class PluginSettings extends Component {
71
65
  }
72
66
  });
73
67
  this.setState({
74
- settings: { ...this.state.settings,
68
+ settings: {
69
+ ...this.state.settings,
75
70
  [sectionKey]: sectionSettings
76
71
  }
77
72
  });
78
73
  });
79
-
80
74
  _defineProperty(this, "handleSectionUpdate", sectionKey => data => {
81
75
  const {
82
76
  afterUpdate,
@@ -95,10 +89,12 @@ class PluginSettings extends Component {
95
89
  }
96
90
  }).then(settings => {
97
91
  this.setState({
98
- settings,
92
+ settings: {
93
+ ...this.state.settings,
94
+ [sectionKey]: settings[sectionKey]
95
+ },
99
96
  error: null
100
97
  });
101
-
102
98
  if ('function' === typeof afterUpdate) {
103
99
  afterUpdate(settings);
104
100
  }
@@ -112,47 +108,67 @@ class PluginSettings extends Component {
112
108
  });
113
109
  });
114
110
  });
115
-
111
+ /**
112
+ * Get the section setting containing section information.
113
+ *
114
+ * @param {string} sectionKey The section name.
115
+ * @return {Object} The section setting.
116
+ */
116
117
  _defineProperty(this, "getSectionInfo", sectionKey => {
117
118
  return this.state.settings[sectionKey]?.find(setting => !setting.key || setting.key === 'active');
118
119
  });
119
-
120
+ /**
121
+ * Get the section title.
122
+ *
123
+ * @param {string} sectionKey The section name.
124
+ * @return {string} The section title.
125
+ */
120
126
  _defineProperty(this, "getSectionTitle", sectionKey => {
121
127
  return this.getSectionInfo(sectionKey)?.description;
122
128
  });
123
-
129
+ /**
130
+ * Get the section description.
131
+ *
132
+ * @param {string} sectionKey The section name.
133
+ * @return {string} The section description.
134
+ */
124
135
  _defineProperty(this, "getSectionDescription", sectionKey => {
125
136
  return this.getSectionInfo(sectionKey)?.help;
126
137
  });
127
-
138
+ /**
139
+ * Get whether a section is active.
140
+ *
141
+ * @param {string} sectionKey The section name.
142
+ * @return {?boolean} Whether the section is active or not. Null if the section is not found or does not support activation.
143
+ */
128
144
  _defineProperty(this, "isSectionActive", sectionKey => {
129
145
  const {
130
146
  settings
131
147
  } = this.state;
132
148
  const activation = settings[sectionKey]?.find(setting => setting.key === 'active');
133
-
134
149
  if (!activation) {
135
150
  return null;
136
151
  }
137
-
138
152
  return activation.value;
139
153
  });
140
-
154
+ /**
155
+ * Get list of section field settings.
156
+ *
157
+ * @param {string} sectionKey The section name.
158
+ * @return {?Array} List of section fields.
159
+ */
141
160
  _defineProperty(this, "getSectionFields", sectionKey => {
142
161
  return this.state.settings[sectionKey]?.filter(setting => setting.key && setting.key !== 'active');
143
162
  });
144
-
145
163
  this.state = {
146
164
  inFlight: false,
147
165
  settings: {},
148
166
  error: null
149
167
  };
150
168
  }
151
-
152
169
  componentDidMount() {
153
170
  this.fetchSettings();
154
171
  }
155
-
156
172
  /**
157
173
  * Render.
158
174
  */
@@ -193,9 +209,7 @@ class PluginSettings extends Component {
193
209
  })]
194
210
  });
195
211
  }
196
-
197
212
  }
198
-
199
213
  PluginSettings.defaultProps = {
200
214
  title: __('General Settings', 'newspack')
201
215
  };
@@ -1,37 +1,35 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
2
  /**
4
3
  * WordPress dependencies.
5
4
  */
6
5
  import apiFetch from '@wordpress/api-fetch';
7
6
  import { Component, Fragment } from '@wordpress/element';
8
7
  import { __ as alias__ } from '@wordpress/i18n';
8
+
9
9
  /**
10
10
  * Internal dependencies.
11
11
  */
12
-
13
12
  const __ = alias__;
14
13
  import { ActionCard, Waiting } from '../';
15
14
  import './style.scss';
15
+
16
16
  /**
17
17
  * Plugin toggle group component.
18
18
  */
19
-
20
19
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
21
20
  import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
22
-
23
21
  class PluginToggle extends Component {
24
22
  constructor() {
25
23
  super(...arguments);
26
-
27
24
  _defineProperty(this, "state", {
28
25
  pluginInfo: {}
29
26
  });
30
-
31
27
  _defineProperty(this, "componentDidMount", () => {
32
28
  this.retrievePluginInfo();
33
29
  });
34
-
30
+ /**
31
+ * Retrieve complete data about Newspack plugins.
32
+ */
35
33
  _defineProperty(this, "retrievePluginInfo", () => {
36
34
  return new Promise(() => {
37
35
  apiFetch({
@@ -41,7 +39,9 @@ class PluginToggle extends Component {
41
39
  }));
42
40
  });
43
41
  });
44
-
42
+ /**
43
+ * Install/activate or remove a plugin.
44
+ */
45
45
  _defineProperty(this, "managePlugin", (plugin, value) => {
46
46
  const {
47
47
  plugins
@@ -55,8 +55,10 @@ class PluginToggle extends Component {
55
55
  method: 'post'
56
56
  };
57
57
  this.setState({
58
- pluginInfo: { ...pluginInfo,
59
- [plugin]: { ...pluginInfo[plugin],
58
+ pluginInfo: {
59
+ ...pluginInfo,
60
+ [plugin]: {
61
+ ...pluginInfo[plugin],
60
62
  inFlight: action
61
63
  }
62
64
  }
@@ -70,15 +72,18 @@ class PluginToggle extends Component {
70
72
  pluginInfo: currentPluginInfo
71
73
  } = _ref;
72
74
  return {
73
- pluginInfo: { ...currentPluginInfo,
75
+ pluginInfo: {
76
+ ...currentPluginInfo,
74
77
  [plugin]: response
75
78
  }
76
79
  };
77
80
  }, () => shouldRefreshAfterUpdate && location.reload());
78
81
  }).catch(e => {
79
82
  this.setState({
80
- pluginInfo: { ...pluginInfo,
81
- [plugin]: { ...pluginInfo[plugin],
83
+ pluginInfo: {
84
+ ...pluginInfo,
85
+ [plugin]: {
86
+ ...pluginInfo[plugin],
82
87
  error: e.message || __('There was an error managing this plugin.', 'newspack')
83
88
  }
84
89
  }
@@ -86,26 +91,31 @@ class PluginToggle extends Component {
86
91
  });
87
92
  });
88
93
  });
89
-
90
- _defineProperty(this, "prepareDataForRender", (pluginsFromProps, pluginsFromAPI) => Object.keys(pluginsFromProps).map(pluginSlug => pluginsFromAPI[pluginSlug] ? Object.keys(pluginsFromAPI[pluginSlug]).reduce((accumulator, key) => ({ ...accumulator,
94
+ /**
95
+ * Prepare plugins data for render. Change all keys to camelCase, merge API-fetched data with prop.
96
+ */
97
+ _defineProperty(this, "prepareDataForRender", (pluginsFromProps, pluginsFromAPI) => Object.keys(pluginsFromProps).map(pluginSlug => pluginsFromAPI[pluginSlug] ? Object.keys(pluginsFromAPI[pluginSlug]).reduce((accumulator, key) => ({
98
+ ...accumulator,
91
99
  [key.charAt(0).toLowerCase() + key.slice(1)]: pluginsFromAPI[pluginSlug][key]
92
100
  }), {}) : {}).map(plugin => Object.assign(plugin, pluginsFromProps[plugin.slug])));
93
-
101
+ /**
102
+ * 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.
103
+ */
94
104
  _defineProperty(this, "classNameForPlugin", plugin => {
95
105
  const {
96
106
  status,
97
107
  inFlight
98
108
  } = plugin;
99
-
100
109
  if (inFlight) {
101
110
  return 'in-flight';
102
111
  }
103
-
104
112
  if (!status) {
105
113
  return 'loading';
106
114
  }
107
115
  });
108
-
116
+ /**
117
+ * Generate the ActionCard action text for a plugin.
118
+ */
109
119
  _defineProperty(this, "actionTextForPlugin", plugin => {
110
120
  const {
111
121
  actionText,
@@ -113,8 +123,8 @@ class PluginToggle extends Component {
113
123
  href,
114
124
  inFlight,
115
125
  name
116
- } = plugin; // Show spinner when plugin data is unavailable, or when an API call is in flight.
117
-
126
+ } = plugin;
127
+ // Show spinner when plugin data is unavailable, or when an API call is in flight.
118
128
  if ('configure' === inFlight) {
119
129
  return _jsxs(Fragment, {
120
130
  children: [__('Installing…', 'newspack'), " ", _jsx(Waiting, {
@@ -122,7 +132,6 @@ class PluginToggle extends Component {
122
132
  })]
123
133
  });
124
134
  }
125
-
126
135
  if ('deactivate' === inFlight) {
127
136
  return _jsxs(Fragment, {
128
137
  children: [__('Deactivating…', 'newspack'), " ", _jsx(Waiting, {
@@ -130,25 +139,24 @@ class PluginToggle extends Component {
130
139
  })]
131
140
  });
132
141
  }
133
-
134
142
  if (!name) {
135
143
  return _jsxs(Fragment, {
136
144
  children: [__('Loading…', 'newspack'), " ", _jsx(Waiting, {
137
145
  isRight: true
138
146
  })]
139
147
  });
140
- } // No action button at all if the plugin isn't installed and active.
141
-
142
-
148
+ }
149
+ // No action button at all if the plugin isn't installed and active.
143
150
  if (!this.isPluginInstalledAndActive(plugin)) {
144
151
  return null;
145
152
  }
146
-
147
153
  if (href || editPath) {
148
154
  return actionText ? actionText : __('Configure', 'newspack');
149
155
  }
150
156
  });
151
-
157
+ /**
158
+ * Get error message for this plugin.
159
+ */
152
160
  _defineProperty(this, "errorForPlugin", plugin => {
153
161
  const {
154
162
  slug
@@ -158,7 +166,9 @@ class PluginToggle extends Component {
158
166
  } = this.state;
159
167
  return pluginInfo[slug]?.error || null;
160
168
  });
161
-
169
+ /**
170
+ * Get installation/activation status for a plugin.
171
+ */
162
172
  _defineProperty(this, "isPluginInstalledAndActive", plugin => {
163
173
  const {
164
174
  status
@@ -166,7 +176,6 @@ class PluginToggle extends Component {
166
176
  return status === 'active';
167
177
  });
168
178
  }
169
-
170
179
  /**
171
180
  * Render.
172
181
  */
@@ -204,11 +213,5 @@ class PluginToggle extends Component {
204
213
  }, index);
205
214
  });
206
215
  }
207
- /**
208
- * Prepare plugins data for render. Change all keys to camelCase, merge API-fetched data with prop.
209
- */
210
-
211
-
212
216
  }
213
-
214
217
  export default PluginToggle;
@@ -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
  }
@@ -3,22 +3,21 @@
3
3
  */
4
4
  import { Popover as BaseComponent } from '@wordpress/components';
5
5
  import { Component } from '@wordpress/element';
6
+
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
-
10
10
  import './style.scss';
11
+
11
12
  /**
12
13
  * External dependencies
13
14
  */
14
-
15
15
  import classnames from 'classnames';
16
+
16
17
  /**
17
18
  * Popover
18
19
  */
19
-
20
20
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
21
-
22
21
  class Popover extends Component {
23
22
  /**
24
23
  * Render
@@ -35,9 +34,7 @@ class Popover extends Component {
35
34
  ...otherProps
36
35
  });
37
36
  }
38
-
39
37
  }
40
-
41
38
  Popover.defaultProps = {
42
39
  padding: false
43
40
  };
@@ -2,30 +2,29 @@
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: 2px;
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
  }
@@ -36,14 +35,14 @@
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 {