newspack-components 2.2.1 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/babel.config.js +25 -0
  2. package/copy-styles.js +2 -10
  3. package/dist/{cjs/accordion → accordion}/index.js +17 -13
  4. package/dist/{cjs/accordion → accordion}/style.scss +7 -3
  5. package/dist/{cjs/action-card → action-card}/index.js +39 -43
  6. package/dist/{esm/action-card → action-card}/style.scss +9 -9
  7. package/dist/{cjs/autocomplete-tokenfield → autocomplete-tokenfield}/index.js +67 -29
  8. package/dist/{esm/autocomplete-tokenfield → autocomplete-tokenfield}/style.scss +14 -8
  9. package/dist/{cjs/autocomplete-with-suggestions → autocomplete-with-suggestions}/index.js +61 -73
  10. package/dist/{esm/autocomplete-with-suggestions → autocomplete-with-suggestions}/style.scss +9 -17
  11. package/dist/button/index.js +51 -0
  12. package/{src/button/index.js → dist/button/index.tsx} +12 -5
  13. package/dist/{cjs/button → button}/style.scss +1 -1
  14. package/dist/{cjs/button-card → button-card}/index.js +9 -10
  15. package/dist/{cjs/button-card → button-card}/style.scss +19 -13
  16. package/dist/{cjs/card → card}/index.js +4 -5
  17. package/dist/{esm/card → card}/style.scss +1 -1
  18. package/dist/{cjs/category-autocomplete → category-autocomplete}/index.js +51 -53
  19. package/dist/{esm/category-autocomplete → category-autocomplete}/style.scss +2 -2
  20. package/dist/{cjs/color-picker → color-picker}/index.js +14 -16
  21. package/dist/{cjs/color-picker → color-picker}/style.scss +3 -3
  22. package/dist/consts.js +7 -0
  23. package/dist/{cjs/custom-select-control → custom-select-control}/index.js +4 -5
  24. package/dist/{cjs/custom-select-control → custom-select-control}/style.scss +11 -10
  25. package/dist/{cjs/date-range-picker → date-range-picker}/index.js +9 -11
  26. package/dist/{cjs/date-range-picker → date-range-picker}/style.scss +6 -6
  27. package/dist/{cjs/footer → footer}/index.js +33 -36
  28. package/dist/{cjs/footer → footer}/style.scss +1 -1
  29. package/dist/{cjs/form-token-field → form-token-field}/index.js +6 -7
  30. package/dist/{esm/form-token-field → form-token-field}/style.scss +1 -1
  31. package/dist/{cjs/global-notices → global-notices}/index.js +4 -5
  32. package/dist/grid/index.js +44 -0
  33. package/dist/grid/index.tsx +34 -0
  34. package/dist/{cjs/grid → grid}/style.scss +9 -9
  35. package/dist/{cjs/handoff → handoff}/index.js +73 -71
  36. package/dist/{cjs/handoff-message → handoff-message}/index.js +5 -3
  37. package/dist/hooks/index.js +29 -0
  38. package/{src/hooks/index.js → dist/hooks/index.ts} +1 -1
  39. package/dist/{cjs/hooks → hooks}/useObjectState.js +2 -3
  40. package/dist/{cjs/hooks → hooks}/useObjectState.test.js +9 -9
  41. package/dist/{cjs/hooks → hooks}/useOnClickOutside.js +1 -2
  42. package/dist/hooks/usePrompt.js +47 -0
  43. package/{src/hooks/usePrompt.js → dist/hooks/usePrompt.ts} +4 -8
  44. package/dist/image-upload/index.js +148 -0
  45. package/dist/{cjs/image-upload → image-upload}/index.test.js +13 -6
  46. package/dist/{esm/image-upload → image-upload}/style.scss +5 -5
  47. package/dist/{cjs/index.js → index.js} +1 -1
  48. package/dist/{cjs/info-button → info-button}/index.js +6 -7
  49. package/dist/{cjs/modal → modal}/index.js +4 -5
  50. package/dist/{esm/modal → modal}/style.scss +5 -5
  51. package/dist/{cjs/newspack-icon → newspack-icon}/index.js +5 -6
  52. package/dist/{cjs/newspack-icon → newspack-icon}/style.scss +1 -1
  53. package/dist/{cjs/newspack-logo → newspack-logo}/index.js +5 -6
  54. package/dist/{cjs/newspack-logo → newspack-logo}/style.scss +1 -1
  55. package/dist/{cjs/notice → notice}/index.js +12 -10
  56. package/dist/{cjs/notice → notice}/style.scss +11 -11
  57. package/dist/patrons-logo/index.js +77 -0
  58. package/dist/plugin-installer/index.js +297 -0
  59. package/dist/{cjs/plugin-installer → plugin-installer}/style.scss +1 -1
  60. package/dist/{cjs/plugin-settings → plugin-settings}/SettingsSection.js +13 -13
  61. package/dist/plugin-settings/index.js +228 -0
  62. package/dist/{cjs/plugin-settings → plugin-settings}/style.scss +1 -1
  63. package/dist/plugin-toggle/README.md +53 -0
  64. package/dist/plugin-toggle/index.js +222 -0
  65. package/dist/{esm/plugin-toggle → plugin-toggle}/style.scss +1 -1
  66. package/dist/{cjs/popover → popover}/index.js +4 -5
  67. package/dist/{cjs/popover → popover}/style.scss +7 -7
  68. package/dist/{cjs/position-control → position-control}/index.js +33 -32
  69. package/dist/{cjs/position-control → position-control}/style.scss +8 -8
  70. package/dist/{cjs/progress-bar → progress-bar}/index.js +9 -10
  71. package/dist/{cjs/progress-bar → progress-bar}/index.test.js +16 -16
  72. package/dist/{cjs/progress-bar → progress-bar}/style.scss +2 -2
  73. package/dist/proxied-imports/router.js +15 -0
  74. package/dist/{cjs/radio-control → radio-control}/index.js +4 -5
  75. package/dist/{cjs/radio-control → radio-control}/style.scss +3 -3
  76. package/dist/{cjs/section-header → section-header}/index.js +20 -21
  77. package/dist/{esm/section-header → section-header}/style.scss +5 -1
  78. package/dist/{cjs/select-control → select-control}/ButtonGroupControl.js +17 -19
  79. package/dist/{cjs/select-control → select-control}/GroupedSelectControl.js +32 -35
  80. package/dist/{cjs/select-control → select-control}/index.js +7 -8
  81. package/dist/{cjs/select-control → select-control}/style.scss +4 -4
  82. package/dist/settings/MinMaxSetting.js +60 -0
  83. package/dist/{cjs/settings → settings}/SettingsCard.js +14 -16
  84. package/dist/settings/SettingsSection.js +33 -0
  85. package/dist/{cjs/settings → settings}/index.js +3 -4
  86. package/dist/{cjs/settings → settings}/style.scss +15 -2
  87. package/dist/sortable-newsletter-list-control/index.js +135 -0
  88. package/dist/sortable-newsletter-list-control/style.scss +45 -0
  89. package/dist/{cjs/steps-list → steps-list}/index.js +5 -6
  90. package/dist/{esm/steps-list → steps-list}/style.scss +2 -2
  91. package/dist/{cjs/steps-list-item → steps-list-item}/index.js +6 -7
  92. package/dist/{cjs/steps-list-item → steps-list-item}/style.scss +5 -5
  93. package/dist/{cjs/style-card → style-card}/index.js +21 -19
  94. package/dist/{esm/style-card → style-card}/style.scss +4 -4
  95. package/dist/{esm/style.scss → style.scss} +14 -2
  96. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/index.js +16 -19
  97. package/dist/{cjs/tabbed-navigation → tabbed-navigation}/style.scss +4 -4
  98. package/dist/text-control/index.js +76 -0
  99. package/dist/text-control/index.tsx +71 -0
  100. package/dist/utils/index.js +36 -0
  101. package/dist/{cjs/waiting → waiting}/index.js +4 -5
  102. package/dist/web-preview/index.js +191 -0
  103. package/dist/{cjs/web-preview → web-preview}/style.scss +5 -5
  104. package/dist/with-wizard/index.js +328 -0
  105. package/dist/{esm/with-wizard → with-wizard}/style.scss +44 -22
  106. package/dist/{cjs/with-wizard-screen → with-wizard-screen}/index.js +40 -43
  107. package/dist/{esm/with-wizard-screen → with-wizard-screen}/style.scss +7 -7
  108. package/dist/{cjs/wizard → wizard}/components/WizardError.js +16 -17
  109. package/dist/{cjs/wizard → wizard}/index.js +44 -46
  110. package/dist/{cjs/wizard → wizard}/store/index.js +37 -38
  111. package/dist/{cjs/wizard → wizard}/store/utils.js +1 -4
  112. package/package.json +16 -14
  113. package/shared/scss/_mixins.scss +2 -2
  114. package/src/accordion/index.js +4 -1
  115. package/src/accordion/style.scss +7 -3
  116. package/src/action-card/style.scss +9 -9
  117. package/src/autocomplete-tokenfield/index.js +48 -15
  118. package/src/autocomplete-tokenfield/style.scss +14 -8
  119. package/src/autocomplete-with-suggestions/index.js +59 -62
  120. package/src/autocomplete-with-suggestions/style.scss +9 -17
  121. package/src/button/index.tsx +48 -0
  122. package/src/button/style.scss +1 -1
  123. package/src/button-card/style.scss +19 -13
  124. package/src/card/style.scss +1 -1
  125. package/src/category-autocomplete/style.scss +2 -2
  126. package/src/color-picker/style.scss +3 -3
  127. package/src/consts.js +0 -2
  128. package/src/custom-select-control/style.scss +11 -10
  129. package/src/date-range-picker/style.scss +6 -6
  130. package/src/footer/index.js +7 -7
  131. package/src/footer/style.scss +1 -1
  132. package/src/form-token-field/style.scss +1 -1
  133. package/src/grid/index.tsx +34 -0
  134. package/src/grid/style.scss +9 -9
  135. package/src/handoff/index.js +7 -6
  136. package/src/handoff-message/index.js +3 -1
  137. package/src/hooks/index.ts +15 -0
  138. package/src/hooks/usePrompt.ts +46 -0
  139. package/src/image-upload/index.js +5 -5
  140. package/src/image-upload/index.test.js +6 -1
  141. package/src/image-upload/style.scss +5 -5
  142. package/src/modal/style.scss +5 -5
  143. package/src/newspack-icon/style.scss +1 -1
  144. package/src/newspack-logo/style.scss +1 -1
  145. package/src/notice/index.js +1 -1
  146. package/src/notice/style.scss +11 -11
  147. package/src/patrons-logo/index.js +4 -1
  148. package/src/plugin-installer/index.js +7 -7
  149. package/src/plugin-installer/style.scss +1 -1
  150. package/src/plugin-settings/index.js +1 -1
  151. package/src/plugin-settings/style.scss +1 -1
  152. package/src/plugin-toggle/index.js +13 -12
  153. package/src/plugin-toggle/style.scss +1 -1
  154. package/src/popover/style.scss +7 -7
  155. package/src/position-control/index.js +63 -64
  156. package/src/position-control/style.scss +8 -8
  157. package/src/progress-bar/style.scss +2 -2
  158. package/src/radio-control/style.scss +3 -3
  159. package/src/section-header/index.js +3 -3
  160. package/src/section-header/style.scss +5 -1
  161. package/src/select-control/GroupedSelectControl.js +1 -1
  162. package/src/select-control/style.scss +4 -4
  163. package/src/settings/MinMaxSetting.js +8 -6
  164. package/src/settings/style.scss +15 -2
  165. package/src/sortable-newsletter-list-control/index.js +137 -0
  166. package/src/sortable-newsletter-list-control/style.scss +45 -0
  167. package/src/steps-list/style.scss +2 -2
  168. package/src/steps-list-item/style.scss +5 -5
  169. package/src/style-card/index.js +11 -5
  170. package/src/style-card/style.scss +4 -4
  171. package/src/style.scss +14 -2
  172. package/src/tabbed-navigation/style.scss +4 -4
  173. package/src/text-control/index.tsx +65 -0
  174. package/src/web-preview/index.js +6 -6
  175. package/src/web-preview/style.scss +5 -5
  176. package/src/with-wizard/index.js +4 -4
  177. package/src/with-wizard/style.scss +44 -22
  178. package/src/with-wizard-screen/index.js +1 -1
  179. package/src/with-wizard-screen/style.scss +7 -7
  180. package/src/wizard/components/WizardError.js +1 -1
  181. package/src/wizard/index.js +3 -3
  182. package/src/wizard/store/index.js +9 -2
  183. package/dist/cjs/action-card/style.scss +0 -483
  184. package/dist/cjs/autocomplete-tokenfield/style.scss +0 -43
  185. package/dist/cjs/autocomplete-with-suggestions/style.scss +0 -171
  186. package/dist/cjs/button/index.js +0 -57
  187. package/dist/cjs/card/style.scss +0 -168
  188. package/dist/cjs/category-autocomplete/style.scss +0 -34
  189. package/dist/cjs/consts.js +0 -12
  190. package/dist/cjs/form-token-field/style.scss +0 -37
  191. package/dist/cjs/grid/index.js +0 -54
  192. package/dist/cjs/hooks/index.js +0 -26
  193. package/dist/cjs/hooks/usePrompt.js +0 -52
  194. package/dist/cjs/image-upload/index.js +0 -144
  195. package/dist/cjs/image-upload/style.scss +0 -103
  196. package/dist/cjs/modal/style.scss +0 -56
  197. package/dist/cjs/patrons-logo/index.js +0 -82
  198. package/dist/cjs/plugin-installer/index.js +0 -299
  199. package/dist/cjs/plugin-settings/index.js +0 -222
  200. package/dist/cjs/plugin-toggle/index.js +0 -222
  201. package/dist/cjs/plugin-toggle/style.scss +0 -20
  202. package/dist/cjs/proxied-imports/router.js +0 -15
  203. package/dist/cjs/section-header/style.scss +0 -41
  204. package/dist/cjs/settings/MinMaxSetting.js +0 -57
  205. package/dist/cjs/settings/SettingsSection.js +0 -37
  206. package/dist/cjs/steps-list/style.scss +0 -11
  207. package/dist/cjs/style-card/style.scss +0 -94
  208. package/dist/cjs/style.scss +0 -43
  209. package/dist/cjs/text-control/index.js +0 -71
  210. package/dist/cjs/utils/index.js +0 -40
  211. package/dist/cjs/web-preview/index.js +0 -189
  212. package/dist/cjs/with-wizard/index.js +0 -318
  213. package/dist/cjs/with-wizard/style.scss +0 -260
  214. package/dist/cjs/with-wizard-screen/style.scss +0 -160
  215. package/dist/esm/accordion/index.js +0 -38
  216. package/dist/esm/accordion/style.scss +0 -27
  217. package/dist/esm/action-card/index.js +0 -222
  218. package/dist/esm/autocomplete-tokenfield/index.js +0 -223
  219. package/dist/esm/autocomplete-with-suggestions/index.js +0 -289
  220. package/dist/esm/button/index.js +0 -48
  221. package/dist/esm/button/style.scss +0 -11
  222. package/dist/esm/button-card/index.js +0 -65
  223. package/dist/esm/button-card/style.scss +0 -174
  224. package/dist/esm/card/index.js +0 -43
  225. package/dist/esm/category-autocomplete/index.js +0 -185
  226. package/dist/esm/color-picker/index.js +0 -61
  227. package/dist/esm/color-picker/style.scss +0 -37
  228. package/dist/esm/consts.js +0 -3
  229. package/dist/esm/custom-select-control/index.js +0 -37
  230. package/dist/esm/custom-select-control/style.scss +0 -92
  231. package/dist/esm/date-range-picker/index.js +0 -32
  232. package/dist/esm/date-range-picker/style.scss +0 -148
  233. package/dist/esm/footer/index.js +0 -105
  234. package/dist/esm/footer/style.scss +0 -82
  235. package/dist/esm/form-token-field/index.js +0 -50
  236. package/dist/esm/global-notices/index.js +0 -30
  237. package/dist/esm/grid/index.js +0 -45
  238. package/dist/esm/grid/style.scss +0 -166
  239. package/dist/esm/handoff/index.js +0 -177
  240. package/dist/esm/handoff-message/index.js +0 -45
  241. package/dist/esm/hooks/index.js +0 -17
  242. package/dist/esm/hooks/useObjectState.js +0 -31
  243. package/dist/esm/hooks/useObjectState.test.js +0 -83
  244. package/dist/esm/hooks/useOnClickOutside.js +0 -31
  245. package/dist/esm/hooks/usePrompt.js +0 -43
  246. package/dist/esm/image-upload/index.js +0 -141
  247. package/dist/esm/image-upload/index.test.js +0 -28
  248. package/dist/esm/index.js +0 -47
  249. package/dist/esm/info-button/index.js +0 -42
  250. package/dist/esm/info-button/style.scss +0 -18
  251. package/dist/esm/modal/index.js +0 -39
  252. package/dist/esm/newspack-icon/index.js +0 -50
  253. package/dist/esm/newspack-icon/style.scss +0 -26
  254. package/dist/esm/newspack-logo/index.js +0 -46
  255. package/dist/esm/newspack-logo/style.scss +0 -30
  256. package/dist/esm/notice/index.js +0 -67
  257. package/dist/esm/notice/style.scss +0 -111
  258. package/dist/esm/patrons-logo/index.js +0 -76
  259. package/dist/esm/plugin-installer/index.js +0 -295
  260. package/dist/esm/plugin-installer/style.scss +0 -72
  261. package/dist/esm/plugin-settings/SettingsSection.js +0 -136
  262. package/dist/esm/plugin-settings/index.js +0 -217
  263. package/dist/esm/plugin-settings/style.scss +0 -7
  264. package/dist/esm/plugin-toggle/index.js +0 -217
  265. package/dist/esm/popover/index.js +0 -41
  266. package/dist/esm/popover/style.scss +0 -161
  267. package/dist/esm/position-control/index.js +0 -109
  268. package/dist/esm/position-control/style.scss +0 -66
  269. package/dist/esm/progress-bar/index.js +0 -69
  270. package/dist/esm/progress-bar/index.test.js +0 -110
  271. package/dist/esm/progress-bar/style.scss +0 -42
  272. package/dist/esm/proxied-imports/router.js +0 -8
  273. package/dist/esm/radio-control/index.js +0 -37
  274. package/dist/esm/radio-control/style.scss +0 -92
  275. package/dist/esm/section-header/index.js +0 -68
  276. package/dist/esm/select-control/ButtonGroupControl.js +0 -54
  277. package/dist/esm/select-control/GroupedSelectControl.js +0 -84
  278. package/dist/esm/select-control/index.js +0 -51
  279. package/dist/esm/select-control/style.scss +0 -108
  280. package/dist/esm/settings/MinMaxSetting.js +0 -53
  281. package/dist/esm/settings/SettingsCard.js +0 -39
  282. package/dist/esm/settings/SettingsSection.js +0 -30
  283. package/dist/esm/settings/index.js +0 -9
  284. package/dist/esm/settings/style.scss +0 -106
  285. package/dist/esm/steps-list/index.js +0 -43
  286. package/dist/esm/steps-list-item/index.js +0 -48
  287. package/dist/esm/steps-list-item/style.scss +0 -47
  288. package/dist/esm/style-card/index.js +0 -76
  289. package/dist/esm/tabbed-navigation/index.js +0 -56
  290. package/dist/esm/tabbed-navigation/style.scss +0 -86
  291. package/dist/esm/text-control/index.js +0 -66
  292. package/dist/esm/text-control/style.scss +0 -32
  293. package/dist/esm/utils/index.js +0 -32
  294. package/dist/esm/waiting/index.js +0 -44
  295. package/dist/esm/waiting/style.scss +0 -27
  296. package/dist/esm/web-preview/index.js +0 -184
  297. package/dist/esm/web-preview/style.scss +0 -155
  298. package/dist/esm/with-wizard/index.js +0 -313
  299. package/dist/esm/with-wizard-screen/index.js +0 -116
  300. package/dist/esm/wizard/components/WizardError.js +0 -69
  301. package/dist/esm/wizard/index.js +0 -126
  302. package/dist/esm/wizard/store/index.js +0 -155
  303. package/dist/esm/wizard/store/utils.js +0 -17
  304. package/src/grid/index.js +0 -44
  305. package/src/text-control/index.js +0 -56
  306. /package/dist/{cjs/info-button → info-button}/style.scss +0 -0
  307. /package/dist/{cjs/text-control → text-control}/style.scss +0 -0
  308. /package/dist/{cjs/waiting → waiting}/style.scss +0 -0
@@ -1,177 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /**
3
- * Handoff
4
- */
5
-
6
- /**
7
- * WordPress dependencies.
8
- */
9
- import apiFetch from '@wordpress/api-fetch';
10
- import { Component, Fragment } from '@wordpress/element';
11
- import { __ as alias__ } from '@wordpress/i18n';
12
-
13
- /**
14
- * Internal dependencies.
15
- */
16
- const __ = alias__;
17
- import { Button, Card, Modal, Waiting } from '../';
18
-
19
- /**
20
- * External dependencies.
21
- */
22
- import assign from 'lodash/assign';
23
- import classnames from 'classnames';
24
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
25
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
26
- class Handoff extends Component {
27
- constructor() {
28
- super(...arguments);
29
- _defineProperty(this, "componentDidMount", () => {
30
- this._isMounted = true;
31
- const {
32
- plugin
33
- } = this.props;
34
- this.retrievePluginInfo(plugin);
35
- });
36
- _defineProperty(this, "componentWillUnmount", () => {
37
- this._isMounted = false;
38
- });
39
- _defineProperty(this, "retrievePluginInfo", plugin => {
40
- const {
41
- onReady
42
- } = this.props;
43
- apiFetch({
44
- path: '/newspack/v1/plugins/' + plugin
45
- }).then(pluginInfo => {
46
- if (this._isMounted) {
47
- onReady(pluginInfo);
48
- this.setState({
49
- pluginInfo
50
- });
51
- }
52
- });
53
- });
54
- _defineProperty(this, "textForPlugin", pluginInfo => {
55
- const defaults = {
56
- modalBody: null,
57
- modalTitle: pluginInfo.Name && `${__('Manage', 'newspack')} ${pluginInfo.Name}`,
58
- primaryButton: pluginInfo.Name && `${__('Manage', 'newspack')} ${pluginInfo.Name}`,
59
- primaryModalButton: __('Manage', 'newspack'),
60
- dismissModalButton: __('Dismiss', 'newspack')
61
- };
62
- return assign(defaults, this.props);
63
- });
64
- _defineProperty(this, "goToPlugin", plugin => {
65
- const {
66
- editLink,
67
- showOnBlockEditor
68
- } = this.props;
69
- apiFetch({
70
- path: '/newspack/v1/plugins/' + plugin + '/handoff',
71
- method: 'POST',
72
- data: {
73
- editLink,
74
- handoffReturnUrl: window && window.location.href,
75
- showOnBlockEditor: showOnBlockEditor ? true : false
76
- }
77
- }).then(response => {
78
- window.location.href = response.HandoffLink;
79
- });
80
- });
81
- this.state = {
82
- pluginInfo: [],
83
- showModal: false
84
- };
85
- }
86
- /**
87
- * Render.
88
- */
89
- render() {
90
- const {
91
- className,
92
- children,
93
- compact,
94
- useModal,
95
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
96
- modalTitle: _modalTitle,
97
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
98
- modalBody: _modalBody,
99
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
100
- onReady,
101
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
102
- editLink,
103
- ...otherProps
104
- } = this.props;
105
- const {
106
- pluginInfo,
107
- showModal
108
- } = this.state;
109
- const {
110
- modalBody,
111
- modalTitle,
112
- primaryButton,
113
- primaryModalButton,
114
- dismissModalButton
115
- } = this.textForPlugin(pluginInfo);
116
- const {
117
- Configured,
118
- Name,
119
- Slug,
120
- Status
121
- } = pluginInfo;
122
- const classes = classnames(Configured && 'is-configured', className);
123
- return _jsxs(Fragment, {
124
- children: [Name && 'active' === Status && _jsx(Button, {
125
- className: classes,
126
- isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
127
- ...otherProps,
128
- onClick: () => useModal ? this.setState({
129
- showModal: true
130
- }) : this.goToPlugin(Slug),
131
- children: children ? children : primaryButton
132
- }), Name && 'active' !== Status && _jsx(Button, {
133
- className: classes,
134
- variant: "secondary",
135
- disabled: true,
136
- ...otherProps,
137
- children: Name + __(' not installed', 'newspack')
138
- }), !Name && _jsx(Button, {
139
- className: classes,
140
- isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
141
- ...otherProps,
142
- children: _jsxs(Fragment, {
143
- children: [!compact && _jsx(Waiting, {
144
- isLeft: true
145
- }), __('Retrieving Plugin Info', 'newspack')]
146
- })
147
- }), showModal && _jsxs(Modal, {
148
- title: modalTitle,
149
- onRequestClose: () => this.setState({
150
- showModal: false
151
- }),
152
- children: [_jsx("p", {
153
- children: modalBody
154
- }), _jsxs(Card, {
155
- buttonsCard: true,
156
- noBorder: true,
157
- className: "justify-end",
158
- children: [_jsx(Button, {
159
- variant: "secondary",
160
- onClick: () => this.setState({
161
- showModal: false
162
- }),
163
- children: dismissModalButton
164
- }), _jsx(Button, {
165
- variant: "primary",
166
- onClick: () => this.goToPlugin(Slug),
167
- children: primaryModalButton
168
- })]
169
- })]
170
- })]
171
- });
172
- }
173
- }
174
- Handoff.defaultProps = {
175
- onReady: () => {}
176
- };
177
- export default Handoff;
@@ -1,45 +0,0 @@
1
- /**
2
- * WordPress dependencies.
3
- */
4
- import { useEffect, useState } from '@wordpress/element';
5
-
6
- /**
7
- * Internal dependencies.
8
- */
9
- import { HANDOFF_KEY } from '../consts';
10
- import { Notice } from '../';
11
-
12
- /**
13
- * Handoff Message Component.
14
- */
15
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
16
- export default function HandoffMessage() {
17
- const [handoffMessage, setHandoffMessage] = useState(false);
18
- useEffect(() => {
19
- // Slight delay to allow for localStorage to be updated by RAS component.
20
- setTimeout(() => {
21
- const handoff = JSON.parse(localStorage.getItem(HANDOFF_KEY));
22
- if (handoff?.message) {
23
- setHandoffMessage(handoff.message);
24
- } else {
25
- setHandoffMessage(false);
26
- }
27
-
28
- // Clean up the notification if navigating away from the relevant page.
29
- if (handoff?.url && -1 === window.location.href.indexOf(handoff.url)) {
30
- window.localStorage.removeItem(HANDOFF_KEY);
31
- setHandoffMessage(false);
32
- }
33
- }, 100);
34
-
35
- // Clean up the notification when unmounting.
36
- return () => window.localStorage.removeItem(HANDOFF_KEY);
37
- }, []);
38
- if (!handoffMessage) return null;
39
- return _jsx(Notice, {
40
- isHandoff: true,
41
- isDismissible: false,
42
- rawHTML: true,
43
- noticeText: handoffMessage
44
- });
45
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useRef } from '@wordpress/element';
5
- import usePrompt from './usePrompt';
6
- import useObjectState from './useObjectState';
7
- import useOnClickOutside from './useOnClickOutside';
8
- const useUniqueId = prefix => {
9
- const id = useRef(`${prefix}-${Math.round(Math.random() * 99999)}`);
10
- return id.current;
11
- };
12
- export default {
13
- usePrompt,
14
- useObjectState,
15
- useOnClickOutside,
16
- useUniqueId
17
- };
@@ -1,31 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useState } from '@wordpress/element';
5
- import isArray from 'lodash/isArray';
6
- import mergeWith from 'lodash/mergeWith';
7
- const mergeCustomizer = (objValue, srcValue) => {
8
- if (isArray(objValue)) {
9
- // If it's an array, replace it (instead of concatenating).
10
- return srcValue;
11
- }
12
- };
13
-
14
- /**
15
- * A useState for an object.
16
- * Nested objects will be nested, but arrays replaced.
17
- */
18
- export default (function () {
19
- let initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
- const [stateObject, setStateObject] = useState(initial);
21
- const runUpdate = update => setStateObject(_stateObject => mergeWith({}, _stateObject, update, mergeCustomizer));
22
- const updateStateObject = keyOrUpdate => {
23
- if (typeof keyOrUpdate === 'string') {
24
- return value => runUpdate({
25
- [keyOrUpdate]: value
26
- });
27
- }
28
- runUpdate(keyOrUpdate);
29
- };
30
- return [stateObject, updateStateObject];
31
- });
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import useObjectState from './useObjectState';
4
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
5
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
6
- const INIT_STATE = {
7
- name: 'Foo',
8
- widgets: [1],
9
- attributes: {
10
- bar: 0,
11
- baz: 1
12
- }
13
- };
14
- const TestComponent = () => {
15
- const [state, updateState] = useObjectState(INIT_STATE);
16
- return _jsxs("div", {
17
- children: [_jsx("input", {
18
- placeholder: "state",
19
- onChange: () => {},
20
- value: JSON.stringify(state)
21
- }), _jsx("button", {
22
- onClick: () => updateState({
23
- widgets: []
24
- }),
25
- children: "Remove widgets"
26
- }), _jsx("button", {
27
- onClick: () => updateState({
28
- widgets: [1]
29
- }),
30
- children: "Add widget"
31
- }), _jsx("button", {
32
- onClick: () => updateState({
33
- attributes: {
34
- bar: 2
35
- }
36
- }),
37
- children: "Nested update"
38
- }), _jsx("input", {
39
- type: "text",
40
- value: state.name,
41
- onChange: e => updateState({
42
- name: e.target.value
43
- }),
44
- placeholder: "name"
45
- })]
46
- });
47
- };
48
- describe('useObjectState', () => {
49
- const getState = () => JSON.parse(screen.getByPlaceholderText('state').getAttribute('value'));
50
- beforeEach(() => {
51
- render(_jsx(TestComponent, {}));
52
- });
53
- it('updates arrays', () => {
54
- expect(getState()).toStrictEqual(INIT_STATE);
55
- screen.getByText('Remove widgets').click();
56
- expect(getState()).toMatchObject({
57
- widgets: []
58
- });
59
- screen.getByText('Add widget').click();
60
- expect(getState()).toMatchObject({
61
- widgets: [1]
62
- });
63
- });
64
- it('updates a simple value', () => {
65
- fireEvent.change(screen.getByPlaceholderText('name'), {
66
- target: {
67
- value: 'Ramon'
68
- }
69
- });
70
- expect(getState()).toMatchObject({
71
- name: 'Ramon'
72
- });
73
- });
74
- it('updates a nested object', () => {
75
- screen.getByText('Nested update').click();
76
- expect(getState()).toMatchObject({
77
- attributes: {
78
- bar: 2,
79
- baz: 1
80
- }
81
- });
82
- });
83
- });
@@ -1,31 +0,0 @@
1
- // https://usehooks.com/useOnClickOutside/
2
-
3
- /**
4
- * External dependencies.
5
- */
6
- import { useEffect } from '@wordpress/element';
7
- const useOnClickOutside = (ref, handler) => {
8
- useEffect(() => {
9
- const listener = event => {
10
- // Do nothing if clicking ref's element or descendent elements
11
- if (!ref.current || ref.current.contains(event.target)) {
12
- return;
13
- }
14
- handler(event);
15
- };
16
- document.addEventListener('mousedown', listener);
17
- document.addEventListener('touchstart', listener);
18
- return () => {
19
- document.removeEventListener('mousedown', listener);
20
- document.removeEventListener('touchstart', listener);
21
- };
22
- },
23
- // Add ref and handler to effect dependencies
24
- // It's worth noting that because passed in handler is a new ...
25
- // ... function on every render that will cause this effect ...
26
- // ... callback/cleanup to run every render. It's not a big deal ...
27
- // ... but to optimize you can wrap handler in useCallback before ...
28
- // ... passing it into this hook.
29
- [ref, handler]);
30
- };
31
- export default useOnClickOutside;
@@ -1,43 +0,0 @@
1
- // https://gist.github.com/sibelius/60a4e11da1f826b8d60dc3975a1ac805
2
-
3
- /**
4
- * External dependencies.
5
- */
6
- import { useEffect, useRef } from '@wordpress/element';
7
-
8
- /**
9
- * Internal dependencies.
10
- */
11
- import Router from '../proxied-imports/router';
12
- const {
13
- useHistory
14
- } = Router;
15
- export default ((when, message) => {
16
- const history = useHistory();
17
- const self = useRef(null);
18
- const onWindowOrTabClose = event => {
19
- if (!when) {
20
- return;
21
- }
22
- if (typeof event === 'undefined') {
23
- event = window.event;
24
- }
25
- if (event) {
26
- event.returnValue = message;
27
- }
28
- return message;
29
- };
30
- useEffect(() => {
31
- if (when) {
32
- self.current = history.block(message);
33
- window.addEventListener('beforeunload', onWindowOrTabClose);
34
- }
35
- return () => {
36
- if (self.current) {
37
- self.current();
38
- }
39
- window.removeEventListener('beforeunload', onWindowOrTabClose);
40
- };
41
- }, [message, when]);
42
- return self.current;
43
- });
@@ -1,141 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /**
3
- * Image Upload
4
- */
5
-
6
- /**
7
- * WordPress dependencies.
8
- */
9
- import { Component } from '@wordpress/element';
10
- import { __ as alias__ } from '@wordpress/i18n';
11
-
12
- /**
13
- * Internal dependencies.
14
- */
15
- const __ = alias__;
16
- import { Button, InfoButton } from '../';
17
- import './style.scss';
18
-
19
- /**
20
- * External dependencies.
21
- */
22
- import classnames from 'classnames';
23
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
24
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
25
- import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
26
- class ImageUpload extends Component {
27
- /**
28
- * Constructor.
29
- */
30
- constructor() {
31
- super(...arguments);
32
- /**
33
- * Open the WP media modal.
34
- */
35
- _defineProperty(this, "openModal", () => {
36
- if (this.state.frame) {
37
- this.state.frame.open();
38
- return;
39
- }
40
- this.setState({
41
- frame: wp.media({
42
- title: __('Select or upload image'),
43
- button: {
44
- text: __('Select')
45
- },
46
- library: {
47
- type: 'image'
48
- },
49
- multiple: false
50
- })
51
- }, () => {
52
- this.state.frame.on('select', this.handleImageSelect);
53
- this.state.frame.open();
54
- });
55
- });
56
- /**
57
- * Update the state when an image is selected from the media modal.
58
- */
59
- _defineProperty(this, "handleImageSelect", () => {
60
- const {
61
- onChange
62
- } = this.props;
63
- const attachment = this.state.frame.state().get('selection').first().toJSON();
64
- onChange(attachment);
65
- });
66
- /**
67
- * Render.
68
- */
69
- _defineProperty(this, "render", () => {
70
- const {
71
- buttonLabel,
72
- className,
73
- disabled,
74
- help,
75
- image,
76
- info,
77
- isCovering,
78
- label,
79
- onChange,
80
- style = {}
81
- } = this.props;
82
- const classes = classnames('newspack-image-upload__image', {
83
- 'newspack-image-upload__image--has-image': image
84
- }, {
85
- 'newspack-image-upload__image--covering': isCovering
86
- });
87
- return _jsxs("div", {
88
- className: classnames('newspack-image-upload', className),
89
- children: [_jsxs("div", {
90
- className: "newspack-image-upload__header",
91
- children: [label && _jsx("label", {
92
- className: "newspack-image-upload__label",
93
- children: label
94
- }), info && _jsx(InfoButton, {
95
- text: info
96
- })]
97
- }), _jsx("div", {
98
- className: classes,
99
- style: {
100
- ...style
101
- },
102
- children: image?.url ? _jsxs(_Fragment, {
103
- children: [_jsx("img", {
104
- "data-testid": "image-upload",
105
- src: image.url,
106
- alt: __('Image preview', 'newspack')
107
- }), _jsxs("div", {
108
- className: "newspack-image-upload__controls",
109
- children: [_jsx(Button, {
110
- disabled: disabled,
111
- onClick: this.openModal,
112
- isLink: true,
113
- children: __('Replace', 'newspack')
114
- }), _jsx("span", {
115
- className: "sep"
116
- }), _jsx(Button, {
117
- disabled: disabled,
118
- onClick: () => onChange(null),
119
- isLink: true,
120
- isDestructive: true,
121
- children: __('Remove', 'newspack')
122
- })]
123
- })]
124
- }) : _jsx(Button, {
125
- disabled: disabled,
126
- onClick: this.openModal,
127
- isLink: true,
128
- children: buttonLabel ? buttonLabel : __('Upload', 'newspack')
129
- })
130
- }), help && _jsx("p", {
131
- className: "newspack-image-upload__help",
132
- children: help
133
- })]
134
- });
135
- });
136
- this.state = {
137
- frame: false
138
- };
139
- }
140
- }
141
- export default ImageUpload;
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import ImageUpload from './';
4
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
5
- describe('ImageUpload', () => {
6
- it('should render an add image button', () => {
7
- const {
8
- getByText
9
- } = render(_jsx(ImageUpload, {}));
10
- expect(getByText('Upload')).toBeInTheDocument();
11
- });
12
- it('should render replace and remove buttons if there is an image provided', () => {
13
- const image = {
14
- id: 1234,
15
- url: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg'
16
- };
17
- const {
18
- getByText,
19
- getByTestId
20
- } = render(_jsx(ImageUpload, {
21
- image: image
22
- }));
23
- expect(getByText('Remove')).toBeInTheDocument();
24
- expect(getByText('Replace')).toBeInTheDocument();
25
- expect(getByTestId('image-upload')).toBeInTheDocument();
26
- expect(getByTestId('image-upload').getAttribute('src')).toEqual(image.url);
27
- });
28
- });
package/dist/esm/index.js DELETED
@@ -1,47 +0,0 @@
1
- export { default as Accordion } from './accordion';
2
- export { default as ActionCard } from './action-card';
3
- export { default as AutocompleteTokenField } from './autocomplete-tokenfield';
4
- export { default as AutocompleteWithSuggestions } from './autocomplete-with-suggestions';
5
- export { default as Button } from './button';
6
- export { default as ButtonCard } from './button-card';
7
- export { default as Card } from './card';
8
- export { default as CategoryAutocomplete } from './category-autocomplete';
9
- export { default as ColorPicker } from './color-picker';
10
- export { default as CustomSelectControl } from './custom-select-control';
11
- export { default as FormTokenField } from './form-token-field';
12
- export { default as Footer } from './footer';
13
- export { default as Handoff } from './handoff';
14
- export { default as HandoffMessage } from './handoff-message';
15
- export { default as InfoButton } from './info-button';
16
- export { default as ImageUpload } from './image-upload';
17
- export { default as GlobalNotices } from './global-notices';
18
- export { default as Grid } from './grid';
19
- export { default as Modal } from './modal';
20
- export { default as NewspackIcon } from './newspack-icon';
21
- export { default as NewspackLogo } from './newspack-logo';
22
- export { default as Notice } from './notice';
23
- export { default as PatronsLogo } from './patrons-logo';
24
- export { default as PluginInstaller } from './plugin-installer';
25
- export { default as PluginSettings } from './plugin-settings';
26
- export { default as PluginToggle } from './plugin-toggle';
27
- export { default as Popover } from './popover';
28
- export { default as ProgressBar } from './progress-bar';
29
- export { default as RadioControl } from './radio-control';
30
- export { default as SectionHeader } from './section-header';
31
- export { default as SelectControl } from './select-control';
32
- export { default as DateRangePicker } from './date-range-picker';
33
- export { default as Settings } from './settings';
34
- export { default as StepsList } from './steps-list';
35
- export { default as StepsListItem } from './steps-list-item';
36
- export { default as StyleCard } from './style-card';
37
- export { default as TabbedNavigation } from './tabbed-navigation';
38
- export { default as TextControl } from './text-control';
39
- export { default as Waiting } from './waiting';
40
- export { default as WebPreview } from './web-preview';
41
- export { default as Wizard } from './wizard';
42
- export { default as withWizard } from './with-wizard';
43
- export { default as withWizardScreen } from './with-wizard-screen';
44
- export { default as Router } from './proxied-imports/router';
45
- export { default as hooks } from './hooks';
46
- export { default as utils } from './utils';
47
- import './style.scss';
@@ -1,42 +0,0 @@
1
- /**
2
- * Info Button
3
- */
4
-
5
- /**
6
- * WordPress dependencies.
7
- */
8
- import { Component } from '@wordpress/element';
9
- import { Tooltip } from '@wordpress/components';
10
- import { Icon, info } from '@wordpress/icons';
11
-
12
- /**
13
- * External dependencies.
14
- */
15
- import classnames from 'classnames';
16
-
17
- /**
18
- * Internal dependencies.
19
- */
20
- import './style.scss';
21
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
22
- class InfoButton extends Component {
23
- /**
24
- * Render.
25
- */
26
- render() {
27
- const {
28
- className,
29
- ...otherProps
30
- } = this.props;
31
- return _jsx(Tooltip, {
32
- ...otherProps,
33
- children: _jsx("span", {
34
- className: classnames('newspack-info-button', className),
35
- children: _jsx(Icon, {
36
- icon: info
37
- })
38
- })
39
- });
40
- }
41
- }
42
- export default InfoButton;