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,82 +0,0 @@
1
- /**
2
- * Footer
3
- */
4
-
5
- @use '~@wordpress/base-styles/colors' as wp-colors;
6
-
7
- .newspack-footer {
8
- align-items: stretch;
9
- background: white;
10
- border: 0 solid wp-colors.$gray-300;
11
- border-width: 1px 0;
12
- bottom: 0;
13
- color: wp-colors.$gray-700;
14
- display: flex;
15
- flex-wrap: wrap;
16
- font-size: 12px;
17
- justify-content: space-between;
18
- left: 0;
19
- line-height: 16px;
20
- position: absolute;
21
- right: 0;
22
-
23
- @media screen and ( min-width: 783px ) {
24
- bottom: 40px;
25
- flex-wrap: nowrap;
26
- }
27
-
28
- &__inner {
29
- align-items: center;
30
- display: flex;
31
- flex: 0 0 100%;
32
-
33
- @media screen and ( min-width: 783px ) {
34
- flex: 1 1 auto;
35
- }
36
- }
37
-
38
- ul {
39
- display: flex;
40
- flex-wrap: wrap;
41
- margin: 0;
42
- padding: 7px 8px;
43
- }
44
-
45
- li {
46
- margin: 8px;
47
-
48
- a {
49
- align-items: flex-end;
50
- color: inherit;
51
- display: flex;
52
-
53
- &:active,
54
- &:focus,
55
- &:hover {
56
- color: wp-colors.$gray-900;
57
- }
58
- }
59
- }
60
-
61
- &__logo {
62
- align-items: center;
63
- background: wp-colors.$gray-900;
64
- display: flex;
65
- margin: 0 0 -1px;
66
- padding: 16px;
67
- width: 100%;
68
-
69
- @media screen and ( min-width: 783px ) {
70
- margin: -1px 0 -1px 8px;
71
- max-width: 33.33%;
72
- width: auto;
73
- }
74
-
75
- .patrons-logo {
76
- display: block;
77
- fill: white;
78
- max-height: 16px;
79
- width: auto;
80
- }
81
- }
82
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * Form Token Field
3
- */
4
-
5
- /**
6
- * WordPress dependencies.
7
- */
8
- import { FormTokenField as BaseComponent } from '@wordpress/components';
9
- import { Component } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies.
13
- */
14
- import './style.scss';
15
-
16
- /**
17
- * External dependencies.
18
- */
19
- import classnames from 'classnames';
20
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
21
- class FormTokenField extends Component {
22
- /**
23
- * Render.
24
- */
25
- render() {
26
- const {
27
- className,
28
- description,
29
- hideHelpFromVision,
30
- hideLabelFromVision,
31
- ...otherProps
32
- } = this.props;
33
- const classes = classnames('newspack-form-token-field__input-container', className);
34
- return _jsxs("div", {
35
- className: classnames({
36
- 'newspack-form-token-field--label-hidden': hideLabelFromVision,
37
- 'newspack-form-token-field--help-hidden': hideHelpFromVision
38
- }, 'newspack-form-token-field'),
39
- children: [_jsx(BaseComponent, {
40
- className: classes,
41
- ...otherProps
42
- }), description && _jsx("p", {
43
- className: "newspack-form-token-field__help",
44
- children: description
45
- })]
46
- });
47
- }
48
- }
49
- export default FormTokenField;
@@ -1,30 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { parse } from 'qs';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { Notice } from '../';
10
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
11
- const GlobalNotices = () => {
12
- const notice = parse(window.location.search)['newspack-notice'];
13
- if (!notice) {
14
- return null;
15
- }
16
- return notice.split(',').map((text, i) => {
17
- if (text.indexOf('_error_') === 0) {
18
- return _jsx(Notice, {
19
- isError: true,
20
- noticeText: text.replace('_error_', ''),
21
- rawHTML: true
22
- }, i);
23
- }
24
- return _jsx(Notice, {
25
- isSuccess: true,
26
- noticeText: text
27
- }, i);
28
- });
29
- };
30
- export default GlobalNotices;
@@ -1,29 +0,0 @@
1
- /**
2
- * Grid
3
- */
4
-
5
- /**
6
- * Internal dependencies
7
- */
8
- import './style.scss';
9
-
10
- /**
11
- * External dependencies
12
- */
13
- import classnames from 'classnames';
14
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
15
- const Grid = ({
16
- className = '',
17
- columns = 2,
18
- gutter = 32,
19
- noMargin = false,
20
- rowGap = 0,
21
- ...otherProps
22
- }) => {
23
- const classes = classnames('newspack-grid', noMargin && 'newspack-grid--no-margin', columns && 'newspack-grid__columns-' + columns, gutter && 'newspack-grid__gutter-' + gutter, rowGap && 'newspack-grid__row-gap-' + rowGap, className);
24
- return _jsx("div", {
25
- className: classes,
26
- ...otherProps
27
- });
28
- };
29
- export default Grid;
@@ -1,176 +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, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
25
- class Handoff extends Component {
26
- constructor() {
27
- super(...arguments);
28
- _defineProperty(this, "componentDidMount", () => {
29
- this._isMounted = true;
30
- const {
31
- plugin
32
- } = this.props;
33
- this.retrievePluginInfo(plugin);
34
- });
35
- _defineProperty(this, "componentWillUnmount", () => {
36
- this._isMounted = false;
37
- });
38
- _defineProperty(this, "retrievePluginInfo", plugin => {
39
- const {
40
- onReady
41
- } = this.props;
42
- apiFetch({
43
- path: '/newspack/v1/plugins/' + plugin
44
- }).then(pluginInfo => {
45
- if (this._isMounted) {
46
- onReady(pluginInfo);
47
- this.setState({
48
- pluginInfo
49
- });
50
- }
51
- });
52
- });
53
- _defineProperty(this, "textForPlugin", pluginInfo => {
54
- const defaults = {
55
- modalBody: null,
56
- modalTitle: pluginInfo.Name && `${__('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
57
- primaryButton: pluginInfo.Name && `${__('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
58
- primaryModalButton: __('Manage', 'newspack-plugin'),
59
- dismissModalButton: __('Dismiss', 'newspack-plugin')
60
- };
61
- return assign(defaults, this.props);
62
- });
63
- _defineProperty(this, "goToPlugin", plugin => {
64
- const {
65
- editLink,
66
- showOnBlockEditor
67
- } = this.props;
68
- apiFetch({
69
- path: '/newspack/v1/plugins/' + plugin + '/handoff',
70
- method: 'POST',
71
- data: {
72
- editLink,
73
- handoffReturnUrl: window && window.location.href,
74
- showOnBlockEditor: showOnBlockEditor ? true : false
75
- }
76
- }).then(response => {
77
- window.location.href = response.HandoffLink;
78
- });
79
- });
80
- this.state = {
81
- pluginInfo: [],
82
- showModal: false
83
- };
84
- }
85
- /**
86
- * Render.
87
- */
88
- render() {
89
- const {
90
- className,
91
- children,
92
- compact,
93
- useModal,
94
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
95
- modalTitle: _modalTitle,
96
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
97
- modalBody: _modalBody,
98
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
99
- onReady,
100
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
101
- editLink,
102
- ...otherProps
103
- } = this.props;
104
- const {
105
- pluginInfo,
106
- showModal
107
- } = this.state;
108
- const {
109
- modalBody,
110
- modalTitle,
111
- primaryButton,
112
- primaryModalButton,
113
- dismissModalButton
114
- } = this.textForPlugin(pluginInfo);
115
- const {
116
- Configured,
117
- Name,
118
- Slug,
119
- Status
120
- } = pluginInfo;
121
- const classes = classnames(Configured && 'is-configured', className);
122
- return _jsxs(Fragment, {
123
- children: [Name && 'active' === Status && _jsx(Button, {
124
- className: classes,
125
- isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
126
- ...otherProps,
127
- onClick: () => useModal ? this.setState({
128
- showModal: true
129
- }) : this.goToPlugin(Slug),
130
- children: children ? children : primaryButton
131
- }), Name && 'active' !== Status && _jsx(Button, {
132
- className: classes,
133
- variant: "secondary",
134
- disabled: true,
135
- ...otherProps,
136
- children: Name + __(' not installed', 'newspack-plugin')
137
- }), !Name && _jsx(Button, {
138
- className: classes,
139
- isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
140
- ...otherProps,
141
- children: _jsxs(Fragment, {
142
- children: [!compact && _jsx(Waiting, {
143
- isLeft: true
144
- }), __('Retrieving Plugin Info', 'newspack-plugin')]
145
- })
146
- }), showModal && _jsxs(Modal, {
147
- title: modalTitle,
148
- onRequestClose: () => this.setState({
149
- showModal: false
150
- }),
151
- children: [_jsx("p", {
152
- children: modalBody
153
- }), _jsxs(Card, {
154
- buttonsCard: true,
155
- noBorder: true,
156
- className: "justify-end",
157
- children: [_jsx(Button, {
158
- variant: "secondary",
159
- onClick: () => this.setState({
160
- showModal: false
161
- }),
162
- children: dismissModalButton
163
- }), _jsx(Button, {
164
- variant: "primary",
165
- onClick: () => this.goToPlugin(Slug),
166
- children: primaryModalButton
167
- })]
168
- })]
169
- })]
170
- });
171
- }
172
- }
173
- Handoff.defaultProps = {
174
- onReady: () => {}
175
- };
176
- 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,30 +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 ((initial = {}) => {
19
- const [stateObject, setStateObject] = useState(initial);
20
- const runUpdate = update => setStateObject(_stateObject => mergeWith({}, _stateObject, update, mergeCustomizer));
21
- const updateStateObject = keyOrUpdate => {
22
- if (typeof keyOrUpdate === 'string') {
23
- return value => runUpdate({
24
- [keyOrUpdate]: value
25
- });
26
- }
27
- runUpdate(keyOrUpdate);
28
- };
29
- return [stateObject, updateStateObject];
30
- });
@@ -1,82 +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, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
5
- const INIT_STATE = {
6
- name: 'Foo',
7
- widgets: [1],
8
- attributes: {
9
- bar: 0,
10
- baz: 1
11
- }
12
- };
13
- const TestComponent = () => {
14
- const [state, updateState] = useObjectState(INIT_STATE);
15
- return _jsxs("div", {
16
- children: [_jsx("input", {
17
- placeholder: "state",
18
- onChange: () => {},
19
- value: JSON.stringify(state)
20
- }), _jsx("button", {
21
- onClick: () => updateState({
22
- widgets: []
23
- }),
24
- children: "Remove widgets"
25
- }), _jsx("button", {
26
- onClick: () => updateState({
27
- widgets: [1]
28
- }),
29
- children: "Add widget"
30
- }), _jsx("button", {
31
- onClick: () => updateState({
32
- attributes: {
33
- bar: 2
34
- }
35
- }),
36
- children: "Nested update"
37
- }), _jsx("input", {
38
- type: "text",
39
- value: state.name,
40
- onChange: e => updateState({
41
- name: e.target.value
42
- }),
43
- placeholder: "name"
44
- })]
45
- });
46
- };
47
- describe('useObjectState', () => {
48
- const getState = () => JSON.parse(screen.getByPlaceholderText('state').getAttribute('value'));
49
- beforeEach(() => {
50
- render(_jsx(TestComponent, {}));
51
- });
52
- it('updates arrays', () => {
53
- expect(getState()).toStrictEqual(INIT_STATE);
54
- screen.getByText('Remove widgets').click();
55
- expect(getState()).toMatchObject({
56
- widgets: []
57
- });
58
- screen.getByText('Add widget').click();
59
- expect(getState()).toMatchObject({
60
- widgets: [1]
61
- });
62
- });
63
- it('updates a simple value', () => {
64
- fireEvent.change(screen.getByPlaceholderText('name'), {
65
- target: {
66
- value: 'Ramon'
67
- }
68
- });
69
- expect(getState()).toMatchObject({
70
- name: 'Ramon'
71
- });
72
- });
73
- it('updates a nested object', () => {
74
- screen.getByText('Nested update').click();
75
- expect(getState()).toMatchObject({
76
- attributes: {
77
- bar: 2,
78
- baz: 1
79
- }
80
- });
81
- });
82
- });
@@ -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,40 +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
- return message;
26
- };
27
- useEffect(() => {
28
- if (when) {
29
- self.current = history.block(message);
30
- window.addEventListener('beforeunload', onWindowOrTabClose);
31
- }
32
- return () => {
33
- if (self.current) {
34
- self.current();
35
- }
36
- window.removeEventListener('beforeunload', onWindowOrTabClose);
37
- };
38
- }, [message, when]);
39
- return self.current || (() => {});
40
- });