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,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 {
@@ -0,0 +1,109 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ as alias__ } from '@wordpress/i18n';
5
+ const __ = alias__;
6
+ import { ButtonGroup, Button } from '@wordpress/components';
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ import classnames from 'classnames';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import './style.scss';
17
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
19
+ export default function PositionControl(_ref) {
20
+ let {
21
+ allowedPositions,
22
+ value,
23
+ label,
24
+ help,
25
+ onChange,
26
+ size,
27
+ ...props
28
+ } = _ref;
29
+ /**
30
+ * Set layout options
31
+ */
32
+ const options = size === 'full-width' ? [{
33
+ value: 'top',
34
+ /* translators: Overlay Position */
35
+ label: __('Top', 'newspack')
36
+ }, {
37
+ value: 'center',
38
+ /* translators: Overlay Position */
39
+ label: __('Center', 'newspack')
40
+ }, {
41
+ value: 'bottom',
42
+ /* translators: Overlay Position */
43
+ label: __('Bottom', 'newspack')
44
+ }] : [{
45
+ value: 'top_left',
46
+ /* translators: Overlay Position */
47
+ label: __('Top Left', 'newspack')
48
+ }, {
49
+ value: 'top',
50
+ /* translators: Overlay Position */
51
+ label: __('Top Center', 'newspack')
52
+ }, {
53
+ value: 'top_right',
54
+ /* translators: Overlay Position */
55
+ label: __('Top Right', 'newspack')
56
+ }, {
57
+ value: 'center_left',
58
+ /* translators: Overlay Position */
59
+ label: __('Center Left', 'newspack')
60
+ }, {
61
+ value: 'center',
62
+ /* translators: Overlay Position */
63
+ label: __('Center', 'newspack')
64
+ }, {
65
+ value: 'center_right',
66
+ /* translators: Overlay Position */
67
+ label: __('Center Right', 'newspack')
68
+ }, {
69
+ value: 'bottom_left',
70
+ /* translators: Overlay Position */
71
+ label: __('Bottom Left', 'newspack')
72
+ }, {
73
+ value: 'bottom',
74
+ /* translators: Overlay Position */
75
+ label: __('Bottom Center', 'newspack')
76
+ }, {
77
+ value: 'bottom_right',
78
+ /* translators: Overlay Position */
79
+ label: __('Bottom Right', 'newspack')
80
+ }];
81
+ return _jsxs("div", {
82
+ className: classnames('newspack-position-placement-control', 'size-' + size),
83
+ children: [_jsx("p", {
84
+ className: "components-base-control__label",
85
+ children: label
86
+ }), _jsx(ButtonGroup, {
87
+ "aria-label": __('Select Position', 'newspack'),
88
+ ...props,
89
+ children: options.map((option, index) => {
90
+ return _jsx("div", {
91
+ className: option.value === value ? 'is-selected' : null,
92
+ children: _jsx(Button, {
93
+ isSmall: true,
94
+ title: option.label,
95
+ "aria-label": option.label,
96
+ isPrimary: option.value === value,
97
+ onClick: () => {
98
+ onChange(option.value);
99
+ },
100
+ disabled: allowedPositions?.length && !allowedPositions.includes(option.value)
101
+ })
102
+ }, `newspack-position-placement-item-${index}`);
103
+ })
104
+ }), _jsx("p", {
105
+ className: "components-base-control__help",
106
+ children: help
107
+ })]
108
+ });
109
+ }
@@ -0,0 +1,66 @@
1
+ @use '~@wordpress/base-styles/colors' as wp-colors;
2
+
3
+ .newspack-position-placement-control {
4
+ margin-bottom: 1em;
5
+
6
+ .components-base-control__label {
7
+ margin-bottom: 8px;
8
+ margin-top: 1em;
9
+ }
10
+
11
+ .components-button-group {
12
+ display: grid;
13
+ grid-template-columns: repeat( 3, 1fr );
14
+ grid-template-rows: repeat( 3, 1fr );
15
+
16
+ div {
17
+ padding: 1px;
18
+ }
19
+
20
+ .components-button {
21
+ border-radius: 0 !important;
22
+ height: 100%;
23
+ padding: 20px;
24
+ width: 100%;
25
+ }
26
+
27
+ div:nth-of-type( 1 ) .components-button {
28
+ border-radius: 4px 0 0 !important;
29
+ }
30
+
31
+ div:nth-of-type( 3 ) .components-button {
32
+ border-radius: 0 4px 0 0 !important;
33
+ }
34
+
35
+ div:nth-last-of-type( 1 ) .components-button {
36
+ border-radius: 0 0 4px !important;
37
+ }
38
+
39
+ div:nth-last-of-type( 3 ) .components-button {
40
+ border-radius: 0 0 0 4px !important;
41
+ }
42
+ }
43
+
44
+ &.size-full-width .components-button-group {
45
+ grid-template-columns: 1fr;
46
+
47
+ div:first-of-type .components-button {
48
+ border-radius: 4px 4px 0 0 !important;
49
+ }
50
+
51
+ div:nth-of-type( 2 ) .components-button {
52
+ border-radius: 0 !important;
53
+ }
54
+
55
+ div:last-of-type .components-button {
56
+ border-radius: 0 0 4px 4px !important;
57
+ }
58
+ }
59
+
60
+ .components-base-control__help {
61
+ color: wp-colors.$gray-700;
62
+ font-size: 12px;
63
+ font-style: normal;
64
+ margin-top: 8px;
65
+ }
66
+ }