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,221 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _classnames = _interopRequireDefault(require("classnames"));
10
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
11
- var _element = require("@wordpress/element");
12
- var _i18n = require("@wordpress/i18n");
13
- var _ = require("../");
14
- var _SettingsSection = _interopRequireDefault(require("./SettingsSection"));
15
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
16
- /**
17
- * External dependencies
18
- */
19
- /**
20
- * WordPress dependencies.
21
- */
22
- /**
23
- * Internal dependencies.
24
- */
25
- const __ = _i18n.__;
26
- class PluginSettings extends _element.Component {
27
- constructor() {
28
- super(...arguments);
29
- (0, _defineProperty2.default)(this, "fetchSettings", () => {
30
- const {
31
- afterFetch,
32
- pluginSlug,
33
- isWizard
34
- } = this.props;
35
- this.setState({
36
- inFlight: true
37
- });
38
- (0, _apiFetch.default)({
39
- path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`
40
- }).then(settings => {
41
- this.setState({
42
- settings,
43
- error: null
44
- });
45
- if ('function' === typeof afterFetch) {
46
- afterFetch(settings);
47
- }
48
- }).catch(error => {
49
- this.setState({
50
- error
51
- });
52
- }).finally(() => {
53
- this.setState({
54
- inFlight: false
55
- });
56
- });
57
- });
58
- (0, _defineProperty2.default)(this, "getSettingsValues", sectionKey => {
59
- return this.state.settings[sectionKey]?.reduce((map, setting) => {
60
- map[setting.key] = setting.value;
61
- return map;
62
- }, {}) || {};
63
- });
64
- (0, _defineProperty2.default)(this, "handleSettingChange", sectionKey => (key, value) => {
65
- const sectionSettings = [...this.state.settings[sectionKey]];
66
- sectionSettings.forEach(setting => {
67
- if (setting.key === key) {
68
- setting.value = value;
69
- }
70
- });
71
- this.setState({
72
- settings: {
73
- ...this.state.settings,
74
- [sectionKey]: sectionSettings
75
- }
76
- });
77
- });
78
- (0, _defineProperty2.default)(this, "handleSectionUpdate", sectionKey => data => {
79
- const {
80
- afterUpdate,
81
- pluginSlug,
82
- isWizard
83
- } = this.props;
84
- this.setState({
85
- inFlight: true
86
- });
87
- (0, _apiFetch.default)({
88
- path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`,
89
- method: 'POST',
90
- data: {
91
- section: sectionKey,
92
- settings: data ? data : this.getSettingsValues(sectionKey)
93
- }
94
- }).then(settings => {
95
- this.setState({
96
- settings: {
97
- ...this.state.settings,
98
- [sectionKey]: settings[sectionKey]
99
- },
100
- error: null
101
- });
102
- if ('function' === typeof afterUpdate) {
103
- afterUpdate(settings);
104
- }
105
- }).catch(error => {
106
- this.setState({
107
- error
108
- });
109
- }).finally(() => {
110
- this.setState({
111
- inFlight: false
112
- });
113
- });
114
- });
115
- /**
116
- * Get the section setting containing section information.
117
- *
118
- * @param {string} sectionKey The section name.
119
- * @return {Object} The section setting.
120
- */
121
- (0, _defineProperty2.default)(this, "getSectionInfo", sectionKey => {
122
- return this.state.settings[sectionKey]?.find(setting => !setting.key || setting.key === 'active');
123
- });
124
- /**
125
- * Get the section title.
126
- *
127
- * @param {string} sectionKey The section name.
128
- * @return {string} The section title.
129
- */
130
- (0, _defineProperty2.default)(this, "getSectionTitle", sectionKey => {
131
- return this.getSectionInfo(sectionKey)?.description;
132
- });
133
- /**
134
- * Get the section description.
135
- *
136
- * @param {string} sectionKey The section name.
137
- * @return {string} The section description.
138
- */
139
- (0, _defineProperty2.default)(this, "getSectionDescription", sectionKey => {
140
- return this.getSectionInfo(sectionKey)?.help;
141
- });
142
- /**
143
- * Get whether a section is active.
144
- *
145
- * @param {string} sectionKey The section name.
146
- * @return {?boolean} Whether the section is active or not. Null if the section is not found or does not support activation.
147
- */
148
- (0, _defineProperty2.default)(this, "isSectionActive", sectionKey => {
149
- const {
150
- settings
151
- } = this.state;
152
- const activation = settings[sectionKey]?.find(setting => setting.key === 'active');
153
- if (!activation) {
154
- return null;
155
- }
156
- return activation.value;
157
- });
158
- /**
159
- * Get list of section field settings.
160
- *
161
- * @param {string} sectionKey The section name.
162
- * @return {?Array} List of section fields.
163
- */
164
- (0, _defineProperty2.default)(this, "getSectionFields", sectionKey => {
165
- return this.state.settings[sectionKey]?.filter(setting => setting.key && setting.key !== 'active');
166
- });
167
- this.state = {
168
- inFlight: false,
169
- settings: {},
170
- error: null
171
- };
172
- }
173
- componentDidMount() {
174
- this.fetchSettings();
175
- }
176
- /**
177
- * Render.
178
- */
179
- render() {
180
- const {
181
- title,
182
- description,
183
- hasGreyHeader,
184
- children
185
- } = this.props;
186
- const {
187
- settings,
188
- inFlight,
189
- error
190
- } = this.state;
191
- return (0, _jsxRuntime.jsxs)(_element.Fragment, {
192
- children: [title && (0, _jsxRuntime.jsx)(_.SectionHeader, {
193
- title: title,
194
- description: description
195
- }), error && (0, _jsxRuntime.jsx)(_.Notice, {
196
- isError: true,
197
- noticeText: error.message
198
- }), (0, _jsxRuntime.jsxs)("div", {
199
- className: (0, _classnames.default)('newspack-plugin-settings', {
200
- 'newspack-wizard-section__is-loading': inFlight && !Object.keys(settings).length
201
- }),
202
- children: [Object.keys(settings).map(sectionKey => (0, _jsxRuntime.jsx)(_SettingsSection.default, {
203
- disabled: inFlight,
204
- sectionKey: sectionKey,
205
- title: this.getSectionTitle(sectionKey),
206
- description: this.getSectionDescription(sectionKey),
207
- active: this.isSectionActive(sectionKey),
208
- fields: this.getSectionFields(sectionKey),
209
- onChange: this.handleSettingChange(sectionKey),
210
- onUpdate: this.handleSectionUpdate(sectionKey),
211
- hasGreyHeader: hasGreyHeader
212
- }, sectionKey)), children]
213
- })]
214
- });
215
- }
216
- }
217
- PluginSettings.defaultProps = {
218
- title: __('General Settings', 'newspack-plugin')
219
- };
220
- PluginSettings.Section = _SettingsSection.default;
221
- var _default = exports.default = PluginSettings;
@@ -1,218 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
10
- var _element = require("@wordpress/element");
11
- var _i18n = require("@wordpress/i18n");
12
- var _ = require("../");
13
- require("./style.scss");
14
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
15
- /**
16
- * WordPress dependencies.
17
- */
18
- /**
19
- * Internal dependencies.
20
- */
21
- const __ = _i18n.__;
22
- /**
23
- * Plugin toggle group component.
24
- */
25
- class PluginToggle extends _element.Component {
26
- constructor(...args) {
27
- super(...args);
28
- (0, _defineProperty2.default)(this, "state", {
29
- pluginInfo: {}
30
- });
31
- (0, _defineProperty2.default)(this, "componentDidMount", () => {
32
- this.retrievePluginInfo();
33
- });
34
- /**
35
- * Retrieve complete data about Newspack plugins.
36
- */
37
- (0, _defineProperty2.default)(this, "retrievePluginInfo", () => {
38
- return new Promise(() => {
39
- (0, _apiFetch.default)({
40
- path: '/newspack/v1/plugins/'
41
- }).then(pluginInfo => this.setState({
42
- pluginInfo
43
- }));
44
- });
45
- });
46
- /**
47
- * Install/activate or remove a plugin.
48
- */
49
- (0, _defineProperty2.default)(this, "managePlugin", (plugin, value) => {
50
- const {
51
- plugins
52
- } = this.props;
53
- const {
54
- pluginInfo
55
- } = this.state;
56
- const action = value ? 'configure' : 'deactivate';
57
- const params = {
58
- path: `/newspack/v1/plugins/${plugin}/${action}/`,
59
- method: 'post'
60
- };
61
- this.setState({
62
- pluginInfo: {
63
- ...pluginInfo,
64
- [plugin]: {
65
- ...pluginInfo[plugin],
66
- inFlight: action
67
- }
68
- }
69
- }, () => {
70
- (0, _apiFetch.default)(params).then(response => {
71
- const {
72
- shouldRefreshAfterUpdate
73
- } = plugins[plugin];
74
- this.setState(({
75
- pluginInfo: currentPluginInfo
76
- }) => ({
77
- pluginInfo: {
78
- ...currentPluginInfo,
79
- [plugin]: response
80
- }
81
- }), () => shouldRefreshAfterUpdate && location.reload());
82
- }).catch(e => {
83
- this.setState({
84
- pluginInfo: {
85
- ...pluginInfo,
86
- [plugin]: {
87
- ...pluginInfo[plugin],
88
- error: e.message || __('There was an error managing this plugin.', 'newspack-plugin')
89
- }
90
- }
91
- });
92
- });
93
- });
94
- });
95
- /**
96
- * Prepare plugins data for render. Change all keys to camelCase, merge API-fetched data with prop.
97
- */
98
- (0, _defineProperty2.default)(this, "prepareDataForRender", (pluginsFromProps, pluginsFromAPI) => Object.keys(pluginsFromProps).map(pluginSlug => pluginsFromAPI[pluginSlug] ? Object.keys(pluginsFromAPI[pluginSlug]).reduce((accumulator, key) => ({
99
- ...accumulator,
100
- [key.charAt(0).toLowerCase() + key.slice(1)]: pluginsFromAPI[pluginSlug][key]
101
- }), {}) : {}).map(plugin => Object.assign(plugin, pluginsFromProps[plugin.slug])));
102
- /**
103
- * 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.
104
- */
105
- (0, _defineProperty2.default)(this, "classNameForPlugin", plugin => {
106
- const {
107
- status,
108
- inFlight
109
- } = plugin;
110
- if (inFlight) {
111
- return 'in-flight';
112
- }
113
- if (!status) {
114
- return 'loading';
115
- }
116
- });
117
- /**
118
- * Generate the ActionCard action text for a plugin.
119
- */
120
- (0, _defineProperty2.default)(this, "actionTextForPlugin", plugin => {
121
- const {
122
- actionText,
123
- editPath,
124
- href,
125
- inFlight,
126
- name
127
- } = plugin;
128
- // Show spinner when plugin data is unavailable, or when an API call is in flight.
129
- if ('configure' === inFlight) {
130
- return (0, _jsxRuntime.jsxs)(_element.Fragment, {
131
- children: [__('Installing…', 'newspack-plugin'), " ", (0, _jsxRuntime.jsx)(_.Waiting, {
132
- isRight: true
133
- })]
134
- });
135
- }
136
- if ('deactivate' === inFlight) {
137
- return (0, _jsxRuntime.jsxs)(_element.Fragment, {
138
- children: [__('Deactivating…', 'newspack-plugin'), " ", (0, _jsxRuntime.jsx)(_.Waiting, {
139
- isRight: true
140
- })]
141
- });
142
- }
143
- if (!name) {
144
- return (0, _jsxRuntime.jsxs)(_element.Fragment, {
145
- children: [__('Loading…', 'newspack-plugin'), " ", (0, _jsxRuntime.jsx)(_.Waiting, {
146
- isRight: true
147
- })]
148
- });
149
- }
150
- // No action button at all if the plugin isn't installed and active.
151
- if (!this.isPluginInstalledAndActive(plugin)) {
152
- return null;
153
- }
154
- if (href || editPath) {
155
- return actionText ? actionText : __('Configure', 'newspack-plugin');
156
- }
157
- });
158
- /**
159
- * Get error message for this plugin.
160
- */
161
- (0, _defineProperty2.default)(this, "errorForPlugin", plugin => {
162
- const {
163
- slug
164
- } = plugin;
165
- const {
166
- pluginInfo
167
- } = this.state;
168
- return pluginInfo[slug]?.error || null;
169
- });
170
- /**
171
- * Get installation/activation status for a plugin.
172
- */
173
- (0, _defineProperty2.default)(this, "isPluginInstalledAndActive", plugin => {
174
- const {
175
- status
176
- } = plugin;
177
- return status === 'active';
178
- });
179
- }
180
- /**
181
- * Render.
182
- */
183
- render() {
184
- const {
185
- plugins
186
- } = this.props;
187
- const {
188
- pluginInfo
189
- } = this.state;
190
- return this.prepareDataForRender(plugins, pluginInfo).map((plugin, index) => {
191
- const {
192
- name,
193
- description,
194
- href,
195
- slug,
196
- editPath
197
- } = plugin;
198
- const pluginStatus = this.isPluginInstalledAndActive(plugin);
199
- const handoff = !href && pluginStatus && editPath ? slug : null;
200
- const error = this.errorForPlugin(plugin);
201
- return (0, _jsxRuntime.jsx)(_.ActionCard, {
202
- className: this.classNameForPlugin(plugin),
203
- title: name,
204
- description: description,
205
- actionText: this.actionTextForPlugin(plugin),
206
- handoff: handoff,
207
- href: href,
208
- toggle: true,
209
- toggleChecked: this.isPluginInstalledAndActive(plugin),
210
- toggleOnChange: value => this.managePlugin(slug, value),
211
- notification: error,
212
- notificationHTML: error,
213
- notificationLevel: "error"
214
- }, index);
215
- });
216
- }
217
- }
218
- var _default = exports.default = PluginToggle;
@@ -1,20 +0,0 @@
1
- /**
2
- * Plugin Toggle
3
- */
4
-
5
- @use '~@wordpress/base-styles/colors' as wp-colors;
6
-
7
- .newspack-action-card {
8
- &.in-flight,
9
- &.loading {
10
- opacity: 0.5;
11
-
12
- .newspack-action-card__region-right {
13
- .newspack-button {
14
- color: wp-colors.$gray-700;
15
- pointer-events: none;
16
- text-decoration: none;
17
- }
18
- }
19
- }
20
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * Popover
3
- */
4
-
5
- @use '../../../shared/scss/colors';
6
- @use '~@wordpress/base-styles/colors' as wp-colors;
7
-
8
- .newspack-popover {
9
- .components-popover__content {
10
- min-width: 238px;
11
-
12
- .newspack-button {
13
- color: wp-colors.$gray-700;
14
- display: flex;
15
- font-weight: normal;
16
- padding: 6px 8px;
17
-
18
- &:hover {
19
- color: colors.$primary-500;
20
-
21
- .components-menu-items__item-icon {
22
- fill: currentcolor;
23
- }
24
- }
25
-
26
- &:focus:not( :disabled ) {
27
- box-shadow: inset 0 0 0 2px colors.$primary-500;
28
- position: relative;
29
- z-index: 1;
30
- }
31
-
32
- &.is-link {
33
- border-radius: 2px;
34
- padding: 6px 8px;
35
- text-decoration: none;
36
-
37
- &:not( .is-destructive ) {
38
- color: wp-colors.$gray-700;
39
-
40
- &:active,
41
- &:active:enabled,
42
- &:focus,
43
- &:focus:enabled &:hover,
44
- &:not( :disabled, [aria-disabled='true'], .is-default ):hover {
45
- color: colors.$primary-500;
46
- }
47
- }
48
-
49
- &:focus,
50
- &:focus:enabled {
51
- outline: none;
52
- }
53
- }
54
-
55
- &.is-destructive:not( :focus ) {
56
- box-shadow: none !important;
57
- }
58
-
59
- .components-menu-items__item-icon {
60
- fill: wp-colors.$gray-900;
61
- }
62
-
63
- .components-menu-item__item {
64
- display: flex;
65
- width: 100%;
66
- }
67
- }
68
-
69
- .components-menu-group__label {
70
- color: wp-colors.$gray-900;
71
- font-size: 12px;
72
- font-weight: bold;
73
- line-height: 16px;
74
- margin: 0;
75
- padding: 10px 8px;
76
- }
77
-
78
- .screen-reader-text {
79
- display: flex;
80
- }
81
-
82
- .newspack-select-control {
83
- margin: 0;
84
- width: 100%;
85
-
86
- .components-select-control {
87
- select.components-select-control__input {
88
- height: 36px;
89
- min-height: 36px;
90
-
91
- &:focus ~ div.components-input-control__backdrop {
92
- border-color: colors.$primary-500;
93
- box-shadow: inset 0 0 0 1px colors.$primary-500;
94
- }
95
- }
96
-
97
- div.components-input-control__backdrop {
98
- padding: 0;
99
- }
100
- }
101
- }
102
-
103
- .newspack-form-token-field {
104
- margin: 0;
105
- text-align: left;
106
-
107
- .newspack-form-token-field__input-container {
108
- min-height: 36px;
109
- padding: 3px 5px;
110
- }
111
-
112
- .components-form-token-field__suggestions-list {
113
- margin: 5px -3px -11px;
114
- }
115
-
116
- .components-form-token-field__label {
117
- display: block;
118
- }
119
- }
120
-
121
- .newspack-toggle-control {
122
- margin: 0;
123
-
124
- .components-base-control__field {
125
- margin: 3px 0;
126
- }
127
-
128
- .components-form-toggle {
129
- border-top: 0;
130
- }
131
- }
132
- }
133
-
134
- &:not( .is-without-arrow )::before {
135
- border-color: wp-colors.$gray-300;
136
- }
137
-
138
- &.is-from-bottom {
139
- margin-bottom: 2px;
140
- }
141
-
142
- &.is-from-top {
143
- margin-top: 2px;
144
- }
145
-
146
- &.components-animate__appear {
147
- animation: none;
148
- }
149
-
150
- &__padding-8 {
151
- .components-popover__content {
152
- padding: 8px;
153
- }
154
- }
155
-
156
- &__padding-16 {
157
- .components-popover__content {
158
- padding: 16px;
159
- }
160
- }
161
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Progress Bar
3
- */
4
-
5
- @use '../../../shared/scss/colors';
6
- @use '~@wordpress/base-styles/colors' as wp-colors;
7
-
8
- .newspack-progress-bar {
9
- margin: 32px 0;
10
-
11
- & &__headings {
12
- align-items: center;
13
- display: flex;
14
- justify-content: space-between;
15
- margin-bottom: 8px;
16
-
17
- h2,
18
- p {
19
- margin-bottom: 0;
20
- margin-top: 0;
21
- }
22
-
23
- p {
24
- margin-left: auto;
25
- }
26
- }
27
-
28
- &__container {
29
- background-color: wp-colors.$gray-100;
30
- border-radius: 4px;
31
- height: 8px;
32
- overflow: hidden;
33
- position: relative;
34
- z-index: 1;
35
- }
36
-
37
- &__bar {
38
- background-color: colors.$primary-500;
39
- height: 8px;
40
- transition: width 125ms ease-in-out;
41
- }
42
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var ReactRouterDOM = _interopRequireWildcard(require("react-router-dom"));
9
- /**
10
- * A proxy for react-router-dom.
11
- * Ensures that both components and the plugin use the same instance of
12
- * React Router, even if there are node_modules in components.
13
- */
14
- var _default = exports.default = ReactRouterDOM;