newspack-components 2.2.1 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/babel.config.js +25 -0
  2. package/copy-styles.js +2 -10
  3. package/dist/{cjs/accordion → accordion}/index.js +17 -13
  4. package/dist/{cjs/accordion → accordion}/style.scss +7 -3
  5. package/dist/{cjs/action-card → action-card}/index.js +39 -43
  6. package/dist/{esm/action-card → action-card}/style.scss +9 -9
  7. package/dist/{cjs/autocomplete-tokenfield → autocomplete-tokenfield}/index.js +67 -29
  8. package/dist/{esm/autocomplete-tokenfield → autocomplete-tokenfield}/style.scss +14 -8
  9. package/dist/{cjs/autocomplete-with-suggestions → autocomplete-with-suggestions}/index.js +61 -73
  10. package/dist/{esm/autocomplete-with-suggestions → autocomplete-with-suggestions}/style.scss +9 -17
  11. package/dist/button/index.js +51 -0
  12. package/{src/button/index.js → dist/button/index.tsx} +12 -5
  13. package/dist/{cjs/button → button}/style.scss +1 -1
  14. package/dist/{cjs/button-card → button-card}/index.js +9 -10
  15. package/dist/{cjs/button-card → button-card}/style.scss +19 -13
  16. package/dist/{cjs/card → card}/index.js +4 -5
  17. package/dist/{esm/card → card}/style.scss +1 -1
  18. package/dist/{cjs/category-autocomplete → category-autocomplete}/index.js +51 -53
  19. package/dist/{esm/category-autocomplete → category-autocomplete}/style.scss +2 -2
  20. package/dist/{cjs/color-picker → color-picker}/index.js +14 -16
  21. package/dist/{cjs/color-picker → color-picker}/style.scss +3 -3
  22. package/dist/consts.js +7 -0
  23. package/dist/{cjs/custom-select-control → custom-select-control}/index.js +4 -5
  24. package/dist/{cjs/custom-select-control → custom-select-control}/style.scss +11 -10
  25. package/dist/{cjs/date-range-picker → date-range-picker}/index.js +9 -11
  26. package/dist/{cjs/date-range-picker → date-range-picker}/style.scss +6 -6
  27. package/dist/{cjs/footer → footer}/index.js +33 -36
  28. package/dist/{cjs/footer → footer}/style.scss +1 -1
  29. package/dist/{cjs/form-token-field → form-token-field}/index.js +6 -7
  30. package/dist/{esm/form-token-field → form-token-field}/style.scss +1 -1
  31. package/dist/{cjs/global-notices → global-notices}/index.js +4 -5
  32. package/dist/grid/index.js +44 -0
  33. package/dist/grid/index.tsx +34 -0
  34. package/dist/{cjs/grid → grid}/style.scss +9 -9
  35. package/dist/{cjs/handoff → handoff}/index.js +73 -71
  36. package/dist/{cjs/handoff-message → handoff-message}/index.js +5 -3
  37. package/dist/hooks/index.js +29 -0
  38. package/{src/hooks/index.js → dist/hooks/index.ts} +1 -1
  39. package/dist/{cjs/hooks → hooks}/useObjectState.js +2 -3
  40. package/dist/{cjs/hooks → hooks}/useObjectState.test.js +9 -9
  41. package/dist/{cjs/hooks → hooks}/useOnClickOutside.js +1 -2
  42. package/dist/hooks/usePrompt.js +47 -0
  43. package/{src/hooks/usePrompt.js → dist/hooks/usePrompt.ts} +4 -8
  44. package/dist/image-upload/index.js +148 -0
  45. package/dist/{cjs/image-upload → image-upload}/index.test.js +13 -6
  46. package/dist/{esm/image-upload → image-upload}/style.scss +5 -5
  47. package/dist/{cjs/index.js → index.js} +1 -1
  48. package/dist/{cjs/info-button → info-button}/index.js +6 -7
  49. package/dist/{cjs/modal → modal}/index.js +4 -5
  50. package/dist/{esm/modal → modal}/style.scss +5 -5
  51. package/dist/{cjs/newspack-icon → newspack-icon}/index.js +5 -6
  52. package/dist/{cjs/newspack-icon → newspack-icon}/style.scss +1 -1
  53. package/dist/{cjs/newspack-logo → newspack-logo}/index.js +5 -6
  54. package/dist/{cjs/newspack-logo → newspack-logo}/style.scss +1 -1
  55. package/dist/{cjs/notice → notice}/index.js +12 -10
  56. package/dist/{cjs/notice → notice}/style.scss +11 -11
  57. package/dist/patrons-logo/index.js +77 -0
  58. package/dist/plugin-installer/index.js +297 -0
  59. package/dist/{cjs/plugin-installer → plugin-installer}/style.scss +1 -1
  60. package/dist/{cjs/plugin-settings → plugin-settings}/SettingsSection.js +13 -13
  61. package/dist/plugin-settings/index.js +228 -0
  62. package/dist/{cjs/plugin-settings → plugin-settings}/style.scss +1 -1
  63. package/dist/plugin-toggle/README.md +53 -0
  64. package/dist/plugin-toggle/index.js +222 -0
  65. package/dist/{esm/plugin-toggle → plugin-toggle}/style.scss +1 -1
  66. package/dist/{cjs/popover → popover}/index.js +4 -5
  67. package/dist/{cjs/popover → popover}/style.scss +7 -7
  68. package/dist/{cjs/position-control → position-control}/index.js +33 -32
  69. package/dist/{cjs/position-control → position-control}/style.scss +8 -8
  70. package/dist/{cjs/progress-bar → progress-bar}/index.js +9 -10
  71. package/dist/{cjs/progress-bar → progress-bar}/index.test.js +16 -16
  72. package/dist/{cjs/progress-bar → progress-bar}/style.scss +2 -2
  73. package/dist/proxied-imports/router.js +15 -0
  74. package/dist/{cjs/radio-control → radio-control}/index.js +4 -5
  75. package/dist/{cjs/radio-control → radio-control}/style.scss +3 -3
  76. package/dist/{cjs/section-header → section-header}/index.js +20 -21
  77. package/dist/{esm/section-header → section-header}/style.scss +5 -1
  78. package/dist/{cjs/select-control → select-control}/ButtonGroupControl.js +17 -19
  79. package/dist/{cjs/select-control → select-control}/GroupedSelectControl.js +32 -35
  80. package/dist/{cjs/select-control → select-control}/index.js +7 -8
  81. package/dist/{cjs/select-control → select-control}/style.scss +4 -4
  82. package/dist/settings/MinMaxSetting.js +60 -0
  83. package/dist/{cjs/settings → settings}/SettingsCard.js +14 -16
  84. package/dist/settings/SettingsSection.js +33 -0
  85. package/dist/{cjs/settings → settings}/index.js +3 -4
  86. package/dist/{cjs/settings → settings}/style.scss +15 -2
  87. package/dist/sortable-newsletter-list-control/index.js +135 -0
  88. package/dist/sortable-newsletter-list-control/style.scss +45 -0
  89. package/dist/{cjs/steps-list → steps-list}/index.js +5 -6
  90. package/dist/{esm/steps-list → steps-list}/style.scss +2 -2
  91. package/dist/{cjs/steps-list-item → steps-list-item}/index.js +6 -7
  92. package/dist/{cjs/steps-list-item → steps-list-item}/style.scss +5 -5
  93. package/dist/{cjs/style-card → style-card}/index.js +21 -19
  94. package/dist/{esm/style-card → style-card}/style.scss +4 -4
  95. package/dist/{esm/style.scss → style.scss} +14 -2
  96. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/index.js +16 -19
  97. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/style.scss +4 -4
  98. package/dist/text-control/index.js +76 -0
  99. package/dist/text-control/index.tsx +71 -0
  100. package/dist/utils/index.js +36 -0
  101. package/dist/{cjs/waiting → waiting}/index.js +4 -5
  102. package/dist/web-preview/index.js +191 -0
  103. package/dist/{cjs/web-preview → web-preview}/style.scss +5 -5
  104. package/dist/with-wizard/index.js +328 -0
  105. package/dist/{esm/with-wizard → with-wizard}/style.scss +44 -22
  106. package/dist/{cjs/with-wizard-screen → with-wizard-screen}/index.js +40 -43
  107. package/dist/{esm/with-wizard-screen → with-wizard-screen}/style.scss +7 -7
  108. package/dist/{cjs/wizard → wizard}/components/WizardError.js +16 -17
  109. package/dist/{cjs/wizard → wizard}/index.js +44 -46
  110. package/dist/{cjs/wizard → wizard}/store/index.js +37 -38
  111. package/dist/{cjs/wizard → wizard}/store/utils.js +1 -4
  112. package/package.json +16 -14
  113. package/shared/scss/_mixins.scss +2 -2
  114. package/src/accordion/index.js +4 -1
  115. package/src/accordion/style.scss +7 -3
  116. package/src/action-card/style.scss +9 -9
  117. package/src/autocomplete-tokenfield/index.js +48 -15
  118. package/src/autocomplete-tokenfield/style.scss +14 -8
  119. package/src/autocomplete-with-suggestions/index.js +59 -62
  120. package/src/autocomplete-with-suggestions/style.scss +9 -17
  121. package/src/button/index.tsx +48 -0
  122. package/src/button/style.scss +1 -1
  123. package/src/button-card/style.scss +19 -13
  124. package/src/card/style.scss +1 -1
  125. package/src/category-autocomplete/style.scss +2 -2
  126. package/src/color-picker/style.scss +3 -3
  127. package/src/consts.js +0 -2
  128. package/src/custom-select-control/style.scss +11 -10
  129. package/src/date-range-picker/style.scss +6 -6
  130. package/src/footer/index.js +7 -7
  131. package/src/footer/style.scss +1 -1
  132. package/src/form-token-field/style.scss +1 -1
  133. package/src/grid/index.tsx +34 -0
  134. package/src/grid/style.scss +9 -9
  135. package/src/handoff/index.js +7 -6
  136. package/src/handoff-message/index.js +3 -1
  137. package/src/hooks/index.ts +15 -0
  138. package/src/hooks/usePrompt.ts +46 -0
  139. package/src/image-upload/index.js +5 -5
  140. package/src/image-upload/index.test.js +6 -1
  141. package/src/image-upload/style.scss +5 -5
  142. package/src/modal/style.scss +5 -5
  143. package/src/newspack-icon/style.scss +1 -1
  144. package/src/newspack-logo/style.scss +1 -1
  145. package/src/notice/index.js +1 -1
  146. package/src/notice/style.scss +11 -11
  147. package/src/patrons-logo/index.js +4 -1
  148. package/src/plugin-installer/index.js +7 -7
  149. package/src/plugin-installer/style.scss +1 -1
  150. package/src/plugin-settings/index.js +1 -1
  151. package/src/plugin-settings/style.scss +1 -1
  152. package/src/plugin-toggle/index.js +13 -12
  153. package/src/plugin-toggle/style.scss +1 -1
  154. package/src/popover/style.scss +7 -7
  155. package/src/position-control/index.js +63 -64
  156. package/src/position-control/style.scss +8 -8
  157. package/src/progress-bar/style.scss +2 -2
  158. package/src/radio-control/style.scss +3 -3
  159. package/src/section-header/index.js +3 -3
  160. package/src/section-header/style.scss +5 -1
  161. package/src/select-control/GroupedSelectControl.js +1 -1
  162. package/src/select-control/style.scss +4 -4
  163. package/src/settings/MinMaxSetting.js +8 -6
  164. package/src/settings/style.scss +15 -2
  165. package/src/sortable-newsletter-list-control/index.js +137 -0
  166. package/src/sortable-newsletter-list-control/style.scss +45 -0
  167. package/src/steps-list/style.scss +2 -2
  168. package/src/steps-list-item/style.scss +5 -5
  169. package/src/style-card/index.js +11 -5
  170. package/src/style-card/style.scss +4 -4
  171. package/src/style.scss +14 -2
  172. package/src/tabbed-navigation/style.scss +4 -4
  173. package/src/text-control/index.tsx +65 -0
  174. package/src/web-preview/index.js +6 -6
  175. package/src/web-preview/style.scss +5 -5
  176. package/src/with-wizard/index.js +4 -4
  177. package/src/with-wizard/style.scss +44 -22
  178. package/src/with-wizard-screen/index.js +1 -1
  179. package/src/with-wizard-screen/style.scss +7 -7
  180. package/src/wizard/components/WizardError.js +1 -1
  181. package/src/wizard/index.js +3 -3
  182. package/src/wizard/store/index.js +9 -2
  183. package/dist/cjs/action-card/style.scss +0 -483
  184. package/dist/cjs/autocomplete-tokenfield/style.scss +0 -43
  185. package/dist/cjs/autocomplete-with-suggestions/style.scss +0 -171
  186. package/dist/cjs/button/index.js +0 -57
  187. package/dist/cjs/card/style.scss +0 -168
  188. package/dist/cjs/category-autocomplete/style.scss +0 -34
  189. package/dist/cjs/consts.js +0 -12
  190. package/dist/cjs/form-token-field/style.scss +0 -37
  191. package/dist/cjs/grid/index.js +0 -54
  192. package/dist/cjs/hooks/index.js +0 -26
  193. package/dist/cjs/hooks/usePrompt.js +0 -52
  194. package/dist/cjs/image-upload/index.js +0 -144
  195. package/dist/cjs/image-upload/style.scss +0 -103
  196. package/dist/cjs/modal/style.scss +0 -56
  197. package/dist/cjs/patrons-logo/index.js +0 -82
  198. package/dist/cjs/plugin-installer/index.js +0 -299
  199. package/dist/cjs/plugin-settings/index.js +0 -222
  200. package/dist/cjs/plugin-toggle/index.js +0 -222
  201. package/dist/cjs/plugin-toggle/style.scss +0 -20
  202. package/dist/cjs/proxied-imports/router.js +0 -15
  203. package/dist/cjs/section-header/style.scss +0 -41
  204. package/dist/cjs/settings/MinMaxSetting.js +0 -57
  205. package/dist/cjs/settings/SettingsSection.js +0 -37
  206. package/dist/cjs/steps-list/style.scss +0 -11
  207. package/dist/cjs/style-card/style.scss +0 -94
  208. package/dist/cjs/style.scss +0 -43
  209. package/dist/cjs/text-control/index.js +0 -71
  210. package/dist/cjs/utils/index.js +0 -40
  211. package/dist/cjs/web-preview/index.js +0 -189
  212. package/dist/cjs/with-wizard/index.js +0 -318
  213. package/dist/cjs/with-wizard/style.scss +0 -260
  214. package/dist/cjs/with-wizard-screen/style.scss +0 -160
  215. package/dist/esm/accordion/index.js +0 -38
  216. package/dist/esm/accordion/style.scss +0 -27
  217. package/dist/esm/action-card/index.js +0 -222
  218. package/dist/esm/autocomplete-tokenfield/index.js +0 -223
  219. package/dist/esm/autocomplete-with-suggestions/index.js +0 -289
  220. package/dist/esm/button/index.js +0 -48
  221. package/dist/esm/button/style.scss +0 -11
  222. package/dist/esm/button-card/index.js +0 -65
  223. package/dist/esm/button-card/style.scss +0 -174
  224. package/dist/esm/card/index.js +0 -43
  225. package/dist/esm/category-autocomplete/index.js +0 -185
  226. package/dist/esm/color-picker/index.js +0 -61
  227. package/dist/esm/color-picker/style.scss +0 -37
  228. package/dist/esm/consts.js +0 -3
  229. package/dist/esm/custom-select-control/index.js +0 -37
  230. package/dist/esm/custom-select-control/style.scss +0 -92
  231. package/dist/esm/date-range-picker/index.js +0 -32
  232. package/dist/esm/date-range-picker/style.scss +0 -148
  233. package/dist/esm/footer/index.js +0 -105
  234. package/dist/esm/footer/style.scss +0 -82
  235. package/dist/esm/form-token-field/index.js +0 -50
  236. package/dist/esm/global-notices/index.js +0 -30
  237. package/dist/esm/grid/index.js +0 -45
  238. package/dist/esm/grid/style.scss +0 -166
  239. package/dist/esm/handoff/index.js +0 -177
  240. package/dist/esm/handoff-message/index.js +0 -45
  241. package/dist/esm/hooks/index.js +0 -17
  242. package/dist/esm/hooks/useObjectState.js +0 -31
  243. package/dist/esm/hooks/useObjectState.test.js +0 -83
  244. package/dist/esm/hooks/useOnClickOutside.js +0 -31
  245. package/dist/esm/hooks/usePrompt.js +0 -43
  246. package/dist/esm/image-upload/index.js +0 -141
  247. package/dist/esm/image-upload/index.test.js +0 -28
  248. package/dist/esm/index.js +0 -47
  249. package/dist/esm/info-button/index.js +0 -42
  250. package/dist/esm/info-button/style.scss +0 -18
  251. package/dist/esm/modal/index.js +0 -39
  252. package/dist/esm/newspack-icon/index.js +0 -50
  253. package/dist/esm/newspack-icon/style.scss +0 -26
  254. package/dist/esm/newspack-logo/index.js +0 -46
  255. package/dist/esm/newspack-logo/style.scss +0 -30
  256. package/dist/esm/notice/index.js +0 -67
  257. package/dist/esm/notice/style.scss +0 -111
  258. package/dist/esm/patrons-logo/index.js +0 -76
  259. package/dist/esm/plugin-installer/index.js +0 -295
  260. package/dist/esm/plugin-installer/style.scss +0 -72
  261. package/dist/esm/plugin-settings/SettingsSection.js +0 -136
  262. package/dist/esm/plugin-settings/index.js +0 -217
  263. package/dist/esm/plugin-settings/style.scss +0 -7
  264. package/dist/esm/plugin-toggle/index.js +0 -217
  265. package/dist/esm/popover/index.js +0 -41
  266. package/dist/esm/popover/style.scss +0 -161
  267. package/dist/esm/position-control/index.js +0 -109
  268. package/dist/esm/position-control/style.scss +0 -66
  269. package/dist/esm/progress-bar/index.js +0 -69
  270. package/dist/esm/progress-bar/index.test.js +0 -110
  271. package/dist/esm/progress-bar/style.scss +0 -42
  272. package/dist/esm/proxied-imports/router.js +0 -8
  273. package/dist/esm/radio-control/index.js +0 -37
  274. package/dist/esm/radio-control/style.scss +0 -92
  275. package/dist/esm/section-header/index.js +0 -68
  276. package/dist/esm/select-control/ButtonGroupControl.js +0 -54
  277. package/dist/esm/select-control/GroupedSelectControl.js +0 -84
  278. package/dist/esm/select-control/index.js +0 -51
  279. package/dist/esm/select-control/style.scss +0 -108
  280. package/dist/esm/settings/MinMaxSetting.js +0 -53
  281. package/dist/esm/settings/SettingsCard.js +0 -39
  282. package/dist/esm/settings/SettingsSection.js +0 -30
  283. package/dist/esm/settings/index.js +0 -9
  284. package/dist/esm/settings/style.scss +0 -106
  285. package/dist/esm/steps-list/index.js +0 -43
  286. package/dist/esm/steps-list-item/index.js +0 -48
  287. package/dist/esm/steps-list-item/style.scss +0 -47
  288. package/dist/esm/style-card/index.js +0 -76
  289. package/dist/esm/tabbed-navigation/index.js +0 -56
  290. package/dist/esm/tabbed-navigation/style.scss +0 -86
  291. package/dist/esm/text-control/index.js +0 -66
  292. package/dist/esm/text-control/style.scss +0 -32
  293. package/dist/esm/utils/index.js +0 -32
  294. package/dist/esm/waiting/index.js +0 -44
  295. package/dist/esm/waiting/style.scss +0 -27
  296. package/dist/esm/web-preview/index.js +0 -184
  297. package/dist/esm/web-preview/style.scss +0 -155
  298. package/dist/esm/with-wizard/index.js +0 -313
  299. package/dist/esm/with-wizard-screen/index.js +0 -116
  300. package/dist/esm/wizard/components/WizardError.js +0 -69
  301. package/dist/esm/wizard/index.js +0 -126
  302. package/dist/esm/wizard/store/index.js +0 -155
  303. package/dist/esm/wizard/store/utils.js +0 -17
  304. package/src/grid/index.js +0 -44
  305. package/src/text-control/index.js +0 -56
  306. /package/dist/{cjs/info-button → info-button}/style.scss +0 -0
  307. /package/dist/{cjs/text-control → text-control}/style.scss +0 -0
  308. /package/dist/{cjs/waiting → waiting}/style.scss +0 -0
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
9
+ var _element = require("@wordpress/element");
10
+ var _i18n = require("@wordpress/i18n");
11
+ var _icons = require("@wordpress/icons");
12
+ var _ = require("../");
13
+ require("./style.scss");
14
+ var _classnames = _interopRequireDefault(require("classnames"));
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ /**
17
+ * Plugin Installer
18
+ */
19
+
20
+ /**
21
+ * WordPress dependencies.
22
+ */
23
+
24
+ /**
25
+ * Internal dependencies.
26
+ */
27
+
28
+ const PLUGIN_STATE_NONE = 0;
29
+ const PLUGIN_STATE_ACTIVE = 1;
30
+ const PLUGIN_STATE_INSTALLING = 2;
31
+ const PLUGIN_STATE_ERROR = 3;
32
+
33
+ /**
34
+ * External dependencies.
35
+ */
36
+
37
+ /**
38
+ * Plugin installer.
39
+ */
40
+ class PluginInstaller extends _element.Component {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.state = {
44
+ pluginInfo: {},
45
+ installationInitialized: false
46
+ };
47
+ }
48
+ componentDidMount = () => {
49
+ const {
50
+ plugins
51
+ } = this.props;
52
+ this.retrievePluginInfo(plugins).then(() => {
53
+ if (this.props.autoInstall) {
54
+ this.installAllPlugins();
55
+ }
56
+ });
57
+ };
58
+ componentDidUpdate = prevProps => {
59
+ const {
60
+ autoInstall,
61
+ plugins
62
+ } = this.props;
63
+ const {
64
+ installationInitialized
65
+ } = this.state;
66
+ if (plugins !== prevProps.plugins) {
67
+ this.retrievePluginInfo(plugins);
68
+ }
69
+ if (autoInstall && !installationInitialized) {
70
+ this.installAllPlugins();
71
+ }
72
+ };
73
+ retrievePluginInfo = plugins => {
74
+ return new Promise(resolve => {
75
+ (0, _apiFetch.default)({
76
+ path: '/newspack/v1/plugins/'
77
+ }).then(response => {
78
+ const pluginInfo = Object.keys(response).reduce((result, slug) => {
79
+ if (plugins.indexOf(slug) === -1) {
80
+ return result;
81
+ }
82
+ result[slug] = {
83
+ ...response[slug],
84
+ installationStatus: response[slug].Status === 'active' ? PLUGIN_STATE_ACTIVE : PLUGIN_STATE_NONE
85
+ };
86
+ return result;
87
+ }, {});
88
+ this.updatePluginInfo(pluginInfo).then(() => resolve());
89
+ });
90
+ });
91
+ };
92
+ installAllPlugins = () => {
93
+ const {
94
+ pluginInfo
95
+ } = this.state;
96
+ this.setState({
97
+ installationInitialized: true
98
+ });
99
+ const promises = Object.keys(pluginInfo).filter(slug => 'active' !== pluginInfo[slug].Status).map(slug => () => this.installPlugin(slug));
100
+ promises.reduce((promise, action) => promise.then(result => action().then(Array.prototype.concat.bind(result))), Promise.resolve([]));
101
+ };
102
+ installPlugin = slug => {
103
+ this.setInstallationStatus(slug, PLUGIN_STATE_INSTALLING);
104
+ const params = {
105
+ path: `/newspack/v1/plugins/${slug}/configure/`,
106
+ method: 'post'
107
+ };
108
+ return (0, _apiFetch.default)(params).then(response => {
109
+ const {
110
+ pluginInfo
111
+ } = this.state;
112
+ this.props.onInstalled(slug);
113
+ this.updatePluginInfo({
114
+ ...pluginInfo,
115
+ [slug]: {
116
+ ...response,
117
+ installationStatus: PLUGIN_STATE_ACTIVE
118
+ }
119
+ });
120
+ }).catch(error => {
121
+ this.setInstallationStatus(slug, PLUGIN_STATE_ERROR, error.message);
122
+ });
123
+ };
124
+ setChecked = (slug, checked) => {
125
+ const {
126
+ pluginInfo
127
+ } = this.state;
128
+ this.updatePluginInfo({
129
+ ...pluginInfo,
130
+ [slug]: {
131
+ ...pluginInfo[slug],
132
+ checked
133
+ }
134
+ });
135
+ };
136
+ setInstallationStatus = (slug, installationStatus, notification = null) => {
137
+ const {
138
+ pluginInfo
139
+ } = this.state;
140
+ this.updatePluginInfo({
141
+ ...pluginInfo,
142
+ [slug]: {
143
+ ...pluginInfo[slug],
144
+ installationStatus,
145
+ notification
146
+ }
147
+ });
148
+ };
149
+ updatePluginInfo = pluginInfo => {
150
+ return new Promise(resolve => {
151
+ const {
152
+ onStatus
153
+ } = this.props;
154
+ this.setState({
155
+ pluginInfo
156
+ }, () => {
157
+ const complete = Object.values(pluginInfo).every(plugin => {
158
+ return 'active' === plugin.Status;
159
+ });
160
+ onStatus({
161
+ complete,
162
+ pluginInfo
163
+ });
164
+ resolve();
165
+ });
166
+ });
167
+ };
168
+ classForInstallationStatus = status => {
169
+ switch (status) {
170
+ case PLUGIN_STATE_ACTIVE:
171
+ return 'newspack-plugin-installer__status-active';
172
+ case PLUGIN_STATE_INSTALLING:
173
+ return 'newspack-plugin-installer__status-installing';
174
+ case PLUGIN_STATE_ERROR:
175
+ return 'newspack-plugin-installer__status-error';
176
+ default:
177
+ return 'newspack-plugin-installer__status-none';
178
+ }
179
+ };
180
+
181
+ /**
182
+ * Render.
183
+ */
184
+ render() {
185
+ const {
186
+ autoInstall,
187
+ isSmall,
188
+ withoutFooterButton
189
+ } = this.props;
190
+ const {
191
+ pluginInfo
192
+ } = this.state;
193
+ const {
194
+ is_atomic: isAtomic
195
+ } = window;
196
+ const slugs = Object.keys(pluginInfo);
197
+
198
+ // Store all plugin status info for installer button text value based on current status.
199
+ const currentPluginStatuses = [];
200
+ slugs.forEach(slug => {
201
+ const plugin = pluginInfo[slug];
202
+ currentPluginStatuses.push(plugin.Status);
203
+ });
204
+
205
+ // Make sure plugin status falls in either one of these, to handle button text.
206
+ const pluginInstalled = currentStatus => currentStatus === 'active' || currentStatus === 'inactive';
207
+ const buttonText = currentPluginStatuses.every(pluginInstalled) ? (0, _i18n.__)('Activate', 'newspack-plugin') : (0, _i18n.__)('Install', 'newspack-plugin');
208
+ const needsInstall = slugs.some(slug => {
209
+ const plugin = pluginInfo[slug];
210
+ return plugin.Status !== 'active' && plugin.installationStatus === PLUGIN_STATE_NONE;
211
+ });
212
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
213
+ children: [(!pluginInfo || !Object.keys(pluginInfo).length) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
214
+ className: "newspack-plugin-installer_is-waiting",
215
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Waiting, {
216
+ isLeft: true
217
+ }), (0, _i18n.__)('Retrieving plugin information…', 'newspack-plugin')]
218
+ }), pluginInfo && slugs.length > 0 && slugs.map(slug => {
219
+ const plugin = pluginInfo[slug];
220
+ const {
221
+ Name,
222
+ Description,
223
+ Download,
224
+ Status,
225
+ installationStatus,
226
+ notification
227
+ } = plugin;
228
+ const isWaiting = installationStatus === PLUGIN_STATE_INSTALLING;
229
+ const isButton = !isWaiting && Status !== 'active';
230
+ const installable = Download || pluginInstalled(Status);
231
+ let actionText;
232
+ if (installationStatus === PLUGIN_STATE_INSTALLING) {
233
+ actionText = 'inactive' === Status ? (0, _i18n.__)('Activating…') : (0, _i18n.__)('Installing…');
234
+ } else if (!installable) {
235
+ actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
236
+ className: "newspack-plugin-installer__status",
237
+ children: [isAtomic ? (0, _i18n.__)('Contact Newspack support to install', 'newspack-plugin') : (0, _i18n.__)('Plugin must be installed manually', 'newspack-plugin'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
238
+ className: "newspack-checkbox-icon"
239
+ })]
240
+ });
241
+ } else if (Status === 'uninstalled') {
242
+ actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
243
+ className: "newspack-plugin-installer__status",
244
+ children: [(0, _i18n.__)('Install', 'newspack'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
245
+ className: "newspack-checkbox-icon"
246
+ })]
247
+ });
248
+ } else if (Status === 'inactive') {
249
+ actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
250
+ className: "newspack-plugin-installer__status",
251
+ children: [(0, _i18n.__)('Activate', 'newspack-plugin'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
252
+ className: "newspack-checkbox-icon"
253
+ })]
254
+ });
255
+ } else if (Status === 'active') {
256
+ actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
257
+ className: "newspack-plugin-installer__status",
258
+ children: [(0, _i18n.__)('Installed', 'newspack-plugin'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
259
+ className: "newspack-checkbox-icon newspack-checkbox-icon--checked",
260
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
261
+ icon: _icons.check
262
+ })
263
+ })]
264
+ });
265
+ }
266
+ const classes = (0, _classnames.default)('newspack-action-card__plugin-installer', this.classForInstallationStatus(installationStatus));
267
+ const onClick = isButton ? () => this.installPlugin(slug) : null;
268
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.ActionCard, {
269
+ title: Name,
270
+ description: Description,
271
+ disabled: !installable,
272
+ actionText: actionText,
273
+ isSmall: isSmall,
274
+ isWaiting: isWaiting,
275
+ onClick: onClick,
276
+ notification: notification,
277
+ notificationLevel: "error",
278
+ notificationHTML: true,
279
+ className: classes
280
+ }, slug);
281
+ }), !withoutFooterButton && !autoInstall && pluginInfo && slugs.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
282
+ className: "newspack-buttons-card",
283
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
284
+ disabled: !needsInstall,
285
+ isPrimary: true,
286
+ onClick: this.installAllPlugins,
287
+ children: buttonText
288
+ })
289
+ })]
290
+ });
291
+ }
292
+ }
293
+ PluginInstaller.defaultProps = {
294
+ onStatus: () => {},
295
+ onInstalled: () => {}
296
+ };
297
+ var _default = exports.default = PluginInstaller;
@@ -2,7 +2,7 @@
2
2
  * Plugin Installer
3
3
  */
4
4
 
5
- @use '~@wordpress/base-styles/colors' as wp-colors;
5
+ @use "~@wordpress/base-styles/colors" as wp-colors;
6
6
 
7
7
  .newspack-card {
8
8
  .newspack-plugin-installer__status {
@@ -10,17 +10,19 @@ var _i18n = require("@wordpress/i18n");
10
10
  var _components = require("@wordpress/components");
11
11
  var _ = require("../");
12
12
  require("./style.scss");
13
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
14
  /**
15
15
  * Ads Settings Section.
16
16
  */
17
+
17
18
  /**
18
19
  * WordPress dependencies
19
20
  */
20
- const __ = _i18n.__;
21
+
21
22
  /**
22
23
  * Internal dependencies
23
24
  */
25
+
24
26
  const isSelectControl = setting => {
25
27
  return Array.isArray(setting.options) && setting.options.length;
26
28
  };
@@ -86,8 +88,7 @@ const SettingsSection = props => {
86
88
  setSaveDisabled(false);
87
89
  }
88
90
  });
89
- const createFilter = function (name) {
90
- let defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
91
+ const createFilter = (name, defaultComponent = null) => {
91
92
  return (0, _hooks.applyFilters)(`newspack.settingSection.${sectionKey}.${name}`, defaultComponent, props);
92
93
  };
93
94
  let columns = 2;
@@ -96,7 +97,7 @@ const SettingsSection = props => {
96
97
  } else if (fields.length === 1) {
97
98
  columns = 1;
98
99
  }
99
- return (0, _jsxRuntime.jsx)(_.ActionCard, {
100
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.ActionCard, {
100
101
  isMedium: true,
101
102
  disabled: disabled,
102
103
  title: title,
@@ -106,25 +107,25 @@ const SettingsSection = props => {
106
107
  toggleOnChange: active !== null ? value => onUpdate({
107
108
  active: value
108
109
  }) : null,
109
- actionContent: (active || null === active) && createFilter('buttons', (0, _jsxRuntime.jsx)(_.Button, {
110
+ actionContent: (active || null === active) && createFilter('buttons', /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
110
111
  variant: "primary",
111
112
  disabled: disabled || saveDisabled,
112
113
  onClick: () => {
113
114
  onUpdate();
114
115
  setSaveDisabled(true);
115
116
  },
116
- children: __('Save Settings', 'newspack')
117
+ children: (0, _i18n.__)('Save Settings', 'newspack')
117
118
  })),
118
- children: (active || active === null) && (0, _jsxRuntime.jsxs)(_element.Fragment, {
119
- children: [error?.message && (0, _jsxRuntime.jsx)(_.Notice, {
119
+ children: (active || active === null) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
120
+ children: [error?.message && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
120
121
  noticeText: error.message,
121
122
  isError: true
122
- }), createFilter('beforeControls'), (0, _jsxRuntime.jsx)(_.Grid, {
123
+ }), createFilter('beforeControls'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Grid, {
123
124
  columns: columns,
124
125
  gutter: 32,
125
126
  children: fields.map(setting => {
126
127
  const Control = getControlComponent(setting); // eslint-disable-line @wordpress/no-unused-vars-before-return, no-unused-vars
127
- return (0, _hooks.applyFilters)(`newspack.settingsSection.${sectionKey}.control`, (0, _jsxRuntime.jsx)(Control, {
128
+ return (0, _hooks.applyFilters)(`newspack.settingsSection.${sectionKey}.control`, /*#__PURE__*/(0, _jsxRuntime.jsx)(Control, {
128
129
  ...getControlProps(setting)
129
130
  }, setting.key), {
130
131
  sectionKey,
@@ -136,5 +137,4 @@ const SettingsSection = props => {
136
137
  })
137
138
  });
138
139
  };
139
- var _default = SettingsSection;
140
- exports.default = _default;
140
+ var _default = exports.default = SettingsSection;
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
10
+ var _element = require("@wordpress/element");
11
+ var _i18n = require("@wordpress/i18n");
12
+ var _ = require("../");
13
+ var _SettingsSection = _interopRequireDefault(require("./SettingsSection"));
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ /**
16
+ * External dependencies
17
+ */
18
+
19
+ /**
20
+ * WordPress dependencies.
21
+ */
22
+
23
+ /**
24
+ * Internal dependencies.
25
+ */
26
+
27
+ class PluginSettings extends _element.Component {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.state = {
31
+ inFlight: false,
32
+ settings: {},
33
+ error: null
34
+ };
35
+ }
36
+ fetchSettings = () => {
37
+ const {
38
+ afterFetch,
39
+ pluginSlug,
40
+ isWizard
41
+ } = this.props;
42
+ this.setState({
43
+ inFlight: true
44
+ });
45
+ (0, _apiFetch.default)({
46
+ path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`
47
+ }).then(settings => {
48
+ this.setState({
49
+ settings,
50
+ error: null
51
+ });
52
+ if ('function' === typeof afterFetch) {
53
+ afterFetch(settings);
54
+ }
55
+ }).catch(error => {
56
+ this.setState({
57
+ error
58
+ });
59
+ }).finally(() => {
60
+ this.setState({
61
+ inFlight: false
62
+ });
63
+ });
64
+ };
65
+ componentDidMount() {
66
+ this.fetchSettings();
67
+ }
68
+ getSettingsValues = sectionKey => {
69
+ return this.state.settings[sectionKey]?.reduce((map, setting) => {
70
+ map[setting.key] = setting.value;
71
+ return map;
72
+ }, {}) || {};
73
+ };
74
+ handleSettingChange = sectionKey => (key, value) => {
75
+ const sectionSettings = [...this.state.settings[sectionKey]];
76
+ sectionSettings.forEach(setting => {
77
+ if (setting.key === key) {
78
+ setting.value = value;
79
+ }
80
+ });
81
+ this.setState({
82
+ settings: {
83
+ ...this.state.settings,
84
+ [sectionKey]: sectionSettings
85
+ }
86
+ });
87
+ };
88
+ handleSectionUpdate = sectionKey => data => {
89
+ const {
90
+ afterUpdate,
91
+ pluginSlug,
92
+ isWizard
93
+ } = this.props;
94
+ this.setState({
95
+ inFlight: true
96
+ });
97
+ (0, _apiFetch.default)({
98
+ path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`,
99
+ method: 'POST',
100
+ data: {
101
+ section: sectionKey,
102
+ settings: data ? data : this.getSettingsValues(sectionKey)
103
+ }
104
+ }).then(settings => {
105
+ this.setState({
106
+ settings: {
107
+ ...this.state.settings,
108
+ [sectionKey]: settings[sectionKey]
109
+ },
110
+ error: null
111
+ });
112
+ if ('function' === typeof afterUpdate) {
113
+ afterUpdate(settings);
114
+ }
115
+ }).catch(error => {
116
+ this.setState({
117
+ error
118
+ });
119
+ }).finally(() => {
120
+ this.setState({
121
+ inFlight: false
122
+ });
123
+ });
124
+ };
125
+
126
+ /**
127
+ * Get the section setting containing section information.
128
+ *
129
+ * @param {string} sectionKey The section name.
130
+ * @return {Object} The section setting.
131
+ */
132
+ getSectionInfo = sectionKey => {
133
+ return this.state.settings[sectionKey]?.find(setting => !setting.key || setting.key === 'active');
134
+ };
135
+
136
+ /**
137
+ * Get the section title.
138
+ *
139
+ * @param {string} sectionKey The section name.
140
+ * @return {string} The section title.
141
+ */
142
+ getSectionTitle = sectionKey => {
143
+ return this.getSectionInfo(sectionKey)?.description;
144
+ };
145
+
146
+ /**
147
+ * Get the section description.
148
+ *
149
+ * @param {string} sectionKey The section name.
150
+ * @return {string} The section description.
151
+ */
152
+ getSectionDescription = sectionKey => {
153
+ return this.getSectionInfo(sectionKey)?.help;
154
+ };
155
+
156
+ /**
157
+ * Get whether a section is active.
158
+ *
159
+ * @param {string} sectionKey The section name.
160
+ * @return {?boolean} Whether the section is active or not. Null if the section is not found or does not support activation.
161
+ */
162
+ isSectionActive = sectionKey => {
163
+ const {
164
+ settings
165
+ } = this.state;
166
+ const activation = settings[sectionKey]?.find(setting => setting.key === 'active');
167
+ if (!activation) {
168
+ return null;
169
+ }
170
+ return activation.value;
171
+ };
172
+
173
+ /**
174
+ * Get list of section field settings.
175
+ *
176
+ * @param {string} sectionKey The section name.
177
+ * @return {?Array} List of section fields.
178
+ */
179
+ getSectionFields = sectionKey => {
180
+ return this.state.settings[sectionKey]?.filter(setting => setting.key && setting.key !== 'active');
181
+ };
182
+
183
+ /**
184
+ * Render.
185
+ */
186
+ render() {
187
+ const {
188
+ title,
189
+ description,
190
+ hasGreyHeader,
191
+ children
192
+ } = this.props;
193
+ const {
194
+ settings,
195
+ inFlight,
196
+ error
197
+ } = this.state;
198
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
199
+ children: [title && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.SectionHeader, {
200
+ title: title,
201
+ description: description
202
+ }), error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
203
+ isError: true,
204
+ noticeText: error.message
205
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
206
+ className: (0, _classnames.default)('newspack-plugin-settings', {
207
+ 'newspack-wizard-section__is-loading': inFlight && !Object.keys(settings).length
208
+ }),
209
+ children: [Object.keys(settings).map(sectionKey => /*#__PURE__*/(0, _jsxRuntime.jsx)(_SettingsSection.default, {
210
+ disabled: inFlight,
211
+ sectionKey: sectionKey,
212
+ title: this.getSectionTitle(sectionKey),
213
+ description: this.getSectionDescription(sectionKey),
214
+ active: this.isSectionActive(sectionKey),
215
+ fields: this.getSectionFields(sectionKey),
216
+ onChange: this.handleSettingChange(sectionKey),
217
+ onUpdate: this.handleSectionUpdate(sectionKey),
218
+ hasGreyHeader: hasGreyHeader
219
+ }, sectionKey)), children]
220
+ })]
221
+ });
222
+ }
223
+ }
224
+ PluginSettings.defaultProps = {
225
+ title: (0, _i18n.__)('General Settings', 'newspack-plugin')
226
+ };
227
+ PluginSettings.Section = _SettingsSection.default;
228
+ var _default = exports.default = PluginSettings;
@@ -1,4 +1,4 @@
1
- .newspack-card:not( .newspack-settings__no-border ) {
1
+ .newspack-card:not(.newspack-settings__no-border) {
2
2
  .newspack-action-card__region-children {
3
3
  > .newspack-grid {
4
4
  margin: 32px 0 0 !important;
@@ -0,0 +1,53 @@
1
+ # PluginToggle
2
+
3
+ PluginToggle presents ActionCards for one or more plugins.
4
+
5
+ Each ActionCard displays the name and description of the plugin. Clicking the ToggleControl installs/activates or uninstalls the plugin. If a plugin is installed, there will be a Handoff link on the right. Optionally the href and label of this link can be overridden.
6
+
7
+ Each plugin accepts a shouldRefreshAfterUpdate param. If true, the page will be reloaded after the plugin is installed or uninstalled. Updating ensures that the WordPress dashboard accurately represents current state, e.g. that newly installed plugins appear in menus.
8
+
9
+ ### Usage
10
+
11
+ ActionCards for WooCommerce and Instant Articles for WP. Both will have Handoff links.
12
+
13
+ ```
14
+ <PluginToggle
15
+ plugins={ {
16
+ woocommerce: true,
17
+ 'fb-instant-articles': true,
18
+ } }
19
+ />
20
+ ```
21
+
22
+ ActionCards for WooCommerce and Instant Articles for WP with custom text and URL for links.
23
+
24
+ ```
25
+ <PluginToggle
26
+ plugins={ {
27
+ woocommerce: {
28
+ actionText: __( 'Use WooCommerce' ),
29
+ href: '/wp-admin/admin.php?page=newspack',
30
+ },
31
+ 'fb-instant-articles': {
32
+ actionText: __( 'Configure Instant Articles' ),
33
+ href: '/wp-admin/admin.php?page=newspack',
34
+ },
35
+ } }
36
+ />
37
+ ```
38
+
39
+ ActionCards for WooCommerce and Instant Articles for WP. Page will refresh after WooCommerce installation or deinstallation.
40
+
41
+ ```
42
+ <PluginToggle
43
+ plugins={ {
44
+ woocommerce: {
45
+ shouldRefreshAfterUpdate: true,
46
+ },
47
+ 'fb-instant-articles': {
48
+ actionText: __( 'Configure Instant Articles' ),
49
+ href: '/wp-admin/admin.php?page=newspack',
50
+ },
51
+ } }
52
+ />
53
+ ```