newspack-components 3.0.0-alpha.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 (278) hide show
  1. package/babel.config.js +25 -0
  2. package/copy-styles.js +2 -10
  3. package/dist/accordion/index.js +50 -0
  4. package/dist/accordion/style.scss +31 -0
  5. package/dist/{cjs/action-card → action-card}/index.js +38 -41
  6. package/dist/{cjs/action-card → action-card}/style.scss +9 -9
  7. package/dist/{cjs/autocomplete-tokenfield → autocomplete-tokenfield}/index.js +19 -18
  8. package/dist/{esm/autocomplete-tokenfield → autocomplete-tokenfield}/style.scss +3 -3
  9. package/dist/{cjs/autocomplete-with-suggestions → autocomplete-with-suggestions}/index.js +29 -29
  10. package/dist/{cjs/autocomplete-with-suggestions → autocomplete-with-suggestions}/style.scss +8 -8
  11. package/dist/button/index.js +51 -0
  12. package/dist/button/index.tsx +48 -0
  13. package/dist/{cjs/button → button}/style.scss +1 -1
  14. package/dist/{cjs/button-card → button-card}/index.js +8 -8
  15. package/dist/{cjs/button-card → button-card}/style.scss +19 -13
  16. package/dist/{cjs/card → card}/index.js +3 -3
  17. package/dist/{esm/card → card}/style.scss +1 -1
  18. package/dist/{cjs/category-autocomplete → category-autocomplete}/index.js +50 -48
  19. package/dist/{cjs/category-autocomplete → category-autocomplete}/style.scss +2 -2
  20. package/dist/{cjs/color-picker → color-picker}/index.js +7 -7
  21. package/dist/{cjs/color-picker → color-picker}/style.scss +3 -3
  22. package/dist/{cjs/custom-select-control → custom-select-control}/index.js +3 -3
  23. package/dist/{esm/custom-select-control → custom-select-control}/style.scss +11 -10
  24. package/dist/date-range-picker/index.js +39 -0
  25. package/dist/date-range-picker/style.scss +148 -0
  26. package/dist/{cjs/footer → footer}/index.js +19 -17
  27. package/dist/{cjs/footer → footer}/style.scss +1 -1
  28. package/dist/{cjs/form-token-field → form-token-field}/index.js +5 -5
  29. package/dist/{esm/form-token-field → form-token-field}/style.scss +1 -1
  30. package/dist/{cjs/global-notices → global-notices}/index.js +3 -3
  31. package/dist/grid/index.js +44 -0
  32. package/dist/grid/index.tsx +34 -0
  33. package/dist/{esm/grid → grid}/style.scss +9 -9
  34. package/dist/{cjs/handoff → handoff}/index.js +72 -69
  35. package/dist/{cjs/handoff-message → handoff-message}/index.js +5 -3
  36. package/dist/hooks/index.js +29 -0
  37. package/dist/hooks/index.ts +15 -0
  38. package/dist/{cjs/hooks → hooks}/useObjectState.js +1 -1
  39. package/dist/{cjs/hooks → hooks}/useObjectState.test.js +9 -9
  40. package/dist/hooks/usePrompt.js +47 -0
  41. package/dist/hooks/usePrompt.ts +46 -0
  42. package/dist/image-upload/index.js +148 -0
  43. package/dist/{cjs/image-upload → image-upload}/index.test.js +13 -6
  44. package/dist/{cjs/image-upload → image-upload}/style.scss +5 -5
  45. package/dist/{cjs/index.js → index.js} +15 -1
  46. package/dist/{cjs/info-button → info-button}/index.js +5 -5
  47. package/dist/{cjs/modal → modal}/index.js +3 -3
  48. package/dist/{cjs/modal → modal}/style.scss +5 -5
  49. package/dist/{cjs/newspack-icon → newspack-icon}/index.js +4 -4
  50. package/dist/{cjs/newspack-icon → newspack-icon}/style.scss +1 -1
  51. package/dist/{cjs/newspack-logo → newspack-logo}/index.js +4 -4
  52. package/dist/{cjs/newspack-logo → newspack-logo}/style.scss +1 -1
  53. package/dist/{cjs/notice → notice}/index.js +11 -8
  54. package/dist/{cjs/notice → notice}/style.scss +11 -11
  55. package/dist/patrons-logo/index.js +77 -0
  56. package/dist/plugin-installer/index.js +297 -0
  57. package/dist/{esm/plugin-installer → plugin-installer}/style.scss +1 -1
  58. package/dist/{cjs/plugin-settings → plugin-settings}/SettingsSection.js +11 -9
  59. package/dist/plugin-settings/index.js +228 -0
  60. package/dist/{cjs/plugin-settings → plugin-settings}/style.scss +1 -1
  61. package/dist/plugin-toggle/README.md +53 -0
  62. package/dist/plugin-toggle/index.js +222 -0
  63. package/dist/{esm/plugin-toggle → plugin-toggle}/style.scss +1 -1
  64. package/dist/{cjs/popover → popover}/index.js +3 -3
  65. package/dist/{esm/popover → popover}/style.scss +7 -7
  66. package/dist/{cjs/position-control → position-control}/index.js +24 -22
  67. package/dist/{cjs/position-control → position-control}/style.scss +8 -8
  68. package/dist/{cjs/progress-bar → progress-bar}/index.js +8 -8
  69. package/dist/{cjs/progress-bar → progress-bar}/index.test.js +12 -11
  70. package/dist/{esm/progress-bar → progress-bar}/style.scss +2 -2
  71. package/dist/proxied-imports/router.js +15 -0
  72. package/dist/{cjs/radio-control → radio-control}/index.js +3 -3
  73. package/dist/{esm/radio-control → radio-control}/style.scss +3 -3
  74. package/dist/{cjs/section-header → section-header}/index.js +8 -8
  75. package/dist/{cjs/section-header → section-header}/style.scss +1 -1
  76. package/dist/{cjs/select-control → select-control}/ButtonGroupControl.js +7 -7
  77. package/dist/{cjs/select-control → select-control}/GroupedSelectControl.js +15 -14
  78. package/dist/{cjs/select-control → select-control}/index.js +6 -6
  79. package/dist/{esm/select-control → select-control}/style.scss +4 -4
  80. package/dist/{cjs/settings → settings}/MinMaxSetting.js +12 -11
  81. package/dist/{cjs/settings → settings}/SettingsCard.js +4 -4
  82. package/dist/{cjs/settings → settings}/SettingsSection.js +6 -6
  83. package/dist/{cjs/settings → settings}/index.js +1 -1
  84. package/dist/{cjs/settings → settings}/style.scss +1 -1
  85. package/dist/{cjs/sortable-newsletter-list-control → sortable-newsletter-list-control}/index.js +25 -24
  86. package/dist/{cjs/steps-list → steps-list}/index.js +4 -4
  87. package/dist/{esm/steps-list → steps-list}/style.scss +2 -2
  88. package/dist/{cjs/steps-list-item → steps-list-item}/index.js +5 -5
  89. package/dist/{cjs/steps-list-item → steps-list-item}/style.scss +5 -5
  90. package/dist/{cjs/style-card → style-card}/index.js +20 -17
  91. package/dist/{cjs/style-card → style-card}/style.scss +4 -4
  92. package/dist/{esm/style.scss → style.scss} +1 -1
  93. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/index.js +7 -7
  94. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/style.scss +4 -4
  95. package/dist/text-control/index.js +76 -0
  96. package/dist/text-control/index.tsx +71 -0
  97. package/dist/{cjs/utils → utils}/index.js +2 -2
  98. package/dist/{cjs/waiting → waiting}/index.js +3 -3
  99. package/dist/web-preview/index.js +191 -0
  100. package/dist/{esm/web-preview → web-preview}/style.scss +5 -5
  101. package/dist/with-wizard/index.js +328 -0
  102. package/dist/{cjs/with-wizard → with-wizard}/style.scss +44 -22
  103. package/dist/{cjs/with-wizard-screen → with-wizard-screen}/index.js +24 -23
  104. package/dist/{esm/with-wizard-screen → with-wizard-screen}/style.scss +7 -7
  105. package/dist/{cjs/wizard → wizard}/components/WizardError.js +10 -9
  106. package/dist/{cjs/wizard → wizard}/index.js +30 -27
  107. package/dist/{cjs/wizard → wizard}/store/index.js +1 -1
  108. package/package.json +18 -15
  109. package/shared/scss/_mixins.scss +2 -2
  110. package/src/accordion/index.js +35 -0
  111. package/src/accordion/style.scss +31 -0
  112. package/src/action-card/style.scss +9 -9
  113. package/src/autocomplete-tokenfield/style.scss +3 -3
  114. package/src/autocomplete-with-suggestions/index.js +46 -44
  115. package/src/autocomplete-with-suggestions/style.scss +8 -8
  116. package/src/button/style.scss +1 -1
  117. package/src/button-card/style.scss +19 -13
  118. package/src/card/style.scss +1 -1
  119. package/src/category-autocomplete/style.scss +2 -2
  120. package/src/color-picker/style.scss +3 -3
  121. package/src/custom-select-control/style.scss +11 -10
  122. package/src/date-range-picker/index.js +31 -0
  123. package/src/date-range-picker/style.scss +148 -0
  124. package/src/footer/style.scss +1 -1
  125. package/src/form-token-field/style.scss +1 -1
  126. package/src/grid/style.scss +9 -9
  127. package/src/handoff-message/index.js +3 -1
  128. package/src/image-upload/index.js +1 -1
  129. package/src/image-upload/index.test.js +6 -1
  130. package/src/image-upload/style.scss +5 -5
  131. package/src/index.js +2 -0
  132. package/src/modal/style.scss +5 -5
  133. package/src/newspack-icon/style.scss +1 -1
  134. package/src/newspack-logo/style.scss +1 -1
  135. package/src/notice/style.scss +11 -11
  136. package/src/plugin-installer/style.scss +1 -1
  137. package/src/plugin-settings/style.scss +1 -1
  138. package/src/plugin-toggle/index.js +6 -7
  139. package/src/plugin-toggle/style.scss +1 -1
  140. package/src/popover/style.scss +7 -7
  141. package/src/position-control/index.js +62 -63
  142. package/src/position-control/style.scss +8 -8
  143. package/src/progress-bar/style.scss +2 -2
  144. package/src/radio-control/style.scss +3 -3
  145. package/src/section-header/style.scss +1 -1
  146. package/src/select-control/style.scss +4 -4
  147. package/src/settings/style.scss +1 -1
  148. package/src/steps-list/style.scss +2 -2
  149. package/src/steps-list-item/style.scss +5 -5
  150. package/src/style-card/style.scss +4 -4
  151. package/src/style.scss +1 -1
  152. package/src/tabbed-navigation/index.js +1 -1
  153. package/src/tabbed-navigation/style.scss +4 -4
  154. package/src/web-preview/style.scss +5 -5
  155. package/src/with-wizard/style.scss +44 -22
  156. package/src/with-wizard-screen/style.scss +7 -7
  157. package/dist/cjs/autocomplete-tokenfield/style.scss +0 -49
  158. package/dist/cjs/button/index.js +0 -56
  159. package/dist/cjs/card/style.scss +0 -168
  160. package/dist/cjs/custom-select-control/style.scss +0 -92
  161. package/dist/cjs/form-token-field/style.scss +0 -37
  162. package/dist/cjs/grid/index.js +0 -37
  163. package/dist/cjs/grid/style.scss +0 -166
  164. package/dist/cjs/hooks/index.js +0 -25
  165. package/dist/cjs/hooks/usePrompt.js +0 -49
  166. package/dist/cjs/image-upload/index.js +0 -143
  167. package/dist/cjs/patrons-logo/index.js +0 -81
  168. package/dist/cjs/plugin-installer/index.js +0 -295
  169. package/dist/cjs/plugin-installer/style.scss +0 -72
  170. package/dist/cjs/plugin-settings/index.js +0 -221
  171. package/dist/cjs/plugin-toggle/index.js +0 -218
  172. package/dist/cjs/plugin-toggle/style.scss +0 -20
  173. package/dist/cjs/popover/style.scss +0 -161
  174. package/dist/cjs/progress-bar/style.scss +0 -42
  175. package/dist/cjs/proxied-imports/router.js +0 -14
  176. package/dist/cjs/radio-control/style.scss +0 -92
  177. package/dist/cjs/select-control/style.scss +0 -108
  178. package/dist/cjs/steps-list/style.scss +0 -11
  179. package/dist/cjs/style.scss +0 -55
  180. package/dist/cjs/text-control/index.js +0 -61
  181. package/dist/cjs/web-preview/index.js +0 -188
  182. package/dist/cjs/web-preview/style.scss +0 -155
  183. package/dist/cjs/with-wizard/index.js +0 -317
  184. package/dist/cjs/with-wizard-screen/style.scss +0 -160
  185. package/dist/esm/action-card/index.js +0 -221
  186. package/dist/esm/action-card/style.scss +0 -483
  187. package/dist/esm/autocomplete-tokenfield/index.js +0 -260
  188. package/dist/esm/autocomplete-with-suggestions/index.js +0 -276
  189. package/dist/esm/autocomplete-with-suggestions/style.scss +0 -163
  190. package/dist/esm/button/index.js +0 -48
  191. package/dist/esm/button/style.scss +0 -11
  192. package/dist/esm/button-card/index.js +0 -64
  193. package/dist/esm/button-card/style.scss +0 -174
  194. package/dist/esm/card/index.js +0 -43
  195. package/dist/esm/category-autocomplete/index.js +0 -181
  196. package/dist/esm/category-autocomplete/style.scss +0 -34
  197. package/dist/esm/color-picker/index.js +0 -59
  198. package/dist/esm/color-picker/style.scss +0 -37
  199. package/dist/esm/consts.js +0 -1
  200. package/dist/esm/custom-select-control/index.js +0 -37
  201. package/dist/esm/footer/index.js +0 -100
  202. package/dist/esm/footer/style.scss +0 -82
  203. package/dist/esm/form-token-field/index.js +0 -49
  204. package/dist/esm/global-notices/index.js +0 -30
  205. package/dist/esm/grid/index.js +0 -29
  206. package/dist/esm/handoff/index.js +0 -176
  207. package/dist/esm/handoff-message/index.js +0 -45
  208. package/dist/esm/hooks/index.js +0 -17
  209. package/dist/esm/hooks/useObjectState.js +0 -30
  210. package/dist/esm/hooks/useObjectState.test.js +0 -82
  211. package/dist/esm/hooks/useOnClickOutside.js +0 -31
  212. package/dist/esm/hooks/usePrompt.js +0 -40
  213. package/dist/esm/image-upload/index.js +0 -139
  214. package/dist/esm/image-upload/index.test.js +0 -28
  215. package/dist/esm/image-upload/style.scss +0 -103
  216. package/dist/esm/index.js +0 -45
  217. package/dist/esm/info-button/index.js +0 -42
  218. package/dist/esm/info-button/style.scss +0 -18
  219. package/dist/esm/modal/index.js +0 -39
  220. package/dist/esm/modal/style.scss +0 -56
  221. package/dist/esm/newspack-icon/index.js +0 -50
  222. package/dist/esm/newspack-icon/style.scss +0 -26
  223. package/dist/esm/newspack-logo/index.js +0 -46
  224. package/dist/esm/newspack-logo/style.scss +0 -30
  225. package/dist/esm/notice/index.js +0 -66
  226. package/dist/esm/notice/style.scss +0 -111
  227. package/dist/esm/patrons-logo/index.js +0 -75
  228. package/dist/esm/plugin-installer/index.js +0 -290
  229. package/dist/esm/plugin-settings/SettingsSection.js +0 -134
  230. package/dist/esm/plugin-settings/index.js +0 -216
  231. package/dist/esm/plugin-settings/style.scss +0 -7
  232. package/dist/esm/plugin-toggle/index.js +0 -213
  233. package/dist/esm/popover/index.js +0 -41
  234. package/dist/esm/position-control/index.js +0 -107
  235. package/dist/esm/position-control/style.scss +0 -66
  236. package/dist/esm/progress-bar/index.js +0 -68
  237. package/dist/esm/progress-bar/index.test.js +0 -109
  238. package/dist/esm/proxied-imports/router.js +0 -8
  239. package/dist/esm/radio-control/index.js +0 -37
  240. package/dist/esm/section-header/index.js +0 -67
  241. package/dist/esm/section-header/style.scss +0 -45
  242. package/dist/esm/select-control/ButtonGroupControl.js +0 -53
  243. package/dist/esm/select-control/GroupedSelectControl.js +0 -79
  244. package/dist/esm/select-control/index.js +0 -51
  245. package/dist/esm/settings/MinMaxSetting.js +0 -54
  246. package/dist/esm/settings/SettingsCard.js +0 -38
  247. package/dist/esm/settings/SettingsSection.js +0 -26
  248. package/dist/esm/settings/index.js +0 -9
  249. package/dist/esm/settings/style.scss +0 -119
  250. package/dist/esm/sortable-newsletter-list-control/index.js +0 -128
  251. package/dist/esm/sortable-newsletter-list-control/style.scss +0 -45
  252. package/dist/esm/steps-list/index.js +0 -43
  253. package/dist/esm/steps-list-item/index.js +0 -47
  254. package/dist/esm/steps-list-item/style.scss +0 -47
  255. package/dist/esm/style-card/index.js +0 -75
  256. package/dist/esm/style-card/style.scss +0 -94
  257. package/dist/esm/tabbed-navigation/index.js +0 -53
  258. package/dist/esm/tabbed-navigation/style.scss +0 -86
  259. package/dist/esm/text-control/index.js +0 -57
  260. package/dist/esm/text-control/style.scss +0 -32
  261. package/dist/esm/utils/index.js +0 -29
  262. package/dist/esm/waiting/index.js +0 -44
  263. package/dist/esm/waiting/style.scss +0 -27
  264. package/dist/esm/web-preview/index.js +0 -183
  265. package/dist/esm/with-wizard/index.js +0 -311
  266. package/dist/esm/with-wizard/style.scss +0 -260
  267. package/dist/esm/with-wizard-screen/index.js +0 -110
  268. package/dist/esm/wizard/components/WizardError.js +0 -67
  269. package/dist/esm/wizard/index.js +0 -120
  270. package/dist/esm/wizard/store/index.js +0 -155
  271. package/dist/esm/wizard/store/utils.js +0 -14
  272. /package/dist/{cjs/consts.js → consts.js} +0 -0
  273. /package/dist/{cjs/hooks → hooks}/useOnClickOutside.js +0 -0
  274. /package/dist/{cjs/info-button → info-button}/style.scss +0 -0
  275. /package/dist/{cjs/sortable-newsletter-list-control → sortable-newsletter-list-control}/style.scss +0 -0
  276. /package/dist/{cjs/text-control → text-control}/style.scss +0 -0
  277. /package/dist/{cjs/waiting → waiting}/style.scss +0 -0
  278. /package/dist/{cjs/wizard → wizard}/store/utils.js +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
  };
@@ -95,7 +97,7 @@ const SettingsSection = props => {
95
97
  } else if (fields.length === 1) {
96
98
  columns = 1;
97
99
  }
98
- return (0, _jsxRuntime.jsx)(_.ActionCard, {
100
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.ActionCard, {
99
101
  isMedium: true,
100
102
  disabled: disabled,
101
103
  title: title,
@@ -105,25 +107,25 @@ const SettingsSection = props => {
105
107
  toggleOnChange: active !== null ? value => onUpdate({
106
108
  active: value
107
109
  }) : null,
108
- actionContent: (active || null === active) && createFilter('buttons', (0, _jsxRuntime.jsx)(_.Button, {
110
+ actionContent: (active || null === active) && createFilter('buttons', /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
109
111
  variant: "primary",
110
112
  disabled: disabled || saveDisabled,
111
113
  onClick: () => {
112
114
  onUpdate();
113
115
  setSaveDisabled(true);
114
116
  },
115
- children: __('Save Settings', 'newspack')
117
+ children: (0, _i18n.__)('Save Settings', 'newspack')
116
118
  })),
117
- children: (active || active === null) && (0, _jsxRuntime.jsxs)(_element.Fragment, {
118
- 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, {
119
121
  noticeText: error.message,
120
122
  isError: true
121
- }), createFilter('beforeControls'), (0, _jsxRuntime.jsx)(_.Grid, {
123
+ }), createFilter('beforeControls'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Grid, {
122
124
  columns: columns,
123
125
  gutter: 32,
124
126
  children: fields.map(setting => {
125
127
  const Control = getControlComponent(setting); // eslint-disable-line @wordpress/no-unused-vars-before-return, no-unused-vars
126
- 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, {
127
129
  ...getControlProps(setting)
128
130
  }, setting.key), {
129
131
  sectionKey,
@@ -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
+ ```