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,5 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
3
  /**
2
4
  * WordPress dependencies
3
5
  */
@@ -10,7 +12,7 @@ import mergeWith from 'lodash/mergeWith';
10
12
  * @property {Object.<string, any>} [update] The update object with key-value pairs to merge into the state.
11
13
  */
12
14
 
13
- const mergeCustomizer = (objValue, srcValue) => {
15
+ var mergeCustomizer = function mergeCustomizer(objValue, srcValue) {
14
16
  if (isArray(objValue)) {
15
17
  // If it's an array, replace it (instead of concatenating).
16
18
  return srcValue;
@@ -25,16 +27,24 @@ const mergeCustomizer = (objValue, srcValue) => {
25
27
  * @param {T} initial Initial state object.
26
28
  * @return {[T, (keyOrUpdate: string | Partial<T>) => (value?: any) => void]} The state object and a function to update it.
27
29
  */
28
- export default (initial = {}) => {
29
- const [stateObject, setStateObject] = useState(initial);
30
- const runUpdate = update => setStateObject(_stateObject => mergeWith({}, _stateObject, update, mergeCustomizer));
31
- const updateStateObject = keyOrUpdate => {
30
+ export default (function () {
31
+ var initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
+ var _useState = useState(initial),
33
+ _useState2 = _slicedToArray(_useState, 2),
34
+ stateObject = _useState2[0],
35
+ setStateObject = _useState2[1];
36
+ var runUpdate = function runUpdate(update) {
37
+ return setStateObject(function (_stateObject) {
38
+ return mergeWith({}, _stateObject, update, mergeCustomizer);
39
+ });
40
+ };
41
+ var updateStateObject = function updateStateObject(keyOrUpdate) {
32
42
  if (typeof keyOrUpdate === 'string') {
33
- return value => runUpdate({
34
- [keyOrUpdate]: value
35
- });
43
+ return function (value) {
44
+ return runUpdate(_defineProperty({}, keyOrUpdate, value));
45
+ };
36
46
  }
37
47
  runUpdate(keyOrUpdate);
38
48
  };
39
49
  return [stateObject, updateStateObject];
40
- };
50
+ });
@@ -1,8 +1,9 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
2
  import React from 'react';
2
3
  import { render, screen, fireEvent, act } from '@testing-library/react';
3
4
  import useObjectState from './useObjectState';
4
5
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
- const INIT_STATE = {
6
+ var INIT_STATE = {
6
7
  name: 'Foo',
7
8
  widgets: [1],
8
9
  attributes: {
@@ -10,68 +11,89 @@ const INIT_STATE = {
10
11
  baz: 1
11
12
  }
12
13
  };
13
- const TestComponent = () => {
14
- const [state, updateState] = useObjectState(INIT_STATE);
14
+ var TestComponent = function TestComponent() {
15
+ var _useObjectState = useObjectState(INIT_STATE),
16
+ _useObjectState2 = _slicedToArray(_useObjectState, 2),
17
+ state = _useObjectState2[0],
18
+ updateState = _useObjectState2[1];
15
19
  return /*#__PURE__*/_jsxs("div", {
16
20
  children: [/*#__PURE__*/_jsx("input", {
17
21
  placeholder: "state",
18
- onChange: () => {},
22
+ onChange: function onChange() {},
19
23
  value: JSON.stringify(state)
20
24
  }), /*#__PURE__*/_jsx("button", {
21
- onClick: () => updateState({
22
- widgets: []
23
- }),
25
+ onClick: function onClick() {
26
+ return updateState({
27
+ widgets: []
28
+ });
29
+ },
24
30
  children: "Remove widgets"
25
31
  }), /*#__PURE__*/_jsx("button", {
26
- onClick: () => updateState({
27
- widgets: [1]
28
- }),
32
+ onClick: function onClick() {
33
+ return updateState({
34
+ widgets: [1]
35
+ });
36
+ },
29
37
  children: "Add widget"
30
38
  }), /*#__PURE__*/_jsx("button", {
31
- onClick: () => updateState({
32
- attributes: {
33
- bar: 2
34
- }
35
- }),
39
+ onClick: function onClick() {
40
+ return updateState({
41
+ attributes: {
42
+ bar: 2
43
+ }
44
+ });
45
+ },
36
46
  children: "Nested update"
37
47
  }), /*#__PURE__*/_jsx("input", {
38
48
  type: "text",
39
49
  value: state.name,
40
- onChange: e => updateState({
41
- name: e.target.value
42
- }),
50
+ onChange: function onChange(e) {
51
+ return updateState({
52
+ name: e.target.value
53
+ });
54
+ },
43
55
  placeholder: "name"
44
56
  })]
45
57
  });
46
58
  };
47
- describe('useObjectState', () => {
48
- const getState = () => JSON.parse(screen.getByPlaceholderText('state').getAttribute('value'));
49
- beforeEach(() => {
59
+ describe('useObjectState', function () {
60
+ var getState = function getState() {
61
+ return JSON.parse(screen.getByPlaceholderText('state').getAttribute('value'));
62
+ };
63
+ beforeEach(function () {
50
64
  render(/*#__PURE__*/_jsx(TestComponent, {}));
51
65
  });
52
- it('updates arrays', () => {
66
+ it('updates arrays', function () {
53
67
  expect(getState()).toStrictEqual(INIT_STATE);
54
- act(() => screen.getByText('Remove widgets').click());
68
+ act(function () {
69
+ return screen.getByText('Remove widgets').click();
70
+ });
55
71
  expect(getState()).toMatchObject({
56
72
  widgets: []
57
73
  });
58
- act(() => screen.getByText('Add widget').click());
74
+ act(function () {
75
+ return screen.getByText('Add widget').click();
76
+ });
59
77
  expect(getState()).toMatchObject({
60
78
  widgets: [1]
61
79
  });
62
80
  });
63
- it('updates a simple value', () => {
64
- act(() => fireEvent.change(screen.getByPlaceholderText('name'), {
65
- target: {
66
- value: 'Ramon'
67
- }
68
- }));
81
+ it('updates a simple value', function () {
82
+ act(function () {
83
+ return fireEvent.change(screen.getByPlaceholderText('name'), {
84
+ target: {
85
+ value: 'Ramon'
86
+ }
87
+ });
88
+ });
69
89
  expect(getState()).toMatchObject({
70
90
  name: 'Ramon'
71
91
  });
72
92
  });
73
- it('updates a nested object', () => {
74
- act(() => screen.getByText('Nested update').click());
93
+ it('updates a nested object', function () {
94
+ act(function () {
95
+ return screen.getByText('Nested update').click();
96
+ });
75
97
  expect(getState()).toMatchObject({
76
98
  attributes: {
77
99
  bar: 2,
@@ -4,9 +4,9 @@
4
4
  * External dependencies.
5
5
  */
6
6
  import { useEffect } from '@wordpress/element';
7
- const useOnClickOutside = (ref, handler) => {
8
- useEffect(() => {
9
- const listener = event => {
7
+ var useOnClickOutside = function useOnClickOutside(ref, handler) {
8
+ useEffect(function () {
9
+ var listener = function listener(event) {
10
10
  // Do nothing if clicking ref's element or descendent elements
11
11
  if (!ref.current || ref.current.contains(event.target)) {
12
12
  return;
@@ -15,7 +15,7 @@ const useOnClickOutside = (ref, handler) => {
15
15
  };
16
16
  document.addEventListener('mousedown', listener);
17
17
  document.addEventListener('touchstart', listener);
18
- return () => {
18
+ return function () {
19
19
  document.removeEventListener('mousedown', listener);
20
20
  document.removeEventListener('touchstart', listener);
21
21
  };
@@ -9,13 +9,11 @@ import { useEffect, useRef } from '@wordpress/element';
9
9
  * Internal dependencies.
10
10
  */
11
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 => {
12
+ var useHistory = Router.useHistory;
13
+ export default (function (when, message) {
14
+ var history = useHistory();
15
+ var self = useRef(null);
16
+ var onWindowOrTabClose = function onWindowOrTabClose(event) {
19
17
  if (!when) {
20
18
  return;
21
19
  }
@@ -24,17 +22,17 @@ export default (when, message) => {
24
22
  }
25
23
  return message;
26
24
  };
27
- useEffect(() => {
25
+ useEffect(function () {
28
26
  if (when) {
29
27
  self.current = history.block(message);
30
28
  window.addEventListener('beforeunload', onWindowOrTabClose);
31
29
  }
32
- return () => {
30
+ return function () {
33
31
  if (self.current) {
34
32
  self.current();
35
33
  }
36
34
  window.removeEventListener('beforeunload', onWindowOrTabClose);
37
35
  };
38
36
  }, [message, when]);
39
- return self.current || (() => {});
40
- };
37
+ return self.current || function () {};
38
+ });
@@ -1,3 +1,11 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
1
9
  /**
2
10
  * Image Upload
3
11
  */
@@ -7,11 +15,12 @@
7
15
  */
8
16
  import { Component } from '@wordpress/element';
9
17
  import { __ } from '@wordpress/i18n';
18
+ import { BaseControl } from '@wordpress/components';
10
19
 
11
20
  /**
12
21
  * Internal dependencies.
13
22
  */
14
- import { Button, InfoButton } from '../';
23
+ import { Button } from '../';
15
24
  import './style.scss';
16
25
 
17
26
  /**
@@ -19,122 +28,112 @@ import './style.scss';
19
28
  */
20
29
  import classnames from 'classnames';
21
30
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
22
- class ImageUpload extends Component {
31
+ var ImageUpload = /*#__PURE__*/function (_Component) {
23
32
  /**
24
33
  * Constructor.
25
34
  */
26
- constructor() {
27
- super(...arguments);
28
- this.state = {
29
- frame: false
30
- };
31
- }
32
-
33
- /**
34
- * Open the WP media modal.
35
- */
36
- openModal = () => {
37
- if (this.state.frame) {
38
- this.state.frame.open();
39
- return;
40
- }
41
- this.setState({
42
- frame: wp.media({
43
- title: __('Select or upload image'),
44
- button: {
45
- text: __('Select')
46
- },
47
- library: {
48
- type: 'image'
49
- },
50
- multiple: false
51
- })
52
- }, () => {
53
- this.state.frame.on('select', this.handleImageSelect);
54
- this.state.frame.open();
35
+ function ImageUpload() {
36
+ var _this;
37
+ _classCallCheck(this, ImageUpload);
38
+ _this = _callSuper(this, ImageUpload, arguments);
39
+ /**
40
+ * Open the WP media modal.
41
+ */
42
+ _defineProperty(_this, "openModal", function () {
43
+ if (_this.state.frame) {
44
+ _this.state.frame.open();
45
+ return;
46
+ }
47
+ _this.setState({
48
+ frame: wp.media({
49
+ title: __('Select or upload image'),
50
+ button: {
51
+ text: __('Select')
52
+ },
53
+ library: {
54
+ type: 'image'
55
+ },
56
+ multiple: false
57
+ })
58
+ }, function () {
59
+ _this.state.frame.on('select', _this.handleImageSelect);
60
+ _this.state.frame.open();
61
+ });
55
62
  });
56
- };
57
-
58
- /**
59
- * Update the state when an image is selected from the media modal.
60
- */
61
- handleImageSelect = () => {
62
- const {
63
- onChange
64
- } = this.props;
65
- const attachment = this.state.frame.state().get('selection').first().toJSON();
66
- onChange(attachment);
67
- };
68
-
69
- /**
70
- * Render.
71
- */
72
- render = () => {
73
- const {
74
- buttonLabel,
75
- className,
76
- disabled,
77
- help,
78
- image,
79
- info,
80
- isCovering,
81
- label,
82
- onChange,
83
- style = {}
84
- } = this.props;
85
- const classes = classnames('newspack-image-upload__image', {
86
- 'newspack-image-upload__image--has-image': image
87
- }, {
88
- 'newspack-image-upload__image--covering': isCovering
63
+ /**
64
+ * Update the state when an image is selected from the media modal.
65
+ */
66
+ _defineProperty(_this, "handleImageSelect", function () {
67
+ var onChange = _this.props.onChange;
68
+ var attachment = _this.state.frame.state().get('selection').first().toJSON();
69
+ onChange(attachment);
89
70
  });
90
- return /*#__PURE__*/_jsxs("div", {
91
- className: classnames('newspack-image-upload', className),
92
- children: [/*#__PURE__*/_jsxs("div", {
93
- className: "newspack-image-upload__header",
94
- children: [label && /*#__PURE__*/_jsx("label", {
95
- className: "newspack-image-upload__label",
71
+ /**
72
+ * Render.
73
+ */
74
+ _defineProperty(_this, "render", function () {
75
+ var _this$props = _this.props,
76
+ buttonLabel = _this$props.buttonLabel,
77
+ className = _this$props.className,
78
+ disabled = _this$props.disabled,
79
+ help = _this$props.help,
80
+ image = _this$props.image,
81
+ isCovering = _this$props.isCovering,
82
+ label = _this$props.label,
83
+ onChange = _this$props.onChange,
84
+ _this$props$style = _this$props.style,
85
+ style = _this$props$style === void 0 ? {} : _this$props$style;
86
+ var classes = classnames('newspack-image-upload__image', {
87
+ 'newspack-image-upload__image--has-image': image
88
+ }, {
89
+ 'newspack-image-upload__image--covering': isCovering
90
+ });
91
+ return /*#__PURE__*/_jsxs(BaseControl, {
92
+ __nextHasNoMarginBottom: true,
93
+ className: classnames('newspack-image-upload', className),
94
+ help: help,
95
+ children: [label && /*#__PURE__*/_jsx(BaseControl.VisualLabel, {
96
96
  children: label
97
- }), info && /*#__PURE__*/_jsx(InfoButton, {
98
- text: info
99
- })]
100
- }), /*#__PURE__*/_jsx("div", {
101
- className: classes,
102
- style: {
103
- ...style
104
- },
105
- children: image?.url ? /*#__PURE__*/_jsxs(_Fragment, {
106
- children: [/*#__PURE__*/_jsx("img", {
107
- "data-testid": "image-upload",
108
- src: image.url,
109
- alt: __('Image preview', 'newspack-plugin')
110
- }), /*#__PURE__*/_jsxs("div", {
111
- className: "newspack-image-upload__controls",
112
- children: [/*#__PURE__*/_jsx(Button, {
113
- disabled: disabled,
114
- onClick: this.openModal,
115
- isLink: true,
116
- children: __('Replace', 'newspack-plugin')
117
- }), /*#__PURE__*/_jsx("span", {
118
- className: "sep"
119
- }), /*#__PURE__*/_jsx(Button, {
120
- disabled: disabled,
121
- onClick: () => onChange(null),
122
- isLink: true,
123
- isDestructive: true,
124
- children: __('Remove', 'newspack-plugin')
97
+ }), /*#__PURE__*/_jsx("div", {
98
+ className: classes,
99
+ style: style,
100
+ children: image !== null && image !== void 0 && image.url ? /*#__PURE__*/_jsxs(_Fragment, {
101
+ children: [/*#__PURE__*/_jsx("img", {
102
+ "data-testid": "image-upload",
103
+ src: image.url,
104
+ alt: __('Image preview', 'newspack-plugin')
105
+ }), /*#__PURE__*/_jsxs("div", {
106
+ className: "newspack-image-upload__controls",
107
+ children: [/*#__PURE__*/_jsx(Button, {
108
+ disabled: disabled,
109
+ onClick: _this.openModal,
110
+ variant: "tertiary",
111
+ children: __('Replace', 'newspack-plugin')
112
+ }), /*#__PURE__*/_jsx(Button, {
113
+ disabled: disabled,
114
+ onClick: function onClick() {
115
+ return onChange(null);
116
+ },
117
+ variant: "tertiary",
118
+ isDestructive: true,
119
+ children: __('Remove', 'newspack-plugin')
120
+ })]
125
121
  })]
126
- })]
127
- }) : /*#__PURE__*/_jsx(Button, {
128
- disabled: disabled,
129
- onClick: this.openModal,
130
- isLink: true,
131
- children: buttonLabel ? buttonLabel : __('Upload', 'newspack-plugin')
132
- })
133
- }), help && /*#__PURE__*/_jsx("p", {
134
- className: "newspack-image-upload__help",
135
- children: help
136
- })]
122
+ }) : /*#__PURE__*/_jsx(Button, {
123
+ disabled: disabled,
124
+ onClick: _this.openModal,
125
+ variant: "tertiary",
126
+ children: buttonLabel ? buttonLabel : __('Upload', 'newspack-plugin')
127
+ })
128
+ })]
129
+ });
137
130
  });
138
- };
139
- }
131
+ _this.state = {
132
+ frame: false
133
+ };
134
+ return _this;
135
+ }
136
+ _inherits(ImageUpload, _Component);
137
+ return _createClass(ImageUpload);
138
+ }(Component);
140
139
  export default ImageUpload;
@@ -8,24 +8,22 @@ import { render } from '@testing-library/react';
8
8
  */
9
9
  import ImageUpload from './';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
- describe('ImageUpload', () => {
12
- it('should render an add image button', () => {
13
- const {
14
- getByText
15
- } = render(/*#__PURE__*/_jsx(ImageUpload, {}));
11
+ describe('ImageUpload', function () {
12
+ it('should render an add image button', function () {
13
+ var _render = render(/*#__PURE__*/_jsx(ImageUpload, {})),
14
+ getByText = _render.getByText;
16
15
  expect(getByText('Upload')).toBeInTheDocument();
17
16
  });
18
- it('should render replace and remove buttons if there is an image provided', () => {
19
- const image = {
17
+ it('should render replace and remove buttons if there is an image provided', function () {
18
+ var image = {
20
19
  id: 1234,
21
20
  url: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg'
22
21
  };
23
- const {
24
- getByText,
25
- getByTestId
26
- } = render(/*#__PURE__*/_jsx(ImageUpload, {
27
- image: image
28
- }));
22
+ var _render2 = render(/*#__PURE__*/_jsx(ImageUpload, {
23
+ image: image
24
+ })),
25
+ getByText = _render2.getByText,
26
+ getByTestId = _render2.getByTestId;
29
27
  expect(getByText('Remove')).toBeInTheDocument();
30
28
  expect(getByText('Replace')).toBeInTheDocument();
31
29
  expect(getByTestId('image-upload')).toBeInTheDocument();
@@ -3,45 +3,29 @@
3
3
  */
4
4
 
5
5
  @use "~@wordpress/base-styles/colors" as wp-colors;
6
+ @use "~@wordpress/base-styles/variables" as wp-vars;
6
7
 
7
8
  .newspack-image-upload {
8
- margin: 32px 0;
9
- &__header {
10
- display: flex;
11
- }
12
- &__label {
13
- margin: 0 0 8px;
14
- }
9
+ margin: wp-vars.$grid-unit-40 0;
15
10
  &__image {
16
11
  align-items: center;
12
+ background-position: center;
17
13
  background-repeat: no-repeat;
18
14
  background-size: contain;
19
- background-position: center;
20
- border: 1px dashed wp-colors.$gray-700;
21
- border-radius: 2px;
15
+ border: 1px dashed wp-colors.$gray-600;
16
+ border-radius: wp-vars.$radius-small;
22
17
  display: flex;
23
18
  justify-content: center;
24
19
  max-width: 100%;
25
- min-height: 48px;
20
+ min-height: wp-vars.$grid-unit-50;
26
21
  position: relative;
27
22
  &--covering {
28
23
  background-size: cover;
29
24
  }
30
25
  &:not(&--has-image) {
31
- .newspack-button {
32
- background: white !important;
33
- border-radius: 2px !important;
34
- padding: 4px 16px !important;
35
-
36
- &:active,
37
- &:focus,
38
- &:hover {
39
- background: white !important;
40
- }
41
-
42
- &:focus {
43
- outline-offset: -3px !important;
44
- }
26
+ .components-button {
27
+ justify-content: center;
28
+ width: calc(100% - 2px);
45
29
  }
46
30
  }
47
31
  &--has-image {
@@ -49,8 +33,8 @@
49
33
  overflow: hidden;
50
34
  &::before,
51
35
  &::after {
52
- border: 1px solid rgba(black, 0.54);
53
- border-radius: 2px;
36
+ border: 1px solid rgba(wp-colors.$black, 0.54);
37
+ border-radius: wp-vars.$radius-small;
54
38
  content: "";
55
39
  inset: 0;
56
40
  position: absolute;
@@ -66,7 +50,7 @@
66
50
  position: relative;
67
51
  }
68
52
  &::after {
69
- background: rgba(white, 0.9);
53
+ background: rgba(wp-colors.$white, 0.95);
70
54
  border-color: wp-colors.$gray-700;
71
55
  }
72
56
  &:focus-within,
@@ -80,20 +64,8 @@
80
64
  max-height: 100%;
81
65
  max-width: 100%;
82
66
  }
83
- .sep {
84
- background: transparent;
85
- display: block;
86
- height: 8px;
87
- margin: 0;
88
- width: 100%;
89
- }
90
67
  }
91
68
  }
92
- &__image + &__help {
93
- color: wp-colors.$gray-700;
94
- font-size: 12px;
95
- margin: 1em 0 0;
96
- }
97
69
  &__controls {
98
70
  align-items: center;
99
71
  display: flex;
package/dist/esm/index.js CHANGED
@@ -2,13 +2,21 @@ export { default as Accordion } from './accordion';
2
2
  export { default as ActionCard } from './action-card';
3
3
  export { default as AutocompleteTokenField } from './autocomplete-tokenfield';
4
4
  export { default as AutocompleteWithSuggestions } from './autocomplete-with-suggestions';
5
+ export { default as AutocompleteWithLatestPosts } from './autocomplete-with-latest-posts';
6
+ export { default as Badge } from './badge';
5
7
  export { default as Button } from './button';
6
- export { default as ButtonCard } from './button-card';
7
8
  export { default as BoxContrast } from './box-contrast';
8
9
  export { default as Card } from './card';
10
+ export { default as CardFeature } from './card-feature';
11
+ export { default as CardForm } from './card-form';
12
+ export { default as CardSettingsGroup } from './card-settings-group';
13
+ export { default as CardSortableList } from './card-sortable-list';
9
14
  export { default as CategoryAutocomplete } from './category-autocomplete';
10
15
  export { default as ColorPicker } from './color-picker';
16
+ export { default as ConfirmDialog } from './confirm-dialog';
11
17
  export { default as CustomSelectControl } from './custom-select-control';
18
+ export { default as DataViews } from './dataviews';
19
+ export { default as Divider } from './divider';
12
20
  export { default as FormTokenField } from './form-token-field';
13
21
  export { default as Footer } from './footer';
14
22
  export { default as Handoff } from './handoff';
@@ -41,5 +49,9 @@ export { default as withWizard } from './with-wizard';
41
49
  export { default as withWizardScreen } from './with-wizard-screen';
42
50
  export { default as Router } from './proxied-imports/router';
43
51
  export { default as hooks } from './hooks';
52
+ export { default as useConfirmDialog } from './hooks/use-confirm-dialog';
53
+ export { default as useUnsavedChangesDialog } from './hooks/use-unsaved-changes-dialog';
54
+ import * as integrationIcons from './integration-icons';
55
+ export { integrationIcons };
44
56
  export { default as utils } from './utils';
45
57
  import './style.scss';