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,91 +1,94 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
8
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
10
9
  var _element = require("@wordpress/element");
11
10
  var _i18n = require("@wordpress/i18n");
12
11
  var _ = require("../");
13
12
  var _assign = _interopRequireDefault(require("lodash/assign"));
14
13
  var _classnames = _interopRequireDefault(require("classnames"));
15
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
14
+ var _jsxRuntime = require("react/jsx-runtime");
16
15
  /**
17
16
  * Handoff
18
17
  */
18
+
19
19
  /**
20
20
  * WordPress dependencies.
21
21
  */
22
+
22
23
  /**
23
24
  * Internal dependencies.
24
25
  */
25
- const __ = _i18n.__;
26
+
26
27
  /**
27
28
  * External dependencies.
28
29
  */
30
+
29
31
  class Handoff extends _element.Component {
30
32
  constructor() {
31
33
  super(...arguments);
32
- (0, _defineProperty2.default)(this, "componentDidMount", () => {
33
- this._isMounted = true;
34
- const {
35
- plugin
36
- } = this.props;
37
- this.retrievePluginInfo(plugin);
38
- });
39
- (0, _defineProperty2.default)(this, "componentWillUnmount", () => {
40
- this._isMounted = false;
41
- });
42
- (0, _defineProperty2.default)(this, "retrievePluginInfo", plugin => {
43
- const {
44
- onReady
45
- } = this.props;
46
- (0, _apiFetch.default)({
47
- path: '/newspack/v1/plugins/' + plugin
48
- }).then(pluginInfo => {
49
- if (this._isMounted) {
50
- onReady(pluginInfo);
51
- this.setState({
52
- pluginInfo
53
- });
54
- }
55
- });
56
- });
57
- (0, _defineProperty2.default)(this, "textForPlugin", pluginInfo => {
58
- const defaults = {
59
- modalBody: null,
60
- modalTitle: pluginInfo.Name && `${__('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
61
- primaryButton: pluginInfo.Name && `${__('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
62
- primaryModalButton: __('Manage', 'newspack-plugin'),
63
- dismissModalButton: __('Dismiss', 'newspack-plugin')
64
- };
65
- return (0, _assign.default)(defaults, this.props);
66
- });
67
- (0, _defineProperty2.default)(this, "goToPlugin", plugin => {
68
- const {
69
- editLink,
70
- showOnBlockEditor
71
- } = this.props;
72
- (0, _apiFetch.default)({
73
- path: '/newspack/v1/plugins/' + plugin + '/handoff',
74
- method: 'POST',
75
- data: {
76
- editLink,
77
- handoffReturnUrl: window && window.location.href,
78
- showOnBlockEditor: showOnBlockEditor ? true : false
79
- }
80
- }).then(response => {
81
- window.location.href = response.HandoffLink;
82
- });
83
- });
84
34
  this.state = {
85
35
  pluginInfo: [],
86
36
  showModal: false
87
37
  };
88
38
  }
39
+ componentDidMount = () => {
40
+ this._isMounted = true;
41
+ const {
42
+ plugin
43
+ } = this.props;
44
+ this.retrievePluginInfo(plugin);
45
+ };
46
+ componentWillUnmount = () => {
47
+ this._isMounted = false;
48
+ };
49
+ retrievePluginInfo = plugin => {
50
+ const {
51
+ onReady
52
+ } = this.props;
53
+ (0, _apiFetch.default)({
54
+ path: '/newspack/v1/plugins/' + plugin
55
+ }).then(pluginInfo => {
56
+ if (this._isMounted) {
57
+ onReady(pluginInfo);
58
+ this.setState({
59
+ pluginInfo
60
+ });
61
+ }
62
+ });
63
+ };
64
+ textForPlugin = pluginInfo => {
65
+ const defaults = {
66
+ modalBody: null,
67
+ modalTitle: pluginInfo.Name && `${(0, _i18n.__)('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
68
+ primaryButton: pluginInfo.Name && `${(0, _i18n.__)('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
69
+ primaryModalButton: (0, _i18n.__)('Manage', 'newspack-plugin'),
70
+ dismissModalButton: (0, _i18n.__)('Dismiss', 'newspack-plugin')
71
+ };
72
+ return (0, _assign.default)(defaults, this.props);
73
+ };
74
+ goToPlugin = plugin => {
75
+ const {
76
+ editLink,
77
+ showOnBlockEditor
78
+ } = this.props;
79
+ (0, _apiFetch.default)({
80
+ path: '/newspack/v1/plugins/' + plugin + '/handoff',
81
+ method: 'POST',
82
+ data: {
83
+ editLink,
84
+ handoffReturnUrl: window && window.location.href,
85
+ showOnBlockEditor: showOnBlockEditor ? true : false
86
+ }
87
+ }).then(response => {
88
+ window.location.href = response.HandoffLink;
89
+ });
90
+ };
91
+
89
92
  /**
90
93
  * Render.
91
94
  */
@@ -123,8 +126,8 @@ class Handoff extends _element.Component {
123
126
  Status
124
127
  } = pluginInfo;
125
128
  const classes = (0, _classnames.default)(Configured && 'is-configured', className);
126
- return (0, _jsxRuntime.jsxs)(_element.Fragment, {
127
- children: [Name && 'active' === Status && (0, _jsxRuntime.jsx)(_.Button, {
129
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
130
+ children: [Name && 'active' === Status && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
128
131
  className: classes,
129
132
  isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
130
133
  ...otherProps,
@@ -132,39 +135,39 @@ class Handoff extends _element.Component {
132
135
  showModal: true
133
136
  }) : this.goToPlugin(Slug),
134
137
  children: children ? children : primaryButton
135
- }), Name && 'active' !== Status && (0, _jsxRuntime.jsx)(_.Button, {
138
+ }), Name && 'active' !== Status && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
136
139
  className: classes,
137
140
  variant: "secondary",
138
141
  disabled: true,
139
142
  ...otherProps,
140
- children: Name + __(' not installed', 'newspack-plugin')
141
- }), !Name && (0, _jsxRuntime.jsx)(_.Button, {
143
+ children: Name + (0, _i18n.__)(' not installed', 'newspack-plugin')
144
+ }), !Name && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
142
145
  className: classes,
143
146
  isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
144
147
  ...otherProps,
145
- children: (0, _jsxRuntime.jsxs)(_element.Fragment, {
146
- children: [!compact && (0, _jsxRuntime.jsx)(_.Waiting, {
148
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
149
+ children: [!compact && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Waiting, {
147
150
  isLeft: true
148
- }), __('Retrieving Plugin Info', 'newspack-plugin')]
151
+ }), (0, _i18n.__)('Retrieving Plugin Info', 'newspack-plugin')]
149
152
  })
150
- }), showModal && (0, _jsxRuntime.jsxs)(_.Modal, {
153
+ }), showModal && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Modal, {
151
154
  title: modalTitle,
152
155
  onRequestClose: () => this.setState({
153
156
  showModal: false
154
157
  }),
155
- children: [(0, _jsxRuntime.jsx)("p", {
158
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
156
159
  children: modalBody
157
- }), (0, _jsxRuntime.jsxs)(_.Card, {
160
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Card, {
158
161
  buttonsCard: true,
159
162
  noBorder: true,
160
163
  className: "justify-end",
161
- children: [(0, _jsxRuntime.jsx)(_.Button, {
164
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
162
165
  variant: "secondary",
163
166
  onClick: () => this.setState({
164
167
  showModal: false
165
168
  }),
166
169
  children: dismissModalButton
167
- }), (0, _jsxRuntime.jsx)(_.Button, {
170
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
168
171
  variant: "primary",
169
172
  onClick: () => this.goToPlugin(Slug),
170
173
  children: primaryModalButton
@@ -7,7 +7,7 @@ exports.default = HandoffMessage;
7
7
  var _element = require("@wordpress/element");
8
8
  var _consts = require("../consts");
9
9
  var _ = require("../");
10
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
11
  /**
12
12
  * WordPress dependencies.
13
13
  */
@@ -40,8 +40,10 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
40
40
  // Clean up the notification when unmounting.
41
41
  return () => window.localStorage.removeItem(_consts.HANDOFF_KEY);
42
42
  }, []);
43
- if (!handoffMessage) return null;
44
- return (0, _jsxRuntime.jsx)(_.Notice, {
43
+ if (!handoffMessage) {
44
+ return null;
45
+ }
46
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
45
47
  isHandoff: true,
46
48
  isDismissible: false,
47
49
  rawHTML: true,
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var _interopRequireDefault = require( '@babel/runtime/helpers/interopRequireDefault' );
4
+ Object.defineProperty( exports, '__esModule', {
5
+ value: true,
6
+ } );
7
+ exports.default = void 0;
8
+ var _element = require( '@wordpress/element' );
9
+ var _usePrompt = _interopRequireDefault( require( './usePrompt' ) );
10
+ var _useObjectState = _interopRequireDefault( require( './useObjectState' ) );
11
+ var _useOnClickOutside = _interopRequireDefault(
12
+ require( './useOnClickOutside' )
13
+ );
14
+ /**
15
+ * WordPress dependencies
16
+ */
17
+
18
+ const useUniqueId = ( prefix ) => {
19
+ const id = ( 0, _element.useRef )(
20
+ `${ prefix }-${ Math.round( Math.random() * 99999 ) }`
21
+ );
22
+ return id.current;
23
+ };
24
+ var _default = ( exports.default = {
25
+ usePrompt: _usePrompt.default,
26
+ useObjectState: _useObjectState.default,
27
+ useOnClickOutside: _useOnClickOutside.default,
28
+ useUniqueId,
29
+ } );
@@ -0,0 +1,15 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useRef } from '@wordpress/element';
5
+
6
+ import usePrompt from './usePrompt';
7
+ import useObjectState from './useObjectState';
8
+ import useOnClickOutside from './useOnClickOutside';
9
+
10
+ const useUniqueId = ( prefix: string ) => {
11
+ const id = useRef( `${ prefix }-${ Math.round( Math.random() * 99999 ) }` );
12
+ return id.current;
13
+ };
14
+
15
+ export default { usePrompt, useObjectState, useOnClickOutside, useUniqueId };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  var _react = _interopRequireDefault(require("react"));
5
5
  var _react2 = require("@testing-library/react");
6
6
  var _useObjectState = _interopRequireDefault(require("./useObjectState"));
7
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
8
  const INIT_STATE = {
9
9
  name: 'Foo',
10
10
  widgets: [1],
@@ -15,29 +15,29 @@ const INIT_STATE = {
15
15
  };
16
16
  const TestComponent = () => {
17
17
  const [state, updateState] = (0, _useObjectState.default)(INIT_STATE);
18
- return (0, _jsxRuntime.jsxs)("div", {
19
- children: [(0, _jsxRuntime.jsx)("input", {
18
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
19
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
20
20
  placeholder: "state",
21
21
  onChange: () => {},
22
22
  value: JSON.stringify(state)
23
- }), (0, _jsxRuntime.jsx)("button", {
23
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
24
24
  onClick: () => updateState({
25
25
  widgets: []
26
26
  }),
27
27
  children: "Remove widgets"
28
- }), (0, _jsxRuntime.jsx)("button", {
28
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
29
29
  onClick: () => updateState({
30
30
  widgets: [1]
31
31
  }),
32
32
  children: "Add widget"
33
- }), (0, _jsxRuntime.jsx)("button", {
33
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
34
34
  onClick: () => updateState({
35
35
  attributes: {
36
36
  bar: 2
37
37
  }
38
38
  }),
39
39
  children: "Nested update"
40
- }), (0, _jsxRuntime.jsx)("input", {
40
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
41
41
  type: "text",
42
42
  value: state.name,
43
43
  onChange: e => updateState({
@@ -50,7 +50,7 @@ const TestComponent = () => {
50
50
  describe('useObjectState', () => {
51
51
  const getState = () => JSON.parse(_react2.screen.getByPlaceholderText('state').getAttribute('value'));
52
52
  beforeEach(() => {
53
- (0, _react2.render)((0, _jsxRuntime.jsx)(TestComponent, {}));
53
+ (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {}));
54
54
  });
55
55
  it('updates arrays', () => {
56
56
  expect(getState()).toStrictEqual(INIT_STATE);
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var _interopRequireDefault = require( '@babel/runtime/helpers/interopRequireDefault' );
4
+ Object.defineProperty( exports, '__esModule', {
5
+ value: true,
6
+ } );
7
+ exports.default = void 0;
8
+ var _element = require( '@wordpress/element' );
9
+ var _router = _interopRequireDefault( require( '../proxied-imports/router' ) );
10
+ // https://gist.github.com/sibelius/60a4e11da1f826b8d60dc3975a1ac805
11
+
12
+ /**
13
+ * External dependencies.
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies.
18
+ */
19
+
20
+ const { useHistory } = _router.default;
21
+ var _default = ( when, message ) => {
22
+ const history = useHistory();
23
+ const self = ( 0, _element.useRef )( null );
24
+ const onWindowOrTabClose = ( event ) => {
25
+ if ( ! when ) {
26
+ return;
27
+ }
28
+ if ( typeof event === 'undefined' ) {
29
+ event = window.event;
30
+ }
31
+ return message;
32
+ };
33
+ ( 0, _element.useEffect )( () => {
34
+ if ( when ) {
35
+ self.current = history.block( message );
36
+ window.addEventListener( 'beforeunload', onWindowOrTabClose );
37
+ }
38
+ return () => {
39
+ if ( self.current ) {
40
+ self.current();
41
+ }
42
+ window.removeEventListener( 'beforeunload', onWindowOrTabClose );
43
+ };
44
+ }, [ message, when ] );
45
+ return self.current || ( () => {} );
46
+ };
47
+ exports.default = _default;
@@ -0,0 +1,46 @@
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
+
13
+ const { useHistory } = Router;
14
+
15
+ export default ( when: boolean, message: string ): ( () => void ) => {
16
+ const history = useHistory();
17
+ const self = useRef( null );
18
+
19
+ const onWindowOrTabClose = ( event: Event | undefined ) => {
20
+ if ( ! when ) {
21
+ return;
22
+ }
23
+
24
+ if ( typeof event === 'undefined' ) {
25
+ event = window.event;
26
+ }
27
+
28
+ return message;
29
+ };
30
+
31
+ useEffect( () => {
32
+ if ( when ) {
33
+ self.current = history.block( message );
34
+ window.addEventListener( 'beforeunload', onWindowOrTabClose );
35
+ }
36
+
37
+ return () => {
38
+ if ( self.current ) {
39
+ ( self.current as () => void )();
40
+ }
41
+ window.removeEventListener( 'beforeunload', onWindowOrTabClose );
42
+ };
43
+ }, [ message, when ] );
44
+
45
+ return self.current || ( () => {} );
46
+ };
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _element = require("@wordpress/element");
9
+ var _i18n = require("@wordpress/i18n");
10
+ var _ = require("../");
11
+ require("./style.scss");
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ /**
15
+ * Image Upload
16
+ */
17
+
18
+ /**
19
+ * WordPress dependencies.
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies.
24
+ */
25
+
26
+ /**
27
+ * External dependencies.
28
+ */
29
+
30
+ class ImageUpload extends _element.Component {
31
+ /**
32
+ * Constructor.
33
+ */
34
+ constructor() {
35
+ super(...arguments);
36
+ this.state = {
37
+ frame: false
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Open the WP media modal.
43
+ */
44
+ openModal = () => {
45
+ if (this.state.frame) {
46
+ this.state.frame.open();
47
+ return;
48
+ }
49
+ this.setState({
50
+ frame: wp.media({
51
+ title: (0, _i18n.__)('Select or upload image'),
52
+ button: {
53
+ text: (0, _i18n.__)('Select')
54
+ },
55
+ library: {
56
+ type: 'image'
57
+ },
58
+ multiple: false
59
+ })
60
+ }, () => {
61
+ this.state.frame.on('select', this.handleImageSelect);
62
+ this.state.frame.open();
63
+ });
64
+ };
65
+
66
+ /**
67
+ * Update the state when an image is selected from the media modal.
68
+ */
69
+ handleImageSelect = () => {
70
+ const {
71
+ onChange
72
+ } = this.props;
73
+ const attachment = this.state.frame.state().get('selection').first().toJSON();
74
+ onChange(attachment);
75
+ };
76
+
77
+ /**
78
+ * Render.
79
+ */
80
+ render = () => {
81
+ const {
82
+ buttonLabel,
83
+ className,
84
+ disabled,
85
+ help,
86
+ image,
87
+ info,
88
+ isCovering,
89
+ label,
90
+ onChange,
91
+ style = {}
92
+ } = this.props;
93
+ const classes = (0, _classnames.default)('newspack-image-upload__image', {
94
+ 'newspack-image-upload__image--has-image': image
95
+ }, {
96
+ 'newspack-image-upload__image--covering': isCovering
97
+ });
98
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
99
+ className: (0, _classnames.default)('newspack-image-upload', className),
100
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
101
+ className: "newspack-image-upload__header",
102
+ children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
103
+ className: "newspack-image-upload__label",
104
+ children: label
105
+ }), info && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.InfoButton, {
106
+ text: info
107
+ })]
108
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
109
+ className: classes,
110
+ style: {
111
+ ...style
112
+ },
113
+ children: image?.url ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
114
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
115
+ "data-testid": "image-upload",
116
+ src: image.url,
117
+ alt: (0, _i18n.__)('Image preview', 'newspack-plugin')
118
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
119
+ className: "newspack-image-upload__controls",
120
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
121
+ disabled: disabled,
122
+ onClick: this.openModal,
123
+ isLink: true,
124
+ children: (0, _i18n.__)('Replace', 'newspack-plugin')
125
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
126
+ className: "sep"
127
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
128
+ disabled: disabled,
129
+ onClick: () => onChange(null),
130
+ isLink: true,
131
+ isDestructive: true,
132
+ children: (0, _i18n.__)('Remove', 'newspack-plugin')
133
+ })]
134
+ })]
135
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
136
+ disabled: disabled,
137
+ onClick: this.openModal,
138
+ isLink: true,
139
+ children: buttonLabel ? buttonLabel : (0, _i18n.__)('Upload', 'newspack-plugin')
140
+ })
141
+ }), help && /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
142
+ className: "newspack-image-upload__help",
143
+ children: help
144
+ })]
145
+ });
146
+ };
147
+ }
148
+ var _default = exports.default = ImageUpload;
@@ -1,15 +1,22 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = _interopRequireDefault(require("react"));
5
- var _react2 = require("@testing-library/react");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _react = require("@testing-library/react");
6
5
  var _ = _interopRequireDefault(require("./"));
7
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /**
8
+ * External dependencies
9
+ */
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+
8
15
  describe('ImageUpload', () => {
9
16
  it('should render an add image button', () => {
10
17
  const {
11
18
  getByText
12
- } = (0, _react2.render)((0, _jsxRuntime.jsx)(_.default, {}));
19
+ } = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {}));
13
20
  expect(getByText('Upload')).toBeInTheDocument();
14
21
  });
15
22
  it('should render replace and remove buttons if there is an image provided', () => {
@@ -20,7 +27,7 @@ describe('ImageUpload', () => {
20
27
  const {
21
28
  getByText,
22
29
  getByTestId
23
- } = (0, _react2.render)((0, _jsxRuntime.jsx)(_.default, {
30
+ } = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
24
31
  image: image
25
32
  }));
26
33
  expect(getByText('Remove')).toBeInTheDocument();
@@ -2,7 +2,7 @@
2
2
  * Image Upload
3
3
  */
4
4
 
5
- @use '~@wordpress/base-styles/colors' as wp-colors;
5
+ @use "~@wordpress/base-styles/colors" as wp-colors;
6
6
 
7
7
  .newspack-image-upload {
8
8
  margin: 32px 0;
@@ -27,7 +27,7 @@
27
27
  &--covering {
28
28
  background-size: cover;
29
29
  }
30
- &:not( &--has-image ) {
30
+ &:not(&--has-image) {
31
31
  .newspack-button {
32
32
  background: white !important;
33
33
  border-radius: 2px !important;
@@ -49,9 +49,9 @@
49
49
  overflow: hidden;
50
50
  &::before,
51
51
  &::after {
52
- border: 1px solid rgba( black, 0.54 );
52
+ border: 1px solid rgba(black, 0.54);
53
53
  border-radius: 2px;
54
- content: '';
54
+ content: "";
55
55
  inset: 0;
56
56
  position: absolute;
57
57
  z-index: 0;
@@ -66,7 +66,7 @@
66
66
  position: relative;
67
67
  }
68
68
  &::after {
69
- background: rgba( white, 0.9 );
69
+ background: rgba(white, 0.9);
70
70
  border-color: wp-colors.$gray-700;
71
71
  }
72
72
  &:focus-within,