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
@@ -1,216 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /**
3
- * External dependencies
4
- */
5
- import classnames from 'classnames';
6
-
7
- /**
8
- * WordPress dependencies.
9
- */
10
- import apiFetch from '@wordpress/api-fetch';
11
- import { Component, Fragment } from '@wordpress/element';
12
- import { __ as alias__ } from '@wordpress/i18n';
13
-
14
- /**
15
- * Internal dependencies.
16
- */
17
- const __ = alias__;
18
- import { SectionHeader, Notice } from '../';
19
- import SettingsSection from './SettingsSection';
20
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
21
- class PluginSettings extends Component {
22
- constructor() {
23
- super(...arguments);
24
- _defineProperty(this, "fetchSettings", () => {
25
- const {
26
- afterFetch,
27
- pluginSlug,
28
- isWizard
29
- } = this.props;
30
- this.setState({
31
- inFlight: true
32
- });
33
- apiFetch({
34
- path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`
35
- }).then(settings => {
36
- this.setState({
37
- settings,
38
- error: null
39
- });
40
- if ('function' === typeof afterFetch) {
41
- afterFetch(settings);
42
- }
43
- }).catch(error => {
44
- this.setState({
45
- error
46
- });
47
- }).finally(() => {
48
- this.setState({
49
- inFlight: false
50
- });
51
- });
52
- });
53
- _defineProperty(this, "getSettingsValues", sectionKey => {
54
- return this.state.settings[sectionKey]?.reduce((map, setting) => {
55
- map[setting.key] = setting.value;
56
- return map;
57
- }, {}) || {};
58
- });
59
- _defineProperty(this, "handleSettingChange", sectionKey => (key, value) => {
60
- const sectionSettings = [...this.state.settings[sectionKey]];
61
- sectionSettings.forEach(setting => {
62
- if (setting.key === key) {
63
- setting.value = value;
64
- }
65
- });
66
- this.setState({
67
- settings: {
68
- ...this.state.settings,
69
- [sectionKey]: sectionSettings
70
- }
71
- });
72
- });
73
- _defineProperty(this, "handleSectionUpdate", sectionKey => data => {
74
- const {
75
- afterUpdate,
76
- pluginSlug,
77
- isWizard
78
- } = this.props;
79
- this.setState({
80
- inFlight: true
81
- });
82
- apiFetch({
83
- path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`,
84
- method: 'POST',
85
- data: {
86
- section: sectionKey,
87
- settings: data ? data : this.getSettingsValues(sectionKey)
88
- }
89
- }).then(settings => {
90
- this.setState({
91
- settings: {
92
- ...this.state.settings,
93
- [sectionKey]: settings[sectionKey]
94
- },
95
- error: null
96
- });
97
- if ('function' === typeof afterUpdate) {
98
- afterUpdate(settings);
99
- }
100
- }).catch(error => {
101
- this.setState({
102
- error
103
- });
104
- }).finally(() => {
105
- this.setState({
106
- inFlight: false
107
- });
108
- });
109
- });
110
- /**
111
- * Get the section setting containing section information.
112
- *
113
- * @param {string} sectionKey The section name.
114
- * @return {Object} The section setting.
115
- */
116
- _defineProperty(this, "getSectionInfo", sectionKey => {
117
- return this.state.settings[sectionKey]?.find(setting => !setting.key || setting.key === 'active');
118
- });
119
- /**
120
- * Get the section title.
121
- *
122
- * @param {string} sectionKey The section name.
123
- * @return {string} The section title.
124
- */
125
- _defineProperty(this, "getSectionTitle", sectionKey => {
126
- return this.getSectionInfo(sectionKey)?.description;
127
- });
128
- /**
129
- * Get the section description.
130
- *
131
- * @param {string} sectionKey The section name.
132
- * @return {string} The section description.
133
- */
134
- _defineProperty(this, "getSectionDescription", sectionKey => {
135
- return this.getSectionInfo(sectionKey)?.help;
136
- });
137
- /**
138
- * Get whether a section is active.
139
- *
140
- * @param {string} sectionKey The section name.
141
- * @return {?boolean} Whether the section is active or not. Null if the section is not found or does not support activation.
142
- */
143
- _defineProperty(this, "isSectionActive", sectionKey => {
144
- const {
145
- settings
146
- } = this.state;
147
- const activation = settings[sectionKey]?.find(setting => setting.key === 'active');
148
- if (!activation) {
149
- return null;
150
- }
151
- return activation.value;
152
- });
153
- /**
154
- * Get list of section field settings.
155
- *
156
- * @param {string} sectionKey The section name.
157
- * @return {?Array} List of section fields.
158
- */
159
- _defineProperty(this, "getSectionFields", sectionKey => {
160
- return this.state.settings[sectionKey]?.filter(setting => setting.key && setting.key !== 'active');
161
- });
162
- this.state = {
163
- inFlight: false,
164
- settings: {},
165
- error: null
166
- };
167
- }
168
- componentDidMount() {
169
- this.fetchSettings();
170
- }
171
- /**
172
- * Render.
173
- */
174
- render() {
175
- const {
176
- title,
177
- description,
178
- hasGreyHeader,
179
- children
180
- } = this.props;
181
- const {
182
- settings,
183
- inFlight,
184
- error
185
- } = this.state;
186
- return _jsxs(Fragment, {
187
- children: [title && _jsx(SectionHeader, {
188
- title: title,
189
- description: description
190
- }), error && _jsx(Notice, {
191
- isError: true,
192
- noticeText: error.message
193
- }), _jsxs("div", {
194
- className: classnames('newspack-plugin-settings', {
195
- 'newspack-wizard-section__is-loading': inFlight && !Object.keys(settings).length
196
- }),
197
- children: [Object.keys(settings).map(sectionKey => _jsx(SettingsSection, {
198
- disabled: inFlight,
199
- sectionKey: sectionKey,
200
- title: this.getSectionTitle(sectionKey),
201
- description: this.getSectionDescription(sectionKey),
202
- active: this.isSectionActive(sectionKey),
203
- fields: this.getSectionFields(sectionKey),
204
- onChange: this.handleSettingChange(sectionKey),
205
- onUpdate: this.handleSectionUpdate(sectionKey),
206
- hasGreyHeader: hasGreyHeader
207
- }, sectionKey)), children]
208
- })]
209
- });
210
- }
211
- }
212
- PluginSettings.defaultProps = {
213
- title: __('General Settings', 'newspack-plugin')
214
- };
215
- PluginSettings.Section = SettingsSection;
216
- export default PluginSettings;
@@ -1,7 +0,0 @@
1
- .newspack-card:not( .newspack-settings__no-border ) {
2
- .newspack-action-card__region-children {
3
- > .newspack-grid {
4
- margin: 32px 0 0 !important;
5
- }
6
- }
7
- }
@@ -1,213 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /**
3
- * WordPress dependencies.
4
- */
5
- import apiFetch from '@wordpress/api-fetch';
6
- import { Component, Fragment } from '@wordpress/element';
7
- import { __ as alias__ } from '@wordpress/i18n';
8
-
9
- /**
10
- * Internal dependencies.
11
- */
12
- const __ = alias__;
13
- import { ActionCard, Waiting } from '../';
14
- import './style.scss';
15
-
16
- /**
17
- * Plugin toggle group component.
18
- */
19
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
20
- class PluginToggle extends Component {
21
- constructor(...args) {
22
- super(...args);
23
- _defineProperty(this, "state", {
24
- pluginInfo: {}
25
- });
26
- _defineProperty(this, "componentDidMount", () => {
27
- this.retrievePluginInfo();
28
- });
29
- /**
30
- * Retrieve complete data about Newspack plugins.
31
- */
32
- _defineProperty(this, "retrievePluginInfo", () => {
33
- return new Promise(() => {
34
- apiFetch({
35
- path: '/newspack/v1/plugins/'
36
- }).then(pluginInfo => this.setState({
37
- pluginInfo
38
- }));
39
- });
40
- });
41
- /**
42
- * Install/activate or remove a plugin.
43
- */
44
- _defineProperty(this, "managePlugin", (plugin, value) => {
45
- const {
46
- plugins
47
- } = this.props;
48
- const {
49
- pluginInfo
50
- } = this.state;
51
- const action = value ? 'configure' : 'deactivate';
52
- const params = {
53
- path: `/newspack/v1/plugins/${plugin}/${action}/`,
54
- method: 'post'
55
- };
56
- this.setState({
57
- pluginInfo: {
58
- ...pluginInfo,
59
- [plugin]: {
60
- ...pluginInfo[plugin],
61
- inFlight: action
62
- }
63
- }
64
- }, () => {
65
- apiFetch(params).then(response => {
66
- const {
67
- shouldRefreshAfterUpdate
68
- } = plugins[plugin];
69
- this.setState(({
70
- pluginInfo: currentPluginInfo
71
- }) => ({
72
- pluginInfo: {
73
- ...currentPluginInfo,
74
- [plugin]: response
75
- }
76
- }), () => shouldRefreshAfterUpdate && location.reload());
77
- }).catch(e => {
78
- this.setState({
79
- pluginInfo: {
80
- ...pluginInfo,
81
- [plugin]: {
82
- ...pluginInfo[plugin],
83
- error: e.message || __('There was an error managing this plugin.', 'newspack-plugin')
84
- }
85
- }
86
- });
87
- });
88
- });
89
- });
90
- /**
91
- * Prepare plugins data for render. Change all keys to camelCase, merge API-fetched data with prop.
92
- */
93
- _defineProperty(this, "prepareDataForRender", (pluginsFromProps, pluginsFromAPI) => Object.keys(pluginsFromProps).map(pluginSlug => pluginsFromAPI[pluginSlug] ? Object.keys(pluginsFromAPI[pluginSlug]).reduce((accumulator, key) => ({
94
- ...accumulator,
95
- [key.charAt(0).toLowerCase() + key.slice(1)]: pluginsFromAPI[pluginSlug][key]
96
- }), {}) : {}).map(plugin => Object.assign(plugin, pluginsFromProps[plugin.slug])));
97
- /**
98
- * 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.
99
- */
100
- _defineProperty(this, "classNameForPlugin", plugin => {
101
- const {
102
- status,
103
- inFlight
104
- } = plugin;
105
- if (inFlight) {
106
- return 'in-flight';
107
- }
108
- if (!status) {
109
- return 'loading';
110
- }
111
- });
112
- /**
113
- * Generate the ActionCard action text for a plugin.
114
- */
115
- _defineProperty(this, "actionTextForPlugin", plugin => {
116
- const {
117
- actionText,
118
- editPath,
119
- href,
120
- inFlight,
121
- name
122
- } = plugin;
123
- // Show spinner when plugin data is unavailable, or when an API call is in flight.
124
- if ('configure' === inFlight) {
125
- return _jsxs(Fragment, {
126
- children: [__('Installing…', 'newspack-plugin'), " ", _jsx(Waiting, {
127
- isRight: true
128
- })]
129
- });
130
- }
131
- if ('deactivate' === inFlight) {
132
- return _jsxs(Fragment, {
133
- children: [__('Deactivating…', 'newspack-plugin'), " ", _jsx(Waiting, {
134
- isRight: true
135
- })]
136
- });
137
- }
138
- if (!name) {
139
- return _jsxs(Fragment, {
140
- children: [__('Loading…', 'newspack-plugin'), " ", _jsx(Waiting, {
141
- isRight: true
142
- })]
143
- });
144
- }
145
- // No action button at all if the plugin isn't installed and active.
146
- if (!this.isPluginInstalledAndActive(plugin)) {
147
- return null;
148
- }
149
- if (href || editPath) {
150
- return actionText ? actionText : __('Configure', 'newspack-plugin');
151
- }
152
- });
153
- /**
154
- * Get error message for this plugin.
155
- */
156
- _defineProperty(this, "errorForPlugin", plugin => {
157
- const {
158
- slug
159
- } = plugin;
160
- const {
161
- pluginInfo
162
- } = this.state;
163
- return pluginInfo[slug]?.error || null;
164
- });
165
- /**
166
- * Get installation/activation status for a plugin.
167
- */
168
- _defineProperty(this, "isPluginInstalledAndActive", plugin => {
169
- const {
170
- status
171
- } = plugin;
172
- return status === 'active';
173
- });
174
- }
175
- /**
176
- * Render.
177
- */
178
- render() {
179
- const {
180
- plugins
181
- } = this.props;
182
- const {
183
- pluginInfo
184
- } = this.state;
185
- return this.prepareDataForRender(plugins, pluginInfo).map((plugin, index) => {
186
- const {
187
- name,
188
- description,
189
- href,
190
- slug,
191
- editPath
192
- } = plugin;
193
- const pluginStatus = this.isPluginInstalledAndActive(plugin);
194
- const handoff = !href && pluginStatus && editPath ? slug : null;
195
- const error = this.errorForPlugin(plugin);
196
- return _jsx(ActionCard, {
197
- className: this.classNameForPlugin(plugin),
198
- title: name,
199
- description: description,
200
- actionText: this.actionTextForPlugin(plugin),
201
- handoff: handoff,
202
- href: href,
203
- toggle: true,
204
- toggleChecked: this.isPluginInstalledAndActive(plugin),
205
- toggleOnChange: value => this.managePlugin(slug, value),
206
- notification: error,
207
- notificationHTML: error,
208
- notificationLevel: "error"
209
- }, index);
210
- });
211
- }
212
- }
213
- export default PluginToggle;
@@ -1,41 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { Popover as BaseComponent } from '@wordpress/components';
5
- import { Component } from '@wordpress/element';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import './style.scss';
11
-
12
- /**
13
- * External dependencies
14
- */
15
- import classnames from 'classnames';
16
-
17
- /**
18
- * Popover
19
- */
20
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
21
- class Popover extends Component {
22
- /**
23
- * Render
24
- */
25
- render() {
26
- const {
27
- className,
28
- padding,
29
- ...otherProps
30
- } = this.props;
31
- const classes = classnames('newspack-popover', padding && 'newspack-popover__padding-' + padding, className);
32
- return _jsx(BaseComponent, {
33
- className: classes,
34
- ...otherProps
35
- });
36
- }
37
- }
38
- Popover.defaultProps = {
39
- padding: false
40
- };
41
- export default Popover;
@@ -1,107 +0,0 @@
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, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
18
- export default function PositionControl({
19
- allowedPositions,
20
- value,
21
- label,
22
- help,
23
- onChange,
24
- size,
25
- ...props
26
- }) {
27
- /**
28
- * Set layout options
29
- */
30
- const options = size === 'full-width' ? [{
31
- value: 'top',
32
- /* translators: Overlay Position */
33
- label: __('Top', 'newspack-plugin')
34
- }, {
35
- value: 'center',
36
- /* translators: Overlay Position */
37
- label: __('Center', 'newspack-plugin')
38
- }, {
39
- value: 'bottom',
40
- /* translators: Overlay Position */
41
- label: __('Bottom', 'newspack-plugin')
42
- }] : [{
43
- value: 'top_left',
44
- /* translators: Overlay Position */
45
- label: __('Top Left', 'newspack-plugin')
46
- }, {
47
- value: 'top',
48
- /* translators: Overlay Position */
49
- label: __('Top Center', 'newspack-plugin')
50
- }, {
51
- value: 'top_right',
52
- /* translators: Overlay Position */
53
- label: __('Top Right', 'newspack-plugin')
54
- }, {
55
- value: 'center_left',
56
- /* translators: Overlay Position */
57
- label: __('Center Left', 'newspack-plugin')
58
- }, {
59
- value: 'center',
60
- /* translators: Overlay Position */
61
- label: __('Center', 'newspack-plugin')
62
- }, {
63
- value: 'center_right',
64
- /* translators: Overlay Position */
65
- label: __('Center Right', 'newspack-plugin')
66
- }, {
67
- value: 'bottom_left',
68
- /* translators: Overlay Position */
69
- label: __('Bottom Left', 'newspack-plugin')
70
- }, {
71
- value: 'bottom',
72
- /* translators: Overlay Position */
73
- label: __('Bottom Center', 'newspack-plugin')
74
- }, {
75
- value: 'bottom_right',
76
- /* translators: Overlay Position */
77
- label: __('Bottom Right', 'newspack-plugin')
78
- }];
79
- return _jsxs("div", {
80
- className: classnames('newspack-position-placement-control', 'size-' + size),
81
- children: [_jsx("p", {
82
- className: "components-base-control__label",
83
- children: label
84
- }), _jsx(ButtonGroup, {
85
- "aria-label": __('Select Position', 'newspack-plugin'),
86
- ...props,
87
- children: options.map((option, index) => {
88
- return _jsx("div", {
89
- className: option.value === value ? 'is-selected' : null,
90
- children: _jsx(Button, {
91
- isSmall: true,
92
- title: option.label,
93
- "aria-label": option.label,
94
- isPrimary: option.value === value,
95
- onClick: () => {
96
- onChange(option.value);
97
- },
98
- disabled: allowedPositions?.length && !allowedPositions.includes(option.value)
99
- })
100
- }, `newspack-position-placement-item-${index}`);
101
- })
102
- }), _jsx("p", {
103
- className: "components-base-control__help",
104
- children: help
105
- })]
106
- });
107
- }
@@ -1,66 +0,0 @@
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
- }