newspack-components 4.2.0 → 4.4.0-epic-editor-refactor.1

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 (315) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/DEVELOPMENT.md +868 -0
  3. package/copy-styles.js +3 -2
  4. package/dist/cjs/accordion/index.js +17 -12
  5. package/dist/cjs/action-card/index.js +186 -140
  6. package/dist/cjs/action-card/style.scss +25 -2
  7. package/dist/cjs/autocomplete-tokenfield/index.js +254 -234
  8. package/dist/cjs/autocomplete-with-latest-posts/index.js +351 -0
  9. package/dist/cjs/autocomplete-with-latest-posts/style.scss +150 -0
  10. package/dist/cjs/autocomplete-with-suggestions/index.js +229 -126
  11. package/dist/cjs/badge/index.js +32 -0
  12. package/dist/cjs/badge/style.scss +36 -0
  13. package/dist/cjs/box-contrast/index.js +19 -15
  14. package/dist/cjs/button/index.js +41 -24
  15. package/dist/cjs/button-props/button-props.js +5 -5
  16. package/dist/cjs/button-props/index.js +2 -2
  17. package/dist/cjs/card/core-card.js +199 -0
  18. package/dist/cjs/card/index.js +75 -35
  19. package/dist/cjs/card/style-core.scss +295 -0
  20. package/dist/cjs/card/style.scss +4 -4
  21. package/dist/cjs/card-feature/index.js +141 -0
  22. package/dist/cjs/card-feature/style.scss +75 -0
  23. package/dist/cjs/card-form/index.js +144 -0
  24. package/dist/cjs/card-form/style.scss +20 -0
  25. package/dist/cjs/card-settings-group/index.js +69 -0
  26. package/dist/cjs/card-settings-group/style.scss +33 -0
  27. package/dist/cjs/card-sortable-list/index.js +426 -0
  28. package/dist/cjs/card-sortable-list/style.scss +48 -0
  29. package/dist/cjs/category-autocomplete/index.js +175 -155
  30. package/dist/cjs/color-picker/index.js +41 -23
  31. package/dist/cjs/color-picker/index.test.js +82 -0
  32. package/dist/cjs/color-picker/style.scss +11 -13
  33. package/dist/cjs/confirm-dialog/index.js +123 -0
  34. package/dist/cjs/consts.js +1 -1
  35. package/dist/cjs/custom-select-control/index.js +39 -28
  36. package/dist/cjs/dataviews/index.js +38 -0
  37. package/dist/cjs/dataviews/style.scss +9 -0
  38. package/dist/cjs/divider/index.js +47 -0
  39. package/dist/cjs/divider/style.scss +51 -0
  40. package/dist/cjs/footer/index.js +36 -30
  41. package/dist/cjs/form-token-field/index.js +51 -40
  42. package/dist/cjs/form-token-field/style.scss +0 -5
  43. package/dist/cjs/global-notices/index.js +5 -5
  44. package/dist/cjs/grid/index.js +25 -18
  45. package/dist/cjs/grid/style.scss +67 -8
  46. package/dist/cjs/handoff/index.js +204 -156
  47. package/dist/cjs/handoff-message/index.js +12 -7
  48. package/dist/cjs/hooks/index.js +10 -8
  49. package/dist/cjs/hooks/use-confirm-dialog.js +79 -0
  50. package/dist/cjs/hooks/use-unsaved-changes-dialog.js +144 -0
  51. package/dist/cjs/hooks/useObjectState.js +21 -12
  52. package/dist/cjs/hooks/useObjectState.test.js +55 -33
  53. package/dist/cjs/hooks/useOnClickOutside.js +6 -6
  54. package/dist/cjs/hooks/usePrompt.js +10 -13
  55. package/dist/cjs/image-upload/index.js +114 -123
  56. package/dist/cjs/image-upload/index.test.js +11 -13
  57. package/dist/cjs/image-upload/style.scss +12 -40
  58. package/dist/cjs/index.js +166 -92
  59. package/dist/cjs/info-button/index.js +43 -32
  60. package/dist/cjs/integration-icons/active-campaign.js +22 -0
  61. package/dist/cjs/integration-icons/constant-contact.js +28 -0
  62. package/dist/cjs/integration-icons/fundraise-up.js +25 -0
  63. package/dist/cjs/integration-icons/index.js +48 -0
  64. package/dist/cjs/integration-icons/mailchimp.js +19 -0
  65. package/dist/cjs/integration-icons/salesforce.js +17 -0
  66. package/dist/cjs/integration-icons/wisepops.js +20 -0
  67. package/dist/cjs/modal/index.js +29 -19
  68. package/dist/cjs/modal/style.scss +47 -13
  69. package/dist/cjs/newspack-icon/index.js +45 -38
  70. package/dist/cjs/newspack-icon/style.scss +5 -3
  71. package/dist/cjs/notice/index.js +64 -55
  72. package/dist/cjs/plugin-installer/index.js +259 -253
  73. package/dist/cjs/plugin-settings/SettingsSection.js +66 -60
  74. package/dist/cjs/plugin-settings/index.js +217 -200
  75. package/dist/cjs/plugin-toggle/index.js +192 -199
  76. package/dist/cjs/popover/index.js +41 -28
  77. package/dist/cjs/position-control/index.js +24 -23
  78. package/dist/cjs/progress-bar/index.js +71 -59
  79. package/dist/cjs/progress-bar/index.test.js +62 -68
  80. package/dist/cjs/proxied-imports/router.js +3 -3
  81. package/dist/cjs/radio-control/index.js +40 -27
  82. package/dist/cjs/section-header/index.js +143 -39
  83. package/dist/cjs/section-header/style.scss +129 -4
  84. package/dist/cjs/select-control/ButtonGroupControl.js +26 -21
  85. package/dist/cjs/select-control/GroupedSelectControl.js +41 -35
  86. package/dist/cjs/select-control/index.js +52 -40
  87. package/dist/cjs/settings/MinMaxSetting.js +30 -20
  88. package/dist/cjs/settings/SettingsCard.js +20 -17
  89. package/dist/cjs/settings/SettingsSection.js +22 -21
  90. package/dist/cjs/settings/index.js +5 -5
  91. package/dist/cjs/sortable-newsletter-list-control/index.js +78 -57
  92. package/dist/cjs/steps-list/index.js +44 -34
  93. package/dist/cjs/steps-list-item/index.js +47 -39
  94. package/dist/cjs/style-card/index.js +70 -63
  95. package/dist/cjs/style.scss +2 -0
  96. package/dist/cjs/tabbed-navigation/index.js +38 -36
  97. package/dist/cjs/text-control/index.js +27 -25
  98. package/dist/cjs/utils/color.js +4 -4
  99. package/dist/cjs/utils/editor-toolbar-back-button.js +61 -0
  100. package/dist/cjs/utils/index.js +31 -19
  101. package/dist/cjs/utils/style.scss +8 -0
  102. package/dist/cjs/waiting/index.js +48 -35
  103. package/dist/cjs/waiting/style.scss +4 -0
  104. package/dist/cjs/web-preview/index.js +219 -154
  105. package/dist/cjs/web-preview/style.scss +20 -53
  106. package/dist/cjs/with-wizard/index.js +362 -364
  107. package/dist/cjs/with-wizard/style.scss +28 -60
  108. package/dist/cjs/with-wizard-screen/index.js +54 -58
  109. package/dist/cjs/with-wizard-screen/style.scss +77 -10
  110. package/dist/cjs/wizard/components/WizardError.js +20 -18
  111. package/dist/cjs/wizard/components/WizardSnackbar.js +73 -0
  112. package/dist/cjs/wizard/components/style.scss +48 -0
  113. package/dist/cjs/wizard/index.js +207 -64
  114. package/dist/cjs/wizard/store/index.js +191 -97
  115. package/dist/cjs/wizard/store/utils.js +13 -8
  116. package/dist/esm/accordion/index.js +14 -9
  117. package/dist/esm/action-card/index.js +178 -124
  118. package/dist/esm/action-card/style.scss +25 -2
  119. package/dist/esm/autocomplete-tokenfield/index.js +248 -222
  120. package/dist/esm/autocomplete-with-latest-posts/index.js +347 -0
  121. package/dist/esm/autocomplete-with-latest-posts/style.scss +150 -0
  122. package/dist/esm/autocomplete-with-suggestions/index.js +226 -119
  123. package/dist/esm/badge/index.js +24 -0
  124. package/dist/esm/badge/style.scss +36 -0
  125. package/dist/esm/box-contrast/index.js +15 -11
  126. package/dist/esm/button/index.js +39 -19
  127. package/dist/esm/button-props/button-props.js +1 -1
  128. package/dist/esm/card/core-card.js +195 -0
  129. package/dist/esm/card/index.js +70 -22
  130. package/dist/esm/card/style-core.scss +295 -0
  131. package/dist/esm/card/style.scss +4 -4
  132. package/dist/esm/card-feature/index.js +131 -0
  133. package/dist/esm/card-feature/style.scss +75 -0
  134. package/dist/esm/card-form/index.js +134 -0
  135. package/dist/esm/card-form/style.scss +20 -0
  136. package/dist/esm/card-settings-group/index.js +61 -0
  137. package/dist/esm/card-settings-group/style.scss +33 -0
  138. package/dist/esm/card-sortable-list/index.js +425 -0
  139. package/dist/esm/card-sortable-list/style.scss +48 -0
  140. package/dist/esm/category-autocomplete/index.js +168 -140
  141. package/dist/esm/color-picker/index.js +39 -21
  142. package/dist/esm/color-picker/index.test.js +78 -0
  143. package/dist/esm/color-picker/style.scss +11 -13
  144. package/dist/esm/confirm-dialog/index.js +116 -0
  145. package/dist/esm/consts.js +1 -1
  146. package/dist/esm/custom-select-control/index.js +34 -15
  147. package/dist/esm/dataviews/index.js +34 -0
  148. package/dist/esm/dataviews/style.scss +9 -0
  149. package/dist/esm/divider/index.js +42 -0
  150. package/dist/esm/divider/style.scss +51 -0
  151. package/dist/esm/footer/index.js +34 -28
  152. package/dist/esm/form-token-field/index.js +46 -27
  153. package/dist/esm/form-token-field/style.scss +0 -5
  154. package/dist/esm/global-notices/index.js +3 -3
  155. package/dist/esm/grid/index.js +23 -13
  156. package/dist/esm/grid/style.scss +67 -8
  157. package/dist/esm/handoff/index.js +199 -143
  158. package/dist/esm/handoff-message/index.js +10 -6
  159. package/dist/esm/hooks/index.js +8 -6
  160. package/dist/esm/hooks/use-confirm-dialog.js +73 -0
  161. package/dist/esm/hooks/use-unsaved-changes-dialog.js +136 -0
  162. package/dist/esm/hooks/useObjectState.js +19 -9
  163. package/dist/esm/hooks/useObjectState.test.js +54 -32
  164. package/dist/esm/hooks/useOnClickOutside.js +4 -4
  165. package/dist/esm/hooks/usePrompt.js +9 -11
  166. package/dist/esm/image-upload/index.js +110 -111
  167. package/dist/esm/image-upload/index.test.js +11 -13
  168. package/dist/esm/image-upload/style.scss +12 -40
  169. package/dist/esm/index.js +13 -1
  170. package/dist/esm/info-button/index.js +38 -19
  171. package/dist/esm/integration-icons/active-campaign.js +16 -0
  172. package/dist/esm/integration-icons/constant-contact.js +22 -0
  173. package/dist/esm/integration-icons/fundraise-up.js +19 -0
  174. package/dist/esm/integration-icons/index.js +6 -0
  175. package/dist/esm/integration-icons/mailchimp.js +13 -0
  176. package/dist/esm/integration-icons/salesforce.js +11 -0
  177. package/dist/esm/integration-icons/wisepops.js +14 -0
  178. package/dist/esm/modal/index.js +27 -13
  179. package/dist/esm/modal/style.scss +47 -13
  180. package/dist/esm/newspack-icon/index.js +40 -25
  181. package/dist/esm/newspack-icon/style.scss +5 -3
  182. package/dist/esm/notice/index.js +59 -42
  183. package/dist/esm/plugin-installer/index.js +255 -243
  184. package/dist/esm/plugin-settings/SettingsSection.js +61 -50
  185. package/dist/esm/plugin-settings/index.js +212 -189
  186. package/dist/esm/plugin-toggle/index.js +187 -190
  187. package/dist/esm/popover/index.js +35 -16
  188. package/dist/esm/position-control/index.js +22 -18
  189. package/dist/esm/progress-bar/index.js +66 -49
  190. package/dist/esm/progress-bar/index.test.js +61 -67
  191. package/dist/esm/radio-control/index.js +34 -15
  192. package/dist/esm/section-header/index.js +140 -38
  193. package/dist/esm/section-header/style.scss +129 -4
  194. package/dist/esm/select-control/ButtonGroupControl.js +23 -18
  195. package/dist/esm/select-control/GroupedSelectControl.js +38 -30
  196. package/dist/esm/select-control/index.js +47 -27
  197. package/dist/esm/settings/MinMaxSetting.js +27 -16
  198. package/dist/esm/settings/SettingsCard.js +18 -13
  199. package/dist/esm/settings/SettingsSection.js +20 -19
  200. package/dist/esm/settings/index.js +3 -3
  201. package/dist/esm/sortable-newsletter-list-control/index.js +74 -53
  202. package/dist/esm/steps-list/index.js +39 -21
  203. package/dist/esm/steps-list-item/index.js +42 -26
  204. package/dist/esm/style-card/index.js +65 -50
  205. package/dist/esm/style.scss +2 -0
  206. package/dist/esm/tabbed-navigation/index.js +35 -33
  207. package/dist/esm/text-control/index.js +25 -19
  208. package/dist/esm/utils/color.js +4 -4
  209. package/dist/esm/utils/editor-toolbar-back-button.js +53 -0
  210. package/dist/esm/utils/index.js +29 -16
  211. package/dist/esm/utils/style.scss +8 -0
  212. package/dist/esm/waiting/index.js +43 -22
  213. package/dist/esm/waiting/style.scss +4 -0
  214. package/dist/esm/web-preview/index.js +218 -147
  215. package/dist/esm/web-preview/style.scss +20 -53
  216. package/dist/esm/with-wizard/index.js +360 -358
  217. package/dist/esm/with-wizard/style.scss +28 -60
  218. package/dist/esm/with-wizard-screen/index.js +48 -46
  219. package/dist/esm/with-wizard-screen/style.scss +77 -10
  220. package/dist/esm/wizard/components/WizardError.js +18 -16
  221. package/dist/esm/wizard/components/WizardSnackbar.js +70 -0
  222. package/dist/esm/wizard/components/style.scss +48 -0
  223. package/dist/esm/wizard/index.js +207 -58
  224. package/dist/esm/wizard/store/index.js +189 -90
  225. package/dist/esm/wizard/store/utils.js +13 -6
  226. package/package.json +30 -17
  227. package/release.config.js +1 -0
  228. package/shared/author-context.js +26 -0
  229. package/shared/hooks/use-coauthors.js +388 -0
  230. package/shared/hooks/use-coauthors.test.js +850 -0
  231. package/shared/hooks/use-custom-byline.js +47 -0
  232. package/shared/hooks/use-custom-byline.test.js +133 -0
  233. package/shared/scss/_mixins.scss +54 -0
  234. package/src/accordion/index.js +8 -7
  235. package/src/action-card/action-card.d.ts +7 -3
  236. package/src/action-card/index.js +39 -12
  237. package/src/action-card/style.scss +25 -2
  238. package/src/autocomplete-tokenfield/index.js +2 -2
  239. package/src/autocomplete-with-latest-posts/index.js +290 -0
  240. package/src/autocomplete-with-latest-posts/style.scss +150 -0
  241. package/src/badge/index.tsx +26 -0
  242. package/src/badge/style.scss +36 -0
  243. package/src/button/index.tsx +3 -2
  244. package/src/card/core-card.js +224 -0
  245. package/src/card/index.js +40 -1
  246. package/src/card/style-core.scss +295 -0
  247. package/src/card/style.scss +4 -4
  248. package/src/card-feature/README.md +188 -0
  249. package/src/card-feature/index.tsx +186 -0
  250. package/src/card-feature/style.scss +75 -0
  251. package/src/card-form/README.md +113 -0
  252. package/src/card-form/index.tsx +128 -0
  253. package/src/card-form/style.scss +20 -0
  254. package/src/card-settings-group/README.md +43 -0
  255. package/src/card-settings-group/index.tsx +78 -0
  256. package/src/card-settings-group/style.scss +33 -0
  257. package/src/card-sortable-list/README.md +51 -0
  258. package/src/card-sortable-list/index.tsx +435 -0
  259. package/src/card-sortable-list/style.scss +48 -0
  260. package/src/color-picker/index.js +15 -8
  261. package/src/color-picker/index.test.js +52 -0
  262. package/src/color-picker/style.scss +11 -13
  263. package/src/confirm-dialog/README.md +128 -0
  264. package/src/confirm-dialog/index.tsx +132 -0
  265. package/src/dataviews/index.tsx +34 -0
  266. package/src/dataviews/style.scss +9 -0
  267. package/src/divider/README.md +25 -0
  268. package/src/divider/index.js +31 -0
  269. package/src/divider/style.scss +51 -0
  270. package/src/form-token-field/style.scss +0 -5
  271. package/src/grid/index.tsx +2 -1
  272. package/src/grid/style.scss +67 -8
  273. package/src/handoff/README.md +93 -0
  274. package/src/handoff/index.js +46 -8
  275. package/src/hooks/index.ts +2 -1
  276. package/src/hooks/use-confirm-dialog.tsx +80 -0
  277. package/src/hooks/use-unsaved-changes-dialog.tsx +140 -0
  278. package/src/image-upload/index.js +10 -15
  279. package/src/image-upload/style.scss +12 -40
  280. package/src/index.js +13 -1
  281. package/src/integration-icons/active-campaign.js +14 -0
  282. package/src/integration-icons/constant-contact.js +22 -0
  283. package/src/integration-icons/fundraise-up.js +18 -0
  284. package/src/integration-icons/index.js +6 -0
  285. package/src/integration-icons/mailchimp.js +10 -0
  286. package/src/integration-icons/salesforce.js +10 -0
  287. package/src/integration-icons/wisepops.js +14 -0
  288. package/src/modal/index.js +12 -3
  289. package/src/modal/style.scss +47 -13
  290. package/src/newspack-icon/style.scss +5 -3
  291. package/src/plugin-installer/index.js +30 -19
  292. package/src/section-header/index.js +105 -14
  293. package/src/section-header/style.scss +129 -4
  294. package/src/select-control/index.js +4 -0
  295. package/src/style.scss +2 -0
  296. package/src/utils/editor-toolbar-back-button.tsx +48 -0
  297. package/src/utils/index.js +6 -0
  298. package/src/utils/style.scss +8 -0
  299. package/src/waiting/index.js +2 -1
  300. package/src/waiting/style.scss +4 -0
  301. package/src/web-preview/index.js +90 -35
  302. package/src/web-preview/style.scss +20 -53
  303. package/src/with-wizard/index.js +1 -1
  304. package/src/with-wizard/style.scss +28 -60
  305. package/src/with-wizard-screen/style.scss +77 -10
  306. package/src/wizard/components/WizardSnackbar.js +58 -0
  307. package/src/wizard/components/style.scss +48 -0
  308. package/src/wizard/index.js +152 -21
  309. package/src/wizard/store/index.js +28 -2
  310. package/dist/cjs/button-card/index.js +0 -72
  311. package/dist/cjs/button-card/style.scss +0 -180
  312. package/dist/esm/button-card/index.js +0 -64
  313. package/dist/esm/button-card/style.scss +0 -180
  314. package/src/button-card/index.js +0 -52
  315. package/src/button-card/style.scss +0 -180
@@ -1,3 +1,15 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ var _excluded = ["className", "children", "compact", "useModal", "modalTitle", "modalBody", "onReady", "editLink", "bannerText", "bannerButtonText", "url"];
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
12
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
1
13
  /**
2
14
  * Handoff
3
15
  */
@@ -20,156 +32,200 @@ import { Button, Card, Modal, Waiting } from '../';
20
32
  import assign from 'lodash/assign';
21
33
  import classnames from 'classnames';
22
34
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
- class Handoff extends Component {
24
- constructor() {
25
- super(...arguments);
26
- this.state = {
35
+ var Handoff = /*#__PURE__*/function (_Component) {
36
+ function Handoff() {
37
+ var _this;
38
+ _classCallCheck(this, Handoff);
39
+ _this = _callSuper(this, Handoff, arguments);
40
+ _defineProperty(_this, "componentDidMount", function () {
41
+ _this._isMounted = true;
42
+ var _this$props = _this.props,
43
+ plugin = _this$props.plugin,
44
+ url = _this$props.url;
45
+ if (plugin && !url) {
46
+ _this.retrievePluginInfo(plugin);
47
+ }
48
+ });
49
+ _defineProperty(_this, "componentWillUnmount", function () {
50
+ _this._isMounted = false;
51
+ });
52
+ _defineProperty(_this, "retrievePluginInfo", function (plugin) {
53
+ var onReady = _this.props.onReady;
54
+ apiFetch({
55
+ path: '/newspack/v1/plugins/' + plugin
56
+ }).then(function (pluginInfo) {
57
+ if (_this._isMounted) {
58
+ onReady(pluginInfo);
59
+ _this.setState({
60
+ pluginInfo: pluginInfo
61
+ });
62
+ }
63
+ });
64
+ });
65
+ _defineProperty(_this, "textForPlugin", function (pluginInfo) {
66
+ var defaults = {
67
+ modalBody: null,
68
+ modalTitle: pluginInfo.Name && "".concat(__('Manage', 'newspack-plugin'), " ").concat(pluginInfo.Name),
69
+ primaryButton: pluginInfo.Name && "".concat(__('Manage', 'newspack-plugin'), " ").concat(pluginInfo.Name),
70
+ primaryModalButton: __('Manage', 'newspack-plugin'),
71
+ dismissModalButton: __('Dismiss', 'newspack-plugin')
72
+ };
73
+ return assign(defaults, _this.props);
74
+ });
75
+ _defineProperty(_this, "goToUrl", function () {
76
+ var _this$props2 = _this.props,
77
+ url = _this$props2.url,
78
+ showOnBlockEditor = _this$props2.showOnBlockEditor,
79
+ bannerText = _this$props2.bannerText,
80
+ bannerButtonText = _this$props2.bannerButtonText;
81
+ apiFetch({
82
+ path: '/newspack/v1/handoff',
83
+ method: 'POST',
84
+ data: {
85
+ destinationUrl: url,
86
+ handoffReturnUrl: window && window.location.href,
87
+ showOnBlockEditor: showOnBlockEditor ? true : false,
88
+ bannerText: bannerText,
89
+ bannerButtonText: bannerButtonText
90
+ }
91
+ }).then(function (response) {
92
+ window.location.href = response.HandoffLink;
93
+ });
94
+ });
95
+ _defineProperty(_this, "goToPlugin", function (plugin) {
96
+ var _this$props3 = _this.props,
97
+ editLink = _this$props3.editLink,
98
+ showOnBlockEditor = _this$props3.showOnBlockEditor,
99
+ bannerText = _this$props3.bannerText,
100
+ bannerButtonText = _this$props3.bannerButtonText;
101
+ apiFetch({
102
+ path: '/newspack/v1/plugins/' + plugin + '/handoff',
103
+ method: 'POST',
104
+ data: {
105
+ editLink: editLink,
106
+ handoffReturnUrl: window && window.location.href,
107
+ showOnBlockEditor: showOnBlockEditor ? true : false,
108
+ bannerText: bannerText,
109
+ bannerButtonText: bannerButtonText
110
+ }
111
+ }).then(function (response) {
112
+ window.location.href = response.HandoffLink;
113
+ });
114
+ });
115
+ _this.state = {
27
116
  pluginInfo: [],
28
117
  showModal: false
29
118
  };
119
+ return _this;
30
120
  }
31
- componentDidMount = () => {
32
- this._isMounted = true;
33
- const {
34
- plugin
35
- } = this.props;
36
- this.retrievePluginInfo(plugin);
37
- };
38
- componentWillUnmount = () => {
39
- this._isMounted = false;
40
- };
41
- retrievePluginInfo = plugin => {
42
- const {
43
- onReady
44
- } = this.props;
45
- apiFetch({
46
- path: '/newspack/v1/plugins/' + plugin
47
- }).then(pluginInfo => {
48
- if (this._isMounted) {
49
- onReady(pluginInfo);
50
- this.setState({
51
- pluginInfo
52
- });
53
- }
54
- });
55
- };
56
- textForPlugin = pluginInfo => {
57
- const defaults = {
58
- modalBody: null,
59
- modalTitle: pluginInfo.Name && `${__('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
60
- primaryButton: pluginInfo.Name && `${__('Manage', 'newspack-plugin')} ${pluginInfo.Name}`,
61
- primaryModalButton: __('Manage', 'newspack-plugin'),
62
- dismissModalButton: __('Dismiss', 'newspack-plugin')
63
- };
64
- return assign(defaults, this.props);
65
- };
66
- goToPlugin = plugin => {
67
- const {
68
- editLink,
69
- showOnBlockEditor
70
- } = this.props;
71
- apiFetch({
72
- path: '/newspack/v1/plugins/' + plugin + '/handoff',
73
- method: 'POST',
74
- data: {
75
- editLink,
76
- handoffReturnUrl: window && window.location.href,
77
- showOnBlockEditor: showOnBlockEditor ? true : false
78
- }
79
- }).then(response => {
80
- window.location.href = response.HandoffLink;
81
- });
82
- };
83
-
84
- /**
85
- * Render.
86
- */
87
- render() {
88
- const {
89
- className,
90
- children,
91
- compact,
92
- useModal,
93
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
94
- modalTitle: _modalTitle,
95
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
96
- modalBody: _modalBody,
97
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
98
- onReady,
99
- // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
100
- editLink,
101
- ...otherProps
102
- } = this.props;
103
- const {
104
- pluginInfo,
105
- showModal
106
- } = this.state;
107
- const {
108
- modalBody,
109
- modalTitle,
110
- primaryButton,
111
- primaryModalButton,
112
- dismissModalButton
113
- } = this.textForPlugin(pluginInfo);
114
- const {
115
- Configured,
116
- Name,
117
- Slug,
118
- Status
119
- } = pluginInfo;
120
- const classes = classnames(Configured && 'is-configured', className);
121
- return /*#__PURE__*/_jsxs(Fragment, {
122
- children: [Name && 'active' === Status && /*#__PURE__*/_jsx(Button, {
123
- className: classes,
124
- isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
125
- ...otherProps,
126
- onClick: () => useModal ? this.setState({
127
- showModal: true
128
- }) : this.goToPlugin(Slug),
129
- children: children ? children : primaryButton
130
- }), Name && 'active' !== Status && /*#__PURE__*/_jsx(Button, {
131
- className: classes,
132
- variant: "secondary",
133
- disabled: true,
134
- ...otherProps,
135
- children: Name + __(' not installed', 'newspack-plugin')
136
- }), !Name && /*#__PURE__*/_jsx(Button, {
137
- className: classes,
138
- isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink,
139
- ...otherProps,
140
- children: /*#__PURE__*/_jsxs(Fragment, {
141
- children: [!compact && /*#__PURE__*/_jsx(Waiting, {
142
- isLeft: true
143
- }), __('Retrieving Plugin Info', 'newspack-plugin')]
144
- })
145
- }), showModal && /*#__PURE__*/_jsxs(Modal, {
146
- title: modalTitle,
147
- onRequestClose: () => this.setState({
148
- showModal: false
149
- }),
150
- children: [/*#__PURE__*/_jsx("p", {
151
- children: modalBody
152
- }), /*#__PURE__*/_jsxs(Card, {
153
- buttonsCard: true,
154
- noBorder: true,
155
- className: "justify-end",
156
- children: [/*#__PURE__*/_jsx(Button, {
157
- variant: "secondary",
158
- onClick: () => this.setState({
121
+ _inherits(Handoff, _Component);
122
+ return _createClass(Handoff, [{
123
+ key: "render",
124
+ value:
125
+ /**
126
+ * Render.
127
+ */
128
+ function render() {
129
+ var _this2 = this;
130
+ var _this$props4 = this.props,
131
+ className = _this$props4.className,
132
+ children = _this$props4.children,
133
+ compact = _this$props4.compact,
134
+ useModal = _this$props4.useModal,
135
+ _modalTitle = _this$props4.modalTitle,
136
+ _modalBody = _this$props4.modalBody,
137
+ onReady = _this$props4.onReady,
138
+ editLink = _this$props4.editLink,
139
+ bannerText = _this$props4.bannerText,
140
+ bannerButtonText = _this$props4.bannerButtonText,
141
+ url = _this$props4.url,
142
+ otherProps = _objectWithoutProperties(_this$props4, _excluded);
143
+ var _this$state = this.state,
144
+ pluginInfo = _this$state.pluginInfo,
145
+ showModal = _this$state.showModal;
146
+ var _this$textForPlugin = this.textForPlugin(pluginInfo),
147
+ modalBody = _this$textForPlugin.modalBody,
148
+ modalTitle = _this$textForPlugin.modalTitle,
149
+ primaryButton = _this$textForPlugin.primaryButton,
150
+ primaryModalButton = _this$textForPlugin.primaryModalButton,
151
+ dismissModalButton = _this$textForPlugin.dismissModalButton;
152
+ var Configured = pluginInfo.Configured,
153
+ Name = pluginInfo.Name,
154
+ Slug = pluginInfo.Slug,
155
+ Status = pluginInfo.Status;
156
+ var classes = classnames(Configured && 'is-configured', className);
157
+ var goTo = function goTo() {
158
+ return url ? _this2.goToUrl() : _this2.goToPlugin(Slug);
159
+ };
160
+ return /*#__PURE__*/_jsxs(Fragment, {
161
+ children: [url && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
162
+ className: classes,
163
+ isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink
164
+ }, otherProps), {}, {
165
+ onClick: function onClick() {
166
+ return useModal && children ? _this2.setState({
167
+ showModal: true
168
+ }) : goTo();
169
+ },
170
+ children: children ? children : primaryButton
171
+ })), !url && Name && 'active' === Status && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
172
+ className: classes,
173
+ isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink
174
+ }, otherProps), {}, {
175
+ onClick: function onClick() {
176
+ return useModal ? _this2.setState({
177
+ showModal: true
178
+ }) : goTo();
179
+ },
180
+ children: children ? children : primaryButton
181
+ })), !url && Name && 'active' !== Status && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
182
+ className: classes,
183
+ variant: "secondary",
184
+ disabled: true
185
+ }, otherProps), {}, {
186
+ children: Name + __(' not installed', 'newspack-plugin')
187
+ })), !url && !Name && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
188
+ className: classes,
189
+ isSecondary: !otherProps.isPrimary && !otherProps.isTertiary && !otherProps.isLink
190
+ }, otherProps), {}, {
191
+ children: /*#__PURE__*/_jsxs(Fragment, {
192
+ children: [!compact && /*#__PURE__*/_jsx(Waiting, {
193
+ isLeft: true
194
+ }), __('Retrieving Plugin Info', 'newspack-plugin')]
195
+ })
196
+ })), showModal && /*#__PURE__*/_jsxs(Modal, {
197
+ title: modalTitle,
198
+ onRequestClose: function onRequestClose() {
199
+ return _this2.setState({
159
200
  showModal: false
160
- }),
161
- children: dismissModalButton
162
- }), /*#__PURE__*/_jsx(Button, {
163
- variant: "primary",
164
- onClick: () => this.goToPlugin(Slug),
165
- children: primaryModalButton
201
+ });
202
+ },
203
+ children: [/*#__PURE__*/_jsx("p", {
204
+ children: modalBody
205
+ }), /*#__PURE__*/_jsxs(Card, {
206
+ buttonsCard: true,
207
+ noBorder: true,
208
+ className: "justify-end",
209
+ children: [/*#__PURE__*/_jsx(Button, {
210
+ variant: "secondary",
211
+ onClick: function onClick() {
212
+ return _this2.setState({
213
+ showModal: false
214
+ });
215
+ },
216
+ children: dismissModalButton
217
+ }), /*#__PURE__*/_jsx(Button, {
218
+ variant: "primary",
219
+ onClick: goTo,
220
+ children: primaryModalButton
221
+ })]
166
222
  })]
167
223
  })]
168
- })]
169
- });
170
- }
171
- }
224
+ });
225
+ }
226
+ }]);
227
+ }(Component);
172
228
  Handoff.defaultProps = {
173
- onReady: () => {}
229
+ onReady: function onReady() {}
174
230
  };
175
231
  export default Handoff;
@@ -1,3 +1,4 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
2
  /**
2
3
  * WordPress dependencies.
3
4
  */
@@ -14,19 +15,22 @@ import { Notice } from '../';
14
15
  */
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  export default function HandoffMessage() {
17
- const [handoffMessage, setHandoffMessage] = useState(false);
18
- useEffect(() => {
18
+ var _useState = useState(false),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ handoffMessage = _useState2[0],
21
+ setHandoffMessage = _useState2[1];
22
+ useEffect(function () {
19
23
  // 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) {
24
+ setTimeout(function () {
25
+ var handoff = JSON.parse(localStorage.getItem(HANDOFF_KEY));
26
+ if (handoff !== null && handoff !== void 0 && handoff.message) {
23
27
  setHandoffMessage(handoff.message);
24
28
  } else {
25
29
  setHandoffMessage(false);
26
30
  }
27
31
 
28
32
  // Clean up the notification if navigating away from the relevant page.
29
- if (handoff?.url && -1 === window.location.href.indexOf(handoff.url)) {
33
+ if (handoff !== null && handoff !== void 0 && handoff.url && -1 === window.location.href.indexOf(handoff.url)) {
30
34
  window.localStorage.removeItem(HANDOFF_KEY);
31
35
  setHandoffMessage(false);
32
36
  }
@@ -5,13 +5,15 @@ import { useRef } from '@wordpress/element';
5
5
  import usePrompt from './usePrompt';
6
6
  import useObjectState from './useObjectState';
7
7
  import useOnClickOutside from './useOnClickOutside';
8
- const useUniqueId = prefix => {
9
- const id = useRef(`${prefix}-${Math.round(Math.random() * 99999)}`);
8
+ import useConfirmDialog from './use-confirm-dialog';
9
+ var useUniqueId = function useUniqueId(prefix) {
10
+ var id = useRef("".concat(prefix, "-").concat(Math.round(Math.random() * 99999)));
10
11
  return id.current;
11
12
  };
12
13
  export default {
13
- usePrompt,
14
- useObjectState,
15
- useOnClickOutside,
16
- useUniqueId
14
+ usePrompt: usePrompt,
15
+ useObjectState: useObjectState,
16
+ useOnClickOutside: useOnClickOutside,
17
+ useUniqueId: useUniqueId,
18
+ useConfirmDialog: useConfirmDialog
17
19
  };
@@ -0,0 +1,73 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["message", "when"];
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ /**
8
+ * WordPress dependencies.
9
+ */
10
+ import { useCallback, useRef, useState } from '@wordpress/element';
11
+
12
+ /**
13
+ * Internal dependencies.
14
+ */
15
+ import ConfirmDialog from '../confirm-dialog';
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ /**
18
+ * A hook that encapsulates the ConfirmDialog component and provides a
19
+ * `requestConfirm` function for imperative use.
20
+ *
21
+ * Calling `requestConfirm( callback )` will show a confirmation dialog.
22
+ * If the user confirms, `callback` is invoked. If the user cancels, it is not.
23
+ *
24
+ * When `when` is explicitly `false`, `requestConfirm( callback )` calls
25
+ * `callback` immediately without showing the dialog. This is useful for
26
+ * guarding actions that are only destructive when there are unsaved changes
27
+ * (e.g. `when={ isDirty }`). When `when` is omitted or `true`, the dialog
28
+ * is always shown.
29
+ *
30
+ * The `confirmDialog` element must be rendered somewhere in the component's
31
+ * JSX for the dialog to appear.
32
+ */
33
+ function useConfirmDialog(options) {
34
+ var message = options.message,
35
+ when = options.when,
36
+ dialogProps = _objectWithoutProperties(options, _excluded);
37
+ var _useState = useState(null),
38
+ _useState2 = _slicedToArray(_useState, 2),
39
+ pendingAction = _useState2[0],
40
+ setPendingAction = _useState2[1];
41
+
42
+ // Keep a ref so `requestConfirm` can always read the latest `when` value
43
+ // without needing to be recreated on every render.
44
+ var whenRef = useRef(when);
45
+ whenRef.current = when;
46
+ var requestConfirm = useCallback(function (callback) {
47
+ if (whenRef.current !== false) {
48
+ // Store as a thunk to opt out of React's functional-update interpretation.
49
+ setPendingAction(function () {
50
+ return callback;
51
+ });
52
+ } else {
53
+ callback();
54
+ }
55
+ }, []);
56
+ var confirmDialog = /*#__PURE__*/_jsx(ConfirmDialog, _objectSpread(_objectSpread({}, dialogProps), {}, {
57
+ when: when,
58
+ isOpen: !!pendingAction,
59
+ onConfirm: function onConfirm() {
60
+ pendingAction === null || pendingAction === void 0 || pendingAction();
61
+ setPendingAction(null);
62
+ },
63
+ onCancel: function onCancel() {
64
+ return setPendingAction(null);
65
+ },
66
+ children: message
67
+ }));
68
+ return {
69
+ confirmDialog: confirmDialog,
70
+ requestConfirm: requestConfirm
71
+ };
72
+ }
73
+ export default useConfirmDialog;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { useEffect, useRef } from '@wordpress/element';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies.
9
+ */
10
+ import useConfirmDialog from './use-confirm-dialog';
11
+ // Stack of mounted guards; the last entry owns the document-level handler so
12
+ // only the most-recently-mounted guard prompts when several are active. Using a
13
+ // stack keeps ownership correct under out-of-order unmounts.
14
+ var activeGuards = [];
15
+
16
+ /**
17
+ * Returns true when `href` resolves to the same origin as the current page —
18
+ * i.e. it is an internal navigation that would unload the wizard. External
19
+ * `https://...` links, `mailto:`, `tel:`, and other schemes navigate to a new
20
+ * context (new tab, mail client, dialer) without unloading the wizard, and
21
+ * must not trigger the discard-changes prompt.
22
+ */
23
+ function isSameOriginNavigation(link) {
24
+ try {
25
+ var url = new URL(link.href, window.location.href);
26
+ return url.origin === window.location.origin && (url.protocol === 'http:' || url.protocol === 'https:');
27
+ } catch (e) {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Shared unsaved-changes guard. Wraps `useConfirmDialog` with standardized
34
+ * messaging, intercepts same-origin link clicks so the dialog fires instead
35
+ * of a silent navigation, and adds a `beforeunload` listener as the last-resort
36
+ * guard for refresh / tab-close (browser-native, cannot be styled). The
37
+ * returned `confirmDialog` element must be rendered in JSX.
38
+ *
39
+ * Single-consumer constraint: the click handler is attached at the document
40
+ * level in capture phase. Two simultaneously-active instances will both fire
41
+ * a dialog. A development-only warning surfaces this.
42
+ */
43
+ function useUnsavedChangesDialog(_ref) {
44
+ var when = _ref.when;
45
+ var _useConfirmDialog = useConfirmDialog({
46
+ when: when,
47
+ message: __('You have unsaved changes that will be lost. Discard changes?', 'newspack-plugin'),
48
+ confirmButtonText: __('Discard changes', 'newspack-plugin'),
49
+ hideTitle: true
50
+ }),
51
+ confirmDialog = _useConfirmDialog.confirmDialog,
52
+ requestConfirm = _useConfirmDialog.requestConfirm;
53
+
54
+ // Tracks navigation the user has already approved via our custom dialog so
55
+ // the beforeunload guard doesn't fire a second native prompt on top of it.
56
+ var isNavigatingRef = useRef(false);
57
+ useEffect(function () {
58
+ if (!when) {
59
+ return;
60
+ }
61
+ var ownerId = Symbol('unsaved-changes-guard');
62
+ activeGuards.push(ownerId);
63
+ if (process.env.NODE_ENV !== 'production' && activeGuards.length > 1) {
64
+ // eslint-disable-next-line no-console
65
+ console.warn('useUnsavedChangesDialog: more than one active instance detected. ' + 'Document-level click capture will fire a dialog per instance — ensure only one guard is active at a time.');
66
+ }
67
+ var handler = function handler(e) {
68
+ // Only the top-of-stack guard prompts, so concurrent guards can't stack dialogs.
69
+ if (activeGuards[activeGuards.length - 1] !== ownerId) {
70
+ return;
71
+ }
72
+ if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) {
73
+ return;
74
+ }
75
+ var target = e.target;
76
+ var link = target === null || target === void 0 ? void 0 : target.closest('a[href]');
77
+ if (!link) {
78
+ return;
79
+ }
80
+ var href = link.getAttribute('href');
81
+ if (!href || href.startsWith('#') || href.startsWith('javascript:')) {
82
+ // All `#`-prefixed links are skipped here: plain anchors
83
+ // (`#section`) are scroll targets, and HashRouter paths
84
+ // (`#/route`) are intercepted by `ConfirmDialog`'s built-in
85
+ // `history.block` listener instead. Routing them through
86
+ // `window.location.href` here would trigger a hashchange
87
+ // that the still-active block re-catches, double-prompting.
88
+ return;
89
+ }
90
+ if (link.target && link.target !== '_self') {
91
+ return;
92
+ }
93
+ // Skip mailto:, tel:, external origins, and any non-http(s) scheme —
94
+ // they don't unload the wizard, so a discard prompt would be wrong.
95
+ if (!isSameOriginNavigation(link)) {
96
+ return;
97
+ }
98
+ e.preventDefault();
99
+ e.stopPropagation();
100
+ var destination = link.href;
101
+ requestConfirm(function () {
102
+ isNavigatingRef.current = true;
103
+ window.location.href = destination;
104
+ });
105
+ };
106
+ document.addEventListener('click', handler, true);
107
+ return function () {
108
+ document.removeEventListener('click', handler, true);
109
+ var idx = activeGuards.indexOf(ownerId);
110
+ if (idx !== -1) {
111
+ activeGuards.splice(idx, 1);
112
+ }
113
+ };
114
+ }, [when, requestConfirm]);
115
+ useEffect(function () {
116
+ if (!when) {
117
+ return;
118
+ }
119
+ var handler = function handler(e) {
120
+ if (isNavigatingRef.current) {
121
+ return;
122
+ }
123
+ e.preventDefault();
124
+ e.returnValue = '';
125
+ };
126
+ window.addEventListener('beforeunload', handler);
127
+ return function () {
128
+ return window.removeEventListener('beforeunload', handler);
129
+ };
130
+ }, [when]);
131
+ return {
132
+ confirmDialog: confirmDialog,
133
+ requestConfirm: requestConfirm
134
+ };
135
+ }
136
+ export default useUnsavedChangesDialog;