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
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _keycodes = require("@wordpress/keycodes");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ /**
10
+ * WordPress dependencies.
11
+ */
12
+
13
+ const InteractiveDiv = ({
14
+ style = {},
15
+ ...props
16
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
17
+ tabIndex: "0",
18
+ role: "button",
19
+ onKeyDown: event => _keycodes.ENTER === event.keyCode && props.onClick(),
20
+ style: {
21
+ cursor: 'pointer',
22
+ ...style
23
+ },
24
+ ...props
25
+ });
26
+ const confirmAction = message => {
27
+ // eslint-disable-next-line no-alert
28
+ if (confirm(message)) {
29
+ return true;
30
+ }
31
+ return false;
32
+ };
33
+ var _default = exports.default = {
34
+ InteractiveDiv,
35
+ confirmAction
36
+ };
@@ -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
  });
@@ -9,7 +9,7 @@ var _element = require("@wordpress/element");
9
9
  var _components = require("@wordpress/components");
10
10
  require("./style.scss");
11
11
  var _classnames = _interopRequireDefault(require("classnames"));
12
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
13
  /**
14
14
  * Waiting
15
15
  */
@@ -43,11 +43,10 @@ class Waiting extends _element.Component {
43
43
  'is-left': isLeft,
44
44
  'is-center': isCenter
45
45
  });
46
- return (0, _jsxRuntime.jsx)(_components.Spinner, {
46
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Spinner, {
47
47
  className: classes,
48
48
  ...otherProps
49
49
  });
50
50
  }
51
51
  }
52
- var _default = Waiting;
53
- exports.default = _default;
52
+ var _default = exports.default = Waiting;
@@ -0,0 +1,191 @@
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 _icons = require("@wordpress/icons");
11
+ var _components = require("@wordpress/components");
12
+ var _ = require("../");
13
+ require("./style.scss");
14
+ var _classnames = _interopRequireDefault(require("classnames"));
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ /**
17
+ * WordPress dependencies.
18
+ */
19
+
20
+ /**
21
+ * Internal dependencies.
22
+ */
23
+
24
+ /**
25
+ * External dependencies.
26
+ */
27
+
28
+ const PORTAL_PARENT_ID = 'newspack-components-web-preview-wrapper';
29
+
30
+ /**
31
+ * Web Preview. A component to preview a website in an iframe, with device sizing options.
32
+ */
33
+ class WebPreview extends _element.Component {
34
+ state = {
35
+ device: 'desktop',
36
+ loaded: false,
37
+ isPreviewVisible: false
38
+ };
39
+ constructor(props) {
40
+ super(props);
41
+ this.iframeRef = (0, _element.createRef)();
42
+ }
43
+
44
+ /**
45
+ * If a div with id PORTAL_PARENT_ID exists, assign it to class field.
46
+ * If not, create it and append to the body.
47
+ */
48
+ componentDidMount() {
49
+ const existingDOMElement = document.getElementById(PORTAL_PARENT_ID);
50
+ this.modalDOMElement = existingDOMElement || document.createElement('div');
51
+ if (!existingDOMElement) {
52
+ this.modalDOMElement.id = PORTAL_PARENT_ID;
53
+ document.body.appendChild(this.modalDOMElement);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Add or remove applicable body classes
59
+ */
60
+ componentDidUpdate() {
61
+ if (this.state.isPreviewVisible === true) {
62
+ document.body.classList.add('newspack-web-preview--open');
63
+ } else {
64
+ document.body.classList.remove('newspack-web-preview--open');
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Create JSX for the modal
70
+ */
71
+ getWebPreviewModal = () => {
72
+ const {
73
+ beforeLoad = () => {},
74
+ onClose = () => {},
75
+ url
76
+ } = this.props;
77
+ const {
78
+ device,
79
+ loaded,
80
+ isPreviewVisible
81
+ } = this.state;
82
+ if (!this.modalDOMElement || !isPreviewVisible) {
83
+ return null;
84
+ }
85
+ const classes = (0, _classnames.default)('newspack-web-preview', device, loaded && 'is-loaded');
86
+ beforeLoad();
87
+ return (0, _element.createPortal)( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
88
+ className: classes,
89
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
90
+ className: "newspack-web-preview__interior",
91
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
92
+ className: "newspack-web-preview__toolbar",
93
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
94
+ className: "newspack-web-preview__toolbar-left",
95
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.ButtonGroup, {
96
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
97
+ onClick: () => this.setState({
98
+ device: 'desktop'
99
+ }),
100
+ variant: 'desktop' === device && 'primary',
101
+ icon: _icons.desktop,
102
+ label: (0, _i18n.__)('Preview Desktop Size', 'newspack-plugin')
103
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
104
+ onClick: () => this.setState({
105
+ device: 'tablet'
106
+ }),
107
+ variant: 'tablet' === device && 'primary',
108
+ icon: _icons.tablet,
109
+ label: (0, _i18n.__)('Preview Tablet Size', 'newspack-plugin')
110
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
111
+ onClick: () => this.setState({
112
+ device: 'phone'
113
+ }),
114
+ variant: 'phone' === device && 'primary',
115
+ icon: _icons.mobile,
116
+ label: (0, _i18n.__)('Preview Phone Size', 'newspack-plugin')
117
+ })]
118
+ })
119
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
120
+ className: "newspack-web-preview__toolbar-right",
121
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
122
+ onClick: () => {
123
+ onClose();
124
+ this.setState({
125
+ isPreviewVisible: false,
126
+ loaded: false
127
+ });
128
+ },
129
+ icon: _icons.closeSmall,
130
+ label: (0, _i18n.__)('Close Preview', 'newspack-plugin')
131
+ })
132
+ })]
133
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
134
+ className: "newspack-web-preview__content",
135
+ children: [!loaded && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
136
+ className: "newspack-web-preview__is-waiting",
137
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Waiting, {
138
+ isLeft: true
139
+ }), (0, _i18n.__)('Loading…', 'newspack-plugin')]
140
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", {
141
+ ref: this.iframeRef,
142
+ title: "web-preview",
143
+ src: url,
144
+ onLoad: () => {
145
+ this.setState({
146
+ loaded: true
147
+ });
148
+ this.props.onLoad(this.iframeRef.current);
149
+ }
150
+ })]
151
+ })]
152
+ })
153
+ }), this.modalDOMElement);
154
+ };
155
+ showPreview = () => {
156
+ this.setState({
157
+ isPreviewVisible: true
158
+ });
159
+ };
160
+
161
+ /**
162
+ * Render.
163
+ */
164
+ render() {
165
+ const {
166
+ label,
167
+ variant,
168
+ /**
169
+ * Inversion of control - let the caller render
170
+ * the button that will trigger the modal
171
+ */
172
+ renderButton
173
+ } = this.props;
174
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
175
+ children: [renderButton ? renderButton({
176
+ showPreview: this.showPreview
177
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
178
+ variant: variant,
179
+ onClick: this.showPreview,
180
+ tabIndex: "0",
181
+ children: label
182
+ }), this.getWebPreviewModal()]
183
+ });
184
+ }
185
+ }
186
+ WebPreview.defaultProps = {
187
+ url: '//newspack.com',
188
+ label: (0, _i18n.__)('Preview', 'newspack-plugin'),
189
+ onLoad: () => {}
190
+ };
191
+ var _default = exports.default = WebPreview;
@@ -2,8 +2,8 @@
2
2
  * Web Preview
3
3
  */
4
4
 
5
- @use '../../../shared/scss/colors';
6
- @use '~@wordpress/base-styles/colors' as wp-colors;
5
+ @use "../../../shared/scss/colors";
6
+ @use "~@wordpress/base-styles/colors" as wp-colors;
7
7
 
8
8
  .newspack-web-preview {
9
9
  // Color
@@ -14,7 +14,7 @@
14
14
  --wp-admin-theme-color-darker-20: #{colors.$primary-700};
15
15
  --wp-admin-theme-color-darker-20--rgb: #{colors.$primary-700--rgb};
16
16
 
17
- background: rgba( black, 0.7 );
17
+ background: rgba(black, 0.7);
18
18
  box-sizing: border-box;
19
19
  height: 100%;
20
20
  left: 0;
@@ -54,7 +54,7 @@
54
54
 
55
55
  &__content {
56
56
  background: wp-colors.$gray-100;
57
- height: calc( 100% - 49px );
57
+ height: calc(100% - 49px);
58
58
  -webkit-overflow-scrolling: touch;
59
59
  overflow-x: hidden;
60
60
  width: 100%;
@@ -81,7 +81,7 @@
81
81
  margin: -12px 0 0;
82
82
  position: absolute;
83
83
  top: 50%;
84
- transform: translateX( -50% );
84
+ transform: translateX(-50%);
85
85
  }
86
86
 
87
87
  &__toolbar {
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = withWizard;
8
+ var _element = require("@wordpress/element");
9
+ var _i18n = require("@wordpress/i18n");
10
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
11
+ var _icons = require("@wordpress/icons");
12
+ var _ = require("../");
13
+ var _router = _interopRequireDefault(require("../proxied-imports/router"));
14
+ var _footer = _interopRequireDefault(require("../footer"));
15
+ require("./style.scss");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ /**
18
+ * WordPress dependencies.
19
+ */
20
+
21
+ /**
22
+ * Internal dependencies.
23
+ */
24
+
25
+ const {
26
+ Redirect,
27
+ Route
28
+ } = _router.default;
29
+
30
+ /**
31
+ * Higher-Order Component to provide plugin management and error handling to Newspack Wizards.
32
+ */
33
+ function withWizard(WrappedComponent, requiredPlugins) {
34
+ return class WrappedWithWizard extends _element.Component {
35
+ constructor(props) {
36
+ super(props);
37
+ this.state = {
38
+ complete: null,
39
+ error: null,
40
+ loading: requiredPlugins && requiredPlugins.length > 0 ? 1 : 0,
41
+ quietLoading: false
42
+ };
43
+ this.wrappedComponentRef = (0, _element.createRef)();
44
+ }
45
+ componentDidMount = () => {
46
+ // If there are no requiredPlugins, fire onWizardReady as soon as component mounts.
47
+ if (!requiredPlugins) {
48
+ const instance = this.wrappedComponentRef.current;
49
+ // eslint-disable-next-line no-unused-expressions
50
+ instance && instance.onWizardReady && instance.onWizardReady();
51
+ }
52
+ };
53
+
54
+ /**
55
+ * Set the error. Called by Wizards when an error occurs.
56
+ *
57
+ * @return {Promise} Resolved after state update
58
+ */
59
+ setError = error => {
60
+ return new Promise(resolve => {
61
+ this.setState({
62
+ error: error || null
63
+ }, () => resolve());
64
+ });
65
+ };
66
+
67
+ /**
68
+ * Render any errors that need rendering.
69
+ *
70
+ * @return {Component} Error UI
71
+ */
72
+ getError = () => {
73
+ const {
74
+ error
75
+ } = this.state;
76
+ if (!error) {
77
+ return null;
78
+ }
79
+ const parsedError = this.parseError(error);
80
+ const {
81
+ level
82
+ } = parsedError;
83
+ if ('fatal' === level) {
84
+ return this.getFatalError(parsedError);
85
+ }
86
+ return this.getErrorNotice(parsedError);
87
+ };
88
+
89
+ /**
90
+ * Get a notice-level error.
91
+ *
92
+ * @param {Error} error object already parsed by parseError
93
+ * @return {Component} Error notice
94
+ */
95
+ getErrorNotice = error => {
96
+ const {
97
+ message
98
+ } = error;
99
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
100
+ isError: true,
101
+ className: "newspack-wizard__above-header",
102
+ noticeText: message,
103
+ rawHTML: true
104
+ });
105
+ };
106
+
107
+ /**
108
+ * Get a fatal-level error.
109
+ *
110
+ * @param {Error} error object already parsed by parseError
111
+ * @return {Component} React object
112
+ */
113
+ getFatalError = error => {
114
+ const fallbackURL = this.getFallbackURL();
115
+ if (!fallbackURL) {
116
+ return null;
117
+ }
118
+ const {
119
+ message
120
+ } = error;
121
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Modal, {
122
+ title: (0, _i18n.__)('Unrecoverable error'),
123
+ onRequestClose: () => window.location = fallbackURL,
124
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
125
+ noticeText: message,
126
+ isError: true,
127
+ rawHTML: true
128
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Card, {
129
+ buttonsCard: true,
130
+ noBorder: true,
131
+ className: "justify-end",
132
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
133
+ isPrimary: true,
134
+ href: fallbackURL,
135
+ children: (0, _i18n.__)('Return to Dashboard', 'newspack-plugin')
136
+ })
137
+ })]
138
+ });
139
+ };
140
+
141
+ /**
142
+ * Get all the relevant info out of a raw API error response.
143
+ *
144
+ * @param {Object} error error object
145
+ * @return {Object} Error object with relevant fields and defaults
146
+ */
147
+ parseError = error => {
148
+ const {
149
+ data,
150
+ message,
151
+ code
152
+ } = error;
153
+ let level = 'fatal';
154
+ if (!!data && 'level' in data) {
155
+ level = data.level;
156
+ } else if ('rest_invalid_param' === code) {
157
+ level = 'notice';
158
+ }
159
+ return {
160
+ message,
161
+ level
162
+ };
163
+ };
164
+
165
+ /**
166
+ * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
167
+ */
168
+ pluginInstallationStatus = ({
169
+ complete
170
+ }) => {
171
+ if (this.state.loading) {
172
+ this.doneLoading();
173
+ }
174
+ const instance = this.wrappedComponentRef.current;
175
+ this.setState({
176
+ complete
177
+ }, () => {
178
+ // eslint-disable-next-line no-unused-expressions
179
+ complete && instance && instance.onWizardReady && instance.onWizardReady();
180
+ });
181
+ };
182
+
183
+ /**
184
+ * Begin loading.
185
+ */
186
+ startLoading = quiet => {
187
+ if (quiet) {
188
+ this.setState(state => ({
189
+ quietLoading: state.quietLoading + 1
190
+ }));
191
+ } else {
192
+ this.setState(state => ({
193
+ loading: state.loading + 1
194
+ }));
195
+ }
196
+ };
197
+
198
+ /**
199
+ * End loading.
200
+ */
201
+ doneLoading = quiet => {
202
+ if (quiet) {
203
+ this.setState(state => ({
204
+ quietLoading: state.quietLoading - 1
205
+ }));
206
+ } else {
207
+ this.setState(state => ({
208
+ loading: state.loading - 1
209
+ }));
210
+ }
211
+ };
212
+
213
+ /**
214
+ * Replacement for core apiFetch that automatically manages wizard loading UI.
215
+ */
216
+ wizardApiFetch = args => {
217
+ const {
218
+ quiet
219
+ } = args;
220
+ this.startLoading(quiet);
221
+ return new Promise((resolve, reject) => {
222
+ (0, _apiFetch.default)(args).then(response => {
223
+ this.doneLoading(quiet);
224
+ resolve(response);
225
+ }).catch(error => {
226
+ this.doneLoading(quiet);
227
+ reject(error);
228
+ });
229
+ });
230
+ };
231
+
232
+ /**
233
+ * Render a Route that checks for plugin installation requirements, and redirects to '/' when all are done.
234
+ *
235
+ * @return {void}
236
+ */
237
+ pluginRequirements = () => {
238
+ const {
239
+ complete
240
+ } = this.state;
241
+ /* After all plugins are loaded, redirect to / (this could be configurable) */
242
+ if (complete) {
243
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Redirect, {
244
+ from: "/plugin-requirements",
245
+ to: "/"
246
+ });
247
+ }
248
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Route, {
249
+ path: "/",
250
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
251
+ children: [complete !== null && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
252
+ className: "newspack-wizard__header",
253
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
254
+ className: "newspack-wizard__header__inner",
255
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
256
+ className: "newspack-wizard__title",
257
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
258
+ isLink: true,
259
+ href: newspack_urls.dashboard,
260
+ label: (0, _i18n.__)('Return to Dashboard', 'newspack-plugin'),
261
+ showTooltip: true,
262
+ icon: _icons.home,
263
+ iconSize: 36,
264
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewspackIcon, {
265
+ size: 36
266
+ })
267
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
268
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
269
+ children: requiredPlugins.length > 1 ? (0, _i18n.__)('Required plugins', 'newspack-plugin') : (0, _i18n.__)('Required plugin', 'newspack-plugin')
270
+ })
271
+ })]
272
+ })
273
+ })
274
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
275
+ className: "newspack-wizard newspack-wizard__content",
276
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.PluginInstaller, {
277
+ plugins: requiredPlugins,
278
+ onStatus: status => this.pluginInstallationStatus(status)
279
+ })
280
+ })]
281
+ })
282
+ });
283
+ };
284
+ getFallbackURL = () => {
285
+ if (typeof newspack_urls !== 'undefined') {
286
+ return newspack_urls.dashboard;
287
+ }
288
+ };
289
+
290
+ /**
291
+ * Render.
292
+ */
293
+ render() {
294
+ const {
295
+ simpleFooter
296
+ } = this.props;
297
+ const {
298
+ loading,
299
+ quietLoading,
300
+ error
301
+ } = this.state;
302
+ const loadingClasses = [loading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded'];
303
+ if (quietLoading) {
304
+ loadingClasses.push('newspack-wizard__is-loading-quiet');
305
+ }
306
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
307
+ children: [this.getError(), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
308
+ className: loadingClasses.join(' '),
309
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedComponent, {
310
+ pluginRequirements: requiredPlugins && this.pluginRequirements(),
311
+ clearError: this.clearError,
312
+ getError: this.getError,
313
+ errorData: error,
314
+ setError: this.setError,
315
+ isLoading: loading,
316
+ startLoading: this.startLoading,
317
+ doneLoading: this.doneLoading,
318
+ wizardApiFetch: this.wizardApiFetch,
319
+ ref: this.wrappedComponentRef,
320
+ ...this.props
321
+ })
322
+ }), !loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_footer.default, {
323
+ simple: simpleFooter
324
+ })]
325
+ });
326
+ }
327
+ };
328
+ }