newspack-components 2.0.3 → 2.2.0

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/copy-styles.js +1 -1
  2. package/dist/cjs/accordion/index.js +46 -0
  3. package/dist/cjs/accordion/style.scss +27 -0
  4. package/dist/cjs/action-card/index.js +72 -40
  5. package/dist/cjs/action-card/style.scss +143 -41
  6. package/dist/cjs/autocomplete-tokenfield/index.js +13 -41
  7. package/dist/cjs/autocomplete-tokenfield/style.scss +6 -6
  8. package/dist/cjs/autocomplete-with-suggestions/index.js +33 -53
  9. package/dist/cjs/autocomplete-with-suggestions/style.scss +27 -27
  10. package/dist/cjs/button/index.js +1 -20
  11. package/dist/cjs/button/style.scss +3 -344
  12. package/dist/cjs/button-card/index.js +11 -15
  13. package/dist/cjs/button-card/style.scss +65 -35
  14. package/dist/cjs/card/index.js +4 -9
  15. package/dist/cjs/card/style.scss +47 -63
  16. package/dist/cjs/category-autocomplete/index.js +66 -47
  17. package/dist/cjs/category-autocomplete/style.scss +20 -24
  18. package/dist/cjs/color-picker/index.js +16 -48
  19. package/dist/cjs/color-picker/style.scss +20 -163
  20. package/dist/cjs/consts.js +5 -3
  21. package/dist/cjs/custom-select-control/index.js +1 -9
  22. package/dist/cjs/custom-select-control/style.scss +14 -45
  23. package/dist/cjs/date-range-picker/index.js +1 -10
  24. package/dist/cjs/date-range-picker/style.scss +12 -12
  25. package/dist/cjs/footer/index.js +24 -22
  26. package/dist/cjs/footer/style.scss +13 -14
  27. package/dist/cjs/form-token-field/index.js +3 -11
  28. package/dist/cjs/form-token-field/style.scss +9 -105
  29. package/dist/cjs/global-notices/index.js +3 -9
  30. package/dist/cjs/grid/index.js +1 -8
  31. package/dist/cjs/grid/style.scss +19 -6
  32. package/dist/cjs/handoff/index.js +15 -24
  33. package/dist/cjs/handoff-message/index.js +50 -0
  34. package/dist/cjs/hooks/index.js +1 -7
  35. package/dist/cjs/hooks/useObjectState.js +7 -13
  36. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  37. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  38. package/dist/cjs/hooks/usePrompt.js +1 -13
  39. package/dist/cjs/image-upload/index.js +22 -20
  40. package/dist/cjs/image-upload/index.test.js +0 -5
  41. package/dist/cjs/image-upload/style.scss +12 -17
  42. package/dist/cjs/index.js +31 -93
  43. package/dist/cjs/info-button/index.js +3 -11
  44. package/dist/cjs/info-button/style.scss +1 -3
  45. package/dist/cjs/modal/index.js +1 -12
  46. package/dist/cjs/modal/style.scss +20 -132
  47. package/dist/cjs/newspack-icon/index.js +5 -11
  48. package/dist/cjs/newspack-icon/style.scss +17 -2
  49. package/dist/cjs/newspack-logo/index.js +1 -9
  50. package/dist/cjs/newspack-logo/style.scss +3 -3
  51. package/dist/cjs/notice/index.js +8 -16
  52. package/dist/cjs/notice/style.scss +60 -19
  53. package/dist/cjs/patrons-logo/index.js +3 -11
  54. package/dist/cjs/plugin-installer/index.js +37 -37
  55. package/dist/cjs/plugin-installer/style.scss +5 -5
  56. package/dist/cjs/plugin-settings/SettingsSection.js +71 -59
  57. package/dist/cjs/plugin-settings/index.js +71 -50
  58. package/dist/cjs/plugin-settings/style.scss +7 -0
  59. package/dist/cjs/plugin-toggle/index.js +60 -32
  60. package/dist/cjs/plugin-toggle/style.scss +2 -2
  61. package/dist/cjs/popover/index.js +1 -11
  62. package/dist/cjs/popover/style.scss +20 -17
  63. package/dist/cjs/position-control/index.js +113 -0
  64. package/dist/cjs/position-control/style.scss +66 -0
  65. package/dist/cjs/progress-bar/index.js +2 -9
  66. package/dist/cjs/progress-bar/index.test.js +2 -7
  67. package/dist/cjs/progress-bar/style.scss +4 -4
  68. package/dist/cjs/proxied-imports/router.js +0 -3
  69. package/dist/cjs/radio-control/index.js +1 -11
  70. package/dist/cjs/radio-control/style.scss +10 -11
  71. package/dist/cjs/section-header/index.js +47 -19
  72. package/dist/cjs/section-header/style.scss +22 -1
  73. package/dist/cjs/select-control/ButtonGroupControl.js +11 -20
  74. package/dist/cjs/select-control/GroupedSelectControl.js +42 -45
  75. package/dist/cjs/select-control/index.js +6 -14
  76. package/dist/cjs/select-control/style.scss +47 -88
  77. package/dist/cjs/settings/MinMaxSetting.js +6 -8
  78. package/dist/cjs/settings/SettingsCard.js +9 -8
  79. package/dist/cjs/settings/SettingsSection.js +5 -8
  80. package/dist/cjs/settings/index.js +0 -6
  81. package/dist/cjs/settings/style.scss +32 -4
  82. package/dist/cjs/steps-list/index.js +52 -0
  83. package/dist/cjs/steps-list/style.scss +11 -0
  84. package/dist/cjs/steps-list-item/index.js +56 -0
  85. package/dist/cjs/steps-list-item/style.scss +47 -0
  86. package/dist/cjs/style-card/index.js +15 -18
  87. package/dist/cjs/style-card/style.scss +19 -18
  88. package/dist/cjs/style.scss +43 -0
  89. package/dist/cjs/tabbed-navigation/index.js +27 -31
  90. package/dist/cjs/tabbed-navigation/style.scss +58 -37
  91. package/dist/cjs/text-control/index.js +6 -19
  92. package/dist/cjs/text-control/style.scss +0 -126
  93. package/dist/cjs/utils/index.js +10 -5
  94. package/dist/cjs/waiting/index.js +9 -33
  95. package/dist/cjs/waiting/style.scss +9 -20
  96. package/dist/cjs/web-preview/index.js +30 -57
  97. package/dist/cjs/web-preview/style.scss +41 -34
  98. package/dist/cjs/with-wizard/index.js +55 -33
  99. package/dist/cjs/with-wizard/style.scss +77 -124
  100. package/dist/cjs/with-wizard-screen/index.js +28 -38
  101. package/dist/cjs/with-wizard-screen/style.scss +75 -125
  102. package/dist/cjs/wizard/components/WizardError.js +74 -0
  103. package/dist/cjs/wizard/index.js +131 -0
  104. package/dist/cjs/wizard/store/index.js +165 -0
  105. package/dist/cjs/wizard/store/utils.js +26 -0
  106. package/dist/cjs/wizard/style.scss +148 -0
  107. package/dist/esm/accordion/index.js +38 -0
  108. package/dist/esm/accordion/style.scss +27 -0
  109. package/dist/esm/action-card/index.js +75 -37
  110. package/dist/esm/action-card/style.scss +143 -41
  111. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  112. package/dist/esm/autocomplete-tokenfield/style.scss +6 -6
  113. package/dist/esm/autocomplete-with-suggestions/index.js +31 -43
  114. package/dist/esm/autocomplete-with-suggestions/style.scss +27 -27
  115. package/dist/esm/button/index.js +2 -14
  116. package/dist/esm/button/style.scss +3 -344
  117. package/dist/esm/button-card/index.js +12 -11
  118. package/dist/esm/button-card/style.scss +65 -35
  119. package/dist/esm/card/index.js +5 -6
  120. package/dist/esm/card/style.scss +47 -63
  121. package/dist/esm/category-autocomplete/index.js +68 -41
  122. package/dist/esm/category-autocomplete/style.scss +20 -24
  123. package/dist/esm/color-picker/index.js +17 -38
  124. package/dist/esm/color-picker/style.scss +20 -163
  125. package/dist/esm/consts.js +3 -2
  126. package/dist/esm/custom-select-control/index.js +2 -5
  127. package/dist/esm/custom-select-control/style.scss +14 -45
  128. package/dist/esm/date-range-picker/index.js +1 -3
  129. package/dist/esm/date-range-picker/style.scss +12 -12
  130. package/dist/esm/footer/index.js +22 -16
  131. package/dist/esm/footer/style.scss +13 -14
  132. package/dist/esm/form-token-field/index.js +4 -7
  133. package/dist/esm/form-token-field/style.scss +9 -105
  134. package/dist/esm/global-notices/index.js +3 -7
  135. package/dist/esm/grid/index.js +2 -5
  136. package/dist/esm/grid/style.scss +19 -6
  137. package/dist/esm/handoff/index.js +10 -21
  138. package/dist/esm/handoff-message/index.js +45 -0
  139. package/dist/esm/hooks/index.js +0 -2
  140. package/dist/esm/hooks/useObjectState.js +3 -8
  141. package/dist/esm/hooks/useObjectState.test.js +0 -3
  142. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  143. package/dist/esm/hooks/usePrompt.js +1 -8
  144. package/dist/esm/image-upload/index.js +18 -17
  145. package/dist/esm/image-upload/style.scss +12 -17
  146. package/dist/esm/index.js +7 -8
  147. package/dist/esm/info-button/index.js +4 -6
  148. package/dist/esm/info-button/style.scss +1 -3
  149. package/dist/esm/modal/index.js +2 -8
  150. package/dist/esm/modal/style.scss +20 -132
  151. package/dist/esm/newspack-icon/index.js +6 -7
  152. package/dist/esm/newspack-icon/style.scss +17 -2
  153. package/dist/esm/newspack-logo/index.js +2 -5
  154. package/dist/esm/newspack-logo/style.scss +3 -3
  155. package/dist/esm/notice/index.js +11 -10
  156. package/dist/esm/notice/style.scss +60 -19
  157. package/dist/esm/patrons-logo/index.js +3 -5
  158. package/dist/esm/plugin-installer/index.js +37 -40
  159. package/dist/esm/plugin-installer/style.scss +5 -5
  160. package/dist/esm/plugin-settings/SettingsSection.js +71 -56
  161. package/dist/esm/plugin-settings/index.js +70 -52
  162. package/dist/esm/plugin-settings/style.scss +7 -0
  163. package/dist/esm/plugin-toggle/index.js +59 -34
  164. package/dist/esm/plugin-toggle/style.scss +2 -2
  165. package/dist/esm/popover/index.js +3 -6
  166. package/dist/esm/popover/style.scss +20 -17
  167. package/dist/esm/position-control/index.js +109 -0
  168. package/dist/esm/position-control/style.scss +66 -0
  169. package/dist/esm/progress-bar/index.js +2 -7
  170. package/dist/esm/progress-bar/index.test.js +2 -1
  171. package/dist/esm/progress-bar/style.scss +4 -4
  172. package/dist/esm/proxied-imports/router.js +1 -0
  173. package/dist/esm/radio-control/index.js +3 -6
  174. package/dist/esm/radio-control/style.scss +10 -11
  175. package/dist/esm/section-header/index.js +47 -16
  176. package/dist/esm/section-header/style.scss +22 -1
  177. package/dist/esm/select-control/ButtonGroupControl.js +12 -14
  178. package/dist/esm/select-control/GroupedSelectControl.js +38 -36
  179. package/dist/esm/select-control/index.js +7 -8
  180. package/dist/esm/select-control/style.scss +47 -88
  181. package/dist/esm/settings/MinMaxSetting.js +4 -5
  182. package/dist/esm/settings/SettingsCard.js +9 -5
  183. package/dist/esm/settings/SettingsSection.js +5 -7
  184. package/dist/esm/settings/style.scss +32 -4
  185. package/dist/esm/steps-list/index.js +43 -0
  186. package/dist/esm/steps-list/style.scss +11 -0
  187. package/dist/esm/steps-list-item/index.js +48 -0
  188. package/dist/esm/steps-list-item/style.scss +47 -0
  189. package/dist/esm/style-card/index.js +13 -13
  190. package/dist/esm/style-card/style.scss +19 -18
  191. package/dist/esm/style.scss +43 -0
  192. package/dist/esm/tabbed-navigation/index.js +30 -28
  193. package/dist/esm/tabbed-navigation/style.scss +58 -37
  194. package/dist/esm/text-control/index.js +2 -12
  195. package/dist/esm/text-control/style.scss +0 -126
  196. package/dist/esm/utils/index.js +9 -3
  197. package/dist/esm/waiting/index.js +11 -27
  198. package/dist/esm/waiting/style.scss +9 -20
  199. package/dist/esm/web-preview/index.js +21 -49
  200. package/dist/esm/web-preview/style.scss +41 -34
  201. package/dist/esm/with-wizard/index.js +53 -36
  202. package/dist/esm/with-wizard/style.scss +77 -124
  203. package/dist/esm/with-wizard-screen/index.js +26 -32
  204. package/dist/esm/with-wizard-screen/style.scss +75 -125
  205. package/dist/esm/wizard/components/WizardError.js +69 -0
  206. package/dist/esm/wizard/index.js +126 -0
  207. package/dist/esm/wizard/store/index.js +155 -0
  208. package/dist/esm/wizard/store/utils.js +17 -0
  209. package/dist/esm/wizard/style.scss +148 -0
  210. package/package.json +4 -4
  211. package/src/accordion/index.js +32 -0
  212. package/src/accordion/style.scss +27 -0
  213. package/src/action-card/index.js +70 -25
  214. package/src/action-card/style.scss +143 -41
  215. package/src/autocomplete-tokenfield/index.js +1 -1
  216. package/src/autocomplete-tokenfield/style.scss +6 -6
  217. package/src/autocomplete-with-suggestions/index.js +4 -2
  218. package/src/autocomplete-with-suggestions/style.scss +27 -27
  219. package/src/button/index.js +2 -9
  220. package/src/button/style.scss +3 -344
  221. package/src/button-card/index.js +19 -5
  222. package/src/button-card/style.scss +65 -35
  223. package/src/card/index.js +4 -0
  224. package/src/card/style.scss +47 -63
  225. package/src/category-autocomplete/index.js +53 -18
  226. package/src/category-autocomplete/style.scss +20 -24
  227. package/src/color-picker/index.js +16 -22
  228. package/src/color-picker/style.scss +20 -163
  229. package/src/consts.js +2 -1
  230. package/src/custom-select-control/style.scss +14 -45
  231. package/src/date-range-picker/style.scss +12 -12
  232. package/src/footer/index.js +20 -9
  233. package/src/footer/style.scss +13 -14
  234. package/src/form-token-field/index.js +3 -8
  235. package/src/form-token-field/style.scss +9 -105
  236. package/src/global-notices/index.js +1 -1
  237. package/src/grid/style.scss +19 -6
  238. package/src/handoff/index.js +10 -15
  239. package/src/handoff-message/index.js +39 -0
  240. package/src/hooks/useObjectState.js +2 -1
  241. package/src/image-upload/index.js +9 -3
  242. package/src/image-upload/style.scss +12 -17
  243. package/src/index.js +7 -7
  244. package/src/info-button/style.scss +1 -3
  245. package/src/modal/index.js +2 -5
  246. package/src/modal/style.scss +20 -132
  247. package/src/newspack-icon/index.js +7 -2
  248. package/src/newspack-icon/style.scss +17 -2
  249. package/src/newspack-logo/style.scss +3 -3
  250. package/src/notice/index.js +9 -1
  251. package/src/notice/style.scss +60 -19
  252. package/src/plugin-installer/index.js +17 -4
  253. package/src/plugin-installer/style.scss +5 -5
  254. package/src/plugin-settings/SettingsSection.js +59 -27
  255. package/src/plugin-settings/index.js +29 -8
  256. package/src/plugin-settings/style.scss +7 -0
  257. package/src/plugin-toggle/index.js +37 -12
  258. package/src/plugin-toggle/style.scss +2 -2
  259. package/src/popover/style.scss +20 -17
  260. package/src/position-control/index.js +122 -0
  261. package/src/position-control/style.scss +66 -0
  262. package/src/progress-bar/style.scss +4 -4
  263. package/src/radio-control/style.scss +10 -11
  264. package/src/section-header/index.js +41 -5
  265. package/src/section-header/style.scss +22 -1
  266. package/src/select-control/ButtonGroupControl.js +15 -5
  267. package/src/select-control/GroupedSelectControl.js +28 -25
  268. package/src/select-control/index.js +6 -3
  269. package/src/select-control/style.scss +47 -88
  270. package/src/settings/MinMaxSetting.js +2 -1
  271. package/src/settings/SettingsCard.js +9 -7
  272. package/src/settings/SettingsSection.js +4 -4
  273. package/src/settings/style.scss +32 -4
  274. package/src/steps-list/index.js +39 -0
  275. package/src/steps-list/style.scss +11 -0
  276. package/src/steps-list-item/index.js +40 -0
  277. package/src/steps-list-item/style.scss +47 -0
  278. package/src/style-card/index.js +16 -27
  279. package/src/style-card/style.scss +19 -18
  280. package/src/style.scss +43 -0
  281. package/src/tabbed-navigation/index.js +20 -24
  282. package/src/tabbed-navigation/style.scss +58 -37
  283. package/src/text-control/index.js +1 -2
  284. package/src/text-control/style.scss +0 -126
  285. package/src/utils/index.js +9 -0
  286. package/src/waiting/index.js +7 -18
  287. package/src/waiting/style.scss +9 -20
  288. package/src/web-preview/index.js +13 -34
  289. package/src/web-preview/style.scss +41 -34
  290. package/src/with-wizard/index.js +7 -5
  291. package/src/with-wizard/style.scss +77 -124
  292. package/src/with-wizard-screen/index.js +17 -17
  293. package/src/with-wizard-screen/style.scss +75 -125
  294. package/src/wizard/components/WizardError.js +57 -0
  295. package/src/wizard/index.js +145 -0
  296. package/src/wizard/store/index.js +132 -0
  297. package/src/wizard/store/utils.js +16 -0
  298. package/dist/cjs/wizard-pagination/index.js +0 -71
  299. package/dist/cjs/wizard-pagination/style.scss +0 -74
  300. package/dist/esm/wizard-pagination/index.js +0 -57
  301. package/dist/esm/wizard-pagination/style.scss +0 -74
  302. package/src/button-group/index.js +0 -35
  303. package/src/button-group/style.scss +0 -73
  304. package/src/checkbox-control/index.js +0 -38
  305. package/src/checkbox-control/style.scss +0 -78
  306. package/src/preview-box/index.js +0 -18
  307. package/src/preview-box/style.scss +0 -18
  308. package/src/textarea-control/index.js +0 -32
  309. package/src/textarea-control/style.scss +0 -76
  310. package/src/toggle-control/index.js +0 -38
  311. package/src/toggle-control/style.scss +0 -74
  312. package/src/toggle-group/index.js +0 -43
  313. package/src/toggle-group/style.scss +0 -28
  314. package/src/wizard-pagination/index.js +0 -59
  315. package/src/wizard-pagination/style.scss +0 -74
@@ -1,24 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _lodash = require("lodash");
13
-
9
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
14
10
  var _element = require("@wordpress/element");
15
-
16
11
  var _components = require("@wordpress/components");
17
-
18
12
  require("./style.scss");
19
-
20
13
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
21
-
22
14
  /**
23
15
  * External dependencies
24
16
  */
@@ -33,10 +25,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
33
25
 
34
26
  /**
35
27
  * An multi-selecting, api-driven autocomplete input suitable for use in block attributes.
36
- */
37
- class AutocompleteTokenField extends _element.Component {
28
+ */class AutocompleteTokenField extends _element.Component {
38
29
  constructor(props) {
39
30
  super(props);
31
+ /**
32
+ * If the component has tokens passed in props, it should fetch info after it mounts.
33
+ */
40
34
  (0, _defineProperty2.default)(this, "isFetchingInfoOnLoad", () => {
41
35
  const {
42
36
  tokens,
@@ -49,13 +43,8 @@ class AutocompleteTokenField extends _element.Component {
49
43
  validValues: {},
50
44
  loading: this.isFetchingInfoOnLoad()
51
45
  };
52
- this.debouncedUpdateSuggestions = (0, _lodash.debounce)(this.updateSuggestions, 500);
46
+ this.debouncedUpdateSuggestions = (0, _debounce.default)(this.updateSuggestions, 500);
53
47
  }
54
- /**
55
- * If the component has tokens passed in props, it should fetch info after it mounts.
56
- */
57
-
58
-
59
48
  /**
60
49
  * When the component loads, fetch information about the tokens so we can populate
61
50
  * the tokens with the correct labels.
@@ -80,23 +69,21 @@ class AutocompleteTokenField extends _element.Component {
80
69
  });
81
70
  }
82
71
  }
72
+
83
73
  /**
84
74
  * Clean up any unfinished autocomplete api call requests.
85
75
  */
86
-
87
-
88
76
  componentWillUnmount() {
89
77
  delete this.suggestionsRequest;
90
78
  this.debouncedUpdateSuggestions.cancel();
91
79
  }
80
+
92
81
  /**
93
82
  * Get a list of labels for input values.
94
83
  *
95
84
  * @param {Array} values Array of values (ids, etc.).
96
85
  * @return {Array} array of valid labels corresponding to the values.
97
86
  */
98
-
99
-
100
87
  getLabelsForValues(values) {
101
88
  const {
102
89
  validValues
@@ -105,31 +92,26 @@ class AutocompleteTokenField extends _element.Component {
105
92
  if (!value) {
106
93
  return accumulator;
107
94
  }
108
-
109
95
  if (value.label) {
110
96
  return [...accumulator, value.label];
111
97
  }
112
-
113
98
  return validValues[value] ? [...accumulator, validValues[value]] : accumulator;
114
99
  }, []);
115
100
  }
101
+
116
102
  /**
117
103
  * Get a list of values for input labels.
118
104
  *
119
105
  * @param {Array} labels Array of labels from the tokens.
120
106
  * @return {Array} Array of valid values corresponding to the labels.
121
107
  */
122
-
123
-
124
108
  getValuesForLabels(labels) {
125
109
  const {
126
110
  returnFullObjects
127
111
  } = this.props; // If this prop is passed, return both the value and label. Otherwise, return just the label.
128
-
129
112
  const {
130
113
  validValues
131
114
  } = this.state;
132
-
133
115
  if (returnFullObjects) {
134
116
  return labels.reduce((acc, label) => {
135
117
  Object.keys(validValues).forEach(key => {
@@ -143,25 +125,21 @@ class AutocompleteTokenField extends _element.Component {
143
125
  return acc;
144
126
  }, []);
145
127
  }
146
-
147
128
  return labels.map(label => Object.keys(validValues).find(key => validValues[key] === label));
148
129
  }
130
+
149
131
  /**
150
132
  * Refresh the autocomplete dropdown.
151
133
  *
152
134
  * @param {string} input Input to fetch suggestions for
153
135
  */
154
-
155
-
156
136
  updateSuggestions(input) {
157
137
  const {
158
138
  fetchSuggestions
159
139
  } = this.props;
160
-
161
140
  if (!fetchSuggestions) {
162
141
  return;
163
142
  }
164
-
165
143
  this.setState({
166
144
  loading: true
167
145
  }, () => {
@@ -173,7 +151,6 @@ class AutocompleteTokenField extends _element.Component {
173
151
  if (this.suggestionsRequest !== request) {
174
152
  return;
175
153
  }
176
-
177
154
  const currentSuggestions = [...suggestions];
178
155
  const currentValidValues = {};
179
156
  suggestions.forEach(suggestion => {
@@ -194,37 +171,34 @@ class AutocompleteTokenField extends _element.Component {
194
171
  this.suggestionsRequest = request;
195
172
  });
196
173
  }
174
+
197
175
  /**
198
176
  * When a token is selected, we need to convert the string label into a recognized value suitable for saving as an attribute.
199
177
  *
200
178
  * @param {Array} tokenStrings An array of token label strings.
201
179
  */
202
-
203
-
204
180
  handleOnChange(tokenStrings) {
205
181
  const {
206
182
  onChange
207
183
  } = this.props;
208
184
  onChange(this.getValuesForLabels(tokenStrings));
209
185
  }
186
+
210
187
  /**
211
188
  * To populate the tokens, we need to convert the values into a human-readable label.
212
189
  *
213
190
  * @return {Array} An array of token label strings.
214
191
  */
215
-
216
-
217
192
  getTokens() {
218
193
  const {
219
194
  tokens
220
195
  } = this.props;
221
196
  return this.getLabelsForValues(tokens);
222
197
  }
198
+
223
199
  /**
224
200
  * Render.
225
201
  */
226
-
227
-
228
202
  render() {
229
203
  const {
230
204
  help,
@@ -250,8 +224,6 @@ class AutocompleteTokenField extends _element.Component {
250
224
  })]
251
225
  });
252
226
  }
253
-
254
227
  }
255
-
256
228
  var _default = AutocompleteTokenField;
257
229
  exports.default = _default;
@@ -2,16 +2,16 @@
2
2
  * Autocomplete Token Field
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
7
6
 
8
7
  .newspack-autocomplete-tokenfield {
9
8
  position: relative;
10
9
 
11
10
  .components-spinner {
11
+ margin: 8px;
12
12
  position: absolute;
13
- right: 1rem;
14
- top: 1rem;
13
+ right: 0;
14
+ top: calc( 1.4em + 8px );
15
15
  }
16
16
 
17
17
  /* Workaround for hard-coded help text in FormTokenField. */
@@ -27,7 +27,7 @@
27
27
  }
28
28
 
29
29
  .newspack-autocomplete-tokenfield__help {
30
- color: $gray-700;
30
+ color: wp-colors.$gray-700;
31
31
  font-size: inherit;
32
32
  margin-top: 0;
33
33
  }
@@ -38,6 +38,6 @@
38
38
  }
39
39
 
40
40
  .components-button:focus:not( :disabled ) {
41
- box-shadow: inset 0 0 0 2px $primary-500;
41
+ box-shadow: inset 0 0 0 var( --wp-admin-border-width-focus ) var( --wp-admin-theme-color );
42
42
  }
43
43
  }
@@ -1,36 +1,27 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
11
-
12
9
  var _components = require("@wordpress/components");
13
-
14
10
  var _htmlEntities = require("@wordpress/html-entities");
15
-
16
11
  var _element = require("@wordpress/element");
17
-
18
12
  var _i18n = require("@wordpress/i18n");
19
-
20
13
  var _url = require("@wordpress/url");
21
-
22
14
  var _ = require("../");
23
-
24
15
  require("./style.scss");
25
-
26
16
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
27
-
28
17
  /**
29
18
  * WordPress dependencies
30
19
  */
31
20
  const __ = _i18n.__,
32
- _x = _i18n._x;
33
-
21
+ _x = _i18n._x;
22
+ /**
23
+ * External dependencies.
24
+ */
34
25
  const AutocompleteWithSuggestions = _ref => {
35
26
  let {
36
27
  fetchSavedPosts = false,
@@ -63,7 +54,6 @@ const AutocompleteWithSuggestions = _ref => {
63
54
  selectedPost = 0,
64
55
  // Legacy prop when single-select was the only option.
65
56
  suggestionsToFetch = 10 // Number of suggestions to fetch per query.
66
-
67
57
  } = _ref;
68
58
  const [isLoading, setIsLoading] = (0, _element.useState)(true);
69
59
  const [isLoadingMore, setIsLoadingMore] = (0, _element.useState)(false);
@@ -71,20 +61,17 @@ const AutocompleteWithSuggestions = _ref => {
71
61
  const [maxSuggestions, setMaxSuggestions] = (0, _element.useState)(0);
72
62
  const [postTypeToSearch, setPostTypeToSearch] = (0, _element.useState)(postTypes[0].slug);
73
63
  const classNames = ['newspack-autocomplete-with-suggestions'];
74
-
75
64
  if (hideHelp) {
76
65
  classNames.push('hide-help');
77
66
  }
67
+
78
68
  /**
79
69
  * Fetch recent posts to show as suggestions.
80
70
  */
81
-
82
-
83
71
  (0, _element.useEffect)(() => {
84
72
  if (onPostTypeChange) {
85
73
  onPostTypeChange(postTypeToSearch);
86
74
  }
87
-
88
75
  setIsLoading(true);
89
76
  handleFetchSuggestions(null, 0, postTypeToSearch).then(_suggestions => {
90
77
  if (0 < _suggestions.length) {
@@ -92,10 +79,10 @@ const AutocompleteWithSuggestions = _ref => {
92
79
  }
93
80
  }).finally(() => setIsLoading(false));
94
81
  }, [postTypeToSearch]);
82
+
95
83
  /**
96
84
  * Fetch more suggestions.
97
85
  */
98
-
99
86
  (0, _element.useEffect)(() => {
100
87
  if (isLoadingMore) {
101
88
  handleFetchSuggestions(null, suggestions.length, postTypeToSearch).then(_suggestions => {
@@ -105,17 +92,16 @@ const AutocompleteWithSuggestions = _ref => {
105
92
  }).finally(() => setIsLoadingMore(false));
106
93
  }
107
94
  }, [isLoadingMore]);
95
+
108
96
  /**
109
97
  * If passed a `fetchSavedPosts` prop, use that, otherwise, build it based on the selected post type.
110
98
  */
111
-
112
99
  const handleFetchSaved = fetchSavedPosts ? fetchSavedPosts : async function () {
113
100
  let postIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
114
101
  let searchSlug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
115
102
  const postTypeSlug = searchSlug || postTypeToSearch;
116
103
  const endpoint = 'post' === postTypeSlug || 'page' === postTypeSlug ? postTypeSlug + 's' // Default post type endpoints are plural.
117
104
  : postTypeSlug; // Custom post type endpoints are singular.
118
-
119
105
  const posts = await (0, _apiFetch.default)({
120
106
  path: (0, _url.addQueryArgs)('/wp/v2/' + endpoint, {
121
107
  per_page: 100,
@@ -128,10 +114,10 @@ const AutocompleteWithSuggestions = _ref => {
128
114
  label: (0, _htmlEntities.decodeEntities)(post.title) || __('(no title)', 'newspack')
129
115
  }));
130
116
  };
117
+
131
118
  /**
132
119
  * If passed a `fetchSuggestions` prop, use that, otherwise, build it based on the selected post type.
133
120
  */
134
-
135
121
  const handleFetchSuggestions = fetchSuggestions ? fetchSuggestions : async function () {
136
122
  let search = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
137
123
  let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -139,7 +125,6 @@ const AutocompleteWithSuggestions = _ref => {
139
125
  const postTypeSlug = searchSlug || postTypeToSearch;
140
126
  const endpoint = 'post' === postTypeSlug || 'page' === postTypeSlug ? postTypeSlug + 's' // Default post type endpoints are plural.
141
127
  : postTypeSlug; // Custom post type endpoints are singular.
142
-
143
128
  const response = await (0, _apiFetch.default)({
144
129
  parse: false,
145
130
  path: (0, _url.addQueryArgs)('/wp/v2/' + endpoint, {
@@ -151,32 +136,33 @@ const AutocompleteWithSuggestions = _ref => {
151
136
  });
152
137
  const total = parseInt(response.headers.get('x-wp-total') || 0);
153
138
  const posts = await response.json();
154
- setMaxSuggestions(total); // Format suggestions for FormTokenField display.
139
+ setMaxSuggestions(total);
155
140
 
141
+ // Format suggestions for FormTokenField display.
156
142
  return posts.reduce((acc, post) => {
157
143
  acc.push({
158
144
  value: parseInt(post.id),
159
- label: (0, _htmlEntities.decodeEntities)(post === null || post === void 0 ? void 0 : post.title.rendered) || __('(no title)', 'newspack')
145
+ label: (0, _htmlEntities.decodeEntities)(post?.title.rendered) || __('(no title)', 'newspack')
160
146
  });
161
147
  return acc;
162
148
  }, []);
163
149
  };
150
+
164
151
  /**
165
152
  * Intercept onChange callback so we can decide whether to allow multiple selections.
166
153
  */
167
-
168
154
  const handleOnChange = _selections => {
169
155
  // If only allowing one selection, just return the one selected item.
170
156
  if (!multiSelect) {
171
157
  return onChange(_selections);
172
- } // Handle legacy `selectedPost` prop.
173
-
158
+ }
174
159
 
175
- const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems]; // Loop through new selections to determine whether to add or remove them.
160
+ // Handle legacy `selectedPost` prop.
161
+ const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems];
176
162
 
163
+ // Loop through new selections to determine whether to add or remove them.
177
164
  _selections.forEach(_selection => {
178
165
  const existingSelection = selections.findIndex(selection => parseInt(selection.value) === parseInt(_selection.value));
179
-
180
166
  if (-1 < existingSelection) {
181
167
  // If the selection is already selected, remove it.
182
168
  selections.splice(existingSelection, 1);
@@ -184,23 +170,25 @@ const AutocompleteWithSuggestions = _ref => {
184
170
  // Otherwise, add it.
185
171
  selections.push(_selection);
186
172
  }
187
- }); // Include currently selected post type in selection results.
188
-
173
+ });
189
174
 
190
- onChange(selections.map(selection => ({ ...selection,
175
+ // Include currently selected post type in selection results.
176
+ onChange(selections.map(selection => ({
177
+ ...selection,
191
178
  postType: postTypeToSearch
192
179
  })));
193
180
  };
181
+
194
182
  /**
195
183
  * Render selected item(s) for this component. Clicking on a selection deselects it.
196
184
  */
197
-
198
-
199
185
  const renderSelections = () => {
200
186
  // Handle legacy `selectedPost` prop.
201
187
  const selections = selectedPost ? [...selectedItems, selectedPost] : selectedItems;
202
- const selectedMessage = multiSelect ? (0, _i18n.sprintf)( // Translators: %1: the length of selections. %2: the selection leabel.
203
- __('%1$s %2$s selected', 'newspack'), selections.length, selections.length > 1 ? postTypeLabelPlural : postTypeLabel) : // Translators: %s: The label for the selection.
188
+ const selectedMessage = multiSelect ? (0, _i18n.sprintf)(
189
+ // Translators: %1: the length of selections. %2: the selection leabel.
190
+ __('%1$s %2$s selected', 'newspack'), selections.length, selections.length > 1 ? postTypeLabelPlural : postTypeLabel) :
191
+ // Translators: %s: The label for the selection.
204
192
  (0, _i18n.sprintf)(__('Selected %s', 'newspack'), postTypeLabel);
205
193
  return (0, _jsxRuntime.jsxs)("div", {
206
194
  className: "newspack-autocomplete-with-suggestions__selected-items",
@@ -209,6 +197,7 @@ const AutocompleteWithSuggestions = _ref => {
209
197
  children: [selectedMessage, 1 < selections.length && _x(' – ', 'separator character', 'newspack'), 1 < selections.length && (0, _jsxRuntime.jsx)(_components.Button, {
210
198
  onClick: () => onChange([]),
211
199
  isLink: true,
200
+ isDestructive: true,
212
201
  children: __('Clear all', 'newspack')
213
202
  })]
214
203
  }), selections.map(selection => (0, _jsxRuntime.jsx)(_components.Button, {
@@ -219,14 +208,14 @@ const AutocompleteWithSuggestions = _ref => {
219
208
  }, selection.value))]
220
209
  });
221
210
  };
211
+
222
212
  /**
223
213
  * Render post type select dropdown.
224
214
  */
225
-
226
-
227
215
  const renderPostTypeSelect = () => {
228
216
  return (0, _jsxRuntime.jsx)(_components.SelectControl, {
229
- label: (0, _i18n.sprintf)( // Translators: %s: The name of the type.
217
+ label: (0, _i18n.sprintf)(
218
+ // Translators: %s: The name of the type.
230
219
  __('%s type', 'newspack'), postTypeLabel.charAt(0).toUpperCase() + postTypeLabel.slice(1)),
231
220
  value: postTypeToSearch,
232
221
  options: postTypes.map(postTypeOption => ({
@@ -236,35 +225,32 @@ const AutocompleteWithSuggestions = _ref => {
236
225
  onChange: _postType => setPostTypeToSearch(_postType)
237
226
  });
238
227
  };
228
+
239
229
  /**
240
230
  * Render a single suggestion object that can be clicked to select it immediately.
241
231
  *
242
232
  * @param {Object} suggestion Suggestion object with value and label keys.
243
233
  */
244
-
245
-
246
234
  const renderSuggestion = suggestion => {
247
235
  if (multiSelect) {
248
236
  const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems];
249
- const isSelected = !!selections.find(_selection => parseInt(_selection.value) === parseInt(suggestion.value));
237
+ const isSelected = !!selections.find(_selection => parseInt(_selection.value) === parseInt(suggestion.value) && _selection.label === suggestion.label);
250
238
  return (0, _jsxRuntime.jsx)(_components.CheckboxControl, {
251
239
  checked: isSelected,
252
240
  onChange: () => handleOnChange([suggestion]),
253
241
  label: suggestion.label
254
242
  }, suggestion.value);
255
243
  }
256
-
257
244
  return (0, _jsxRuntime.jsx)(_components.Button, {
258
245
  isLink: true,
259
246
  onClick: () => handleOnChange([suggestion]),
260
247
  children: suggestion.label
261
248
  }, suggestion.value);
262
249
  };
250
+
263
251
  /**
264
252
  * Render a list of suggestions that can be clicked to select instead of searching by title.
265
253
  */
266
-
267
-
268
254
  const renderSuggestions = () => {
269
255
  if (isLoading) {
270
256
  return (0, _jsxRuntime.jsx)("div", {
@@ -272,18 +258,14 @@ const AutocompleteWithSuggestions = _ref => {
272
258
  children: (0, _jsxRuntime.jsx)(_components.Spinner, {})
273
259
  });
274
260
  }
275
-
276
261
  if (0 === suggestions.length) {
277
262
  return null;
278
263
  }
279
-
280
264
  const className = multiSelect ? 'newspack-autocomplete-with-suggestions__search-suggestions-multiselect' : 'newspack-autocomplete-with-suggestions__search-suggestions';
281
265
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
282
266
  children: [!hideHelp && (0, _jsxRuntime.jsx)("p", {
283
267
  className: "newspack-autocomplete-with-suggestions__label",
284
- children:
285
- /* Translators: %s: the name of a post type. */
286
- (0, _i18n.sprintf)(__('Or, select a recent %s:', 'newspack'), postTypeLabel)
268
+ children: /* Translators: %s: the name of a post type. */(0, _i18n.sprintf)(__('Or, select a recent %s:', 'newspack'), postTypeLabel)
287
269
  }), (0, _jsxRuntime.jsxs)("div", {
288
270
  className: className,
289
271
  children: [suggestions.map(renderSuggestion), suggestions.length < (maxItemsToSuggest || maxSuggestions) && (0, _jsxRuntime.jsx)(_components.Button, {
@@ -295,7 +277,6 @@ const AutocompleteWithSuggestions = _ref => {
295
277
  })]
296
278
  });
297
279
  };
298
-
299
280
  return (0, _jsxRuntime.jsxs)("div", {
300
281
  className: classNames.join(' '),
301
282
  children: [0 < selectedItems.length && renderSelections(), 1 < postTypes.length && renderPostTypeSelect(), (0, _jsxRuntime.jsx)(_.AutocompleteTokenField, {
@@ -309,6 +290,5 @@ const AutocompleteWithSuggestions = _ref => {
309
290
  }), renderSuggestions()]
310
291
  });
311
292
  };
312
-
313
293
  var _default = AutocompleteWithSuggestions;
314
294
  exports.default = _default;
@@ -2,8 +2,7 @@
2
2
  * Styles for AutocompleteWithSuggestions component.
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
7
6
 
8
7
  .newspack-autocomplete-with-suggestions {
9
8
  width: 100%;
@@ -18,8 +17,9 @@
18
17
  }
19
18
 
20
19
  .components-spinner {
20
+ margin: 8px;
21
21
  right: 0;
22
- top: 2em;
22
+ top: calc( 1.4em + 8px );
23
23
  }
24
24
 
25
25
  .components-select-control__input {
@@ -27,19 +27,19 @@
27
27
  }
28
28
 
29
29
  .components-input-control__backdrop {
30
- border-color: $gray-900 !important;
30
+ border-color: wp-colors.$gray-700 !important;
31
31
  }
32
32
 
33
33
  .newspack-autocomplete-with-suggestions__label,
34
34
  .components-form-token-field__label,
35
35
  .components-input-control__label,
36
36
  .components-checkbox-control__label {
37
- color: $gray-900 !important;
37
+ color: wp-colors.$gray-900 !important;
38
38
  }
39
39
 
40
40
  &__suggestions-spinner {
41
- background: $gray-100;
42
- border: 1px solid $gray-900;
41
+ background: wp-colors.$gray-100;
42
+ border: 1px solid wp-colors.$gray-700;
43
43
  border-radius: 2px;
44
44
  cursor: progress;
45
45
  margin: 16px 0;
@@ -49,21 +49,23 @@
49
49
  display: block;
50
50
  margin: 0 auto;
51
51
  position: relative;
52
+ right: auto;
52
53
  top: 0;
53
54
  }
54
55
  }
55
56
 
56
57
  .newspack-autocomplete-tokenfield__help {
57
58
  font-size: inherit;
59
+ margin-bottom: 8px !important;
58
60
  }
59
61
 
60
62
  .components-form-token-field {
61
63
  &__input-container {
62
- border-color: $gray-900;
64
+ border-color: wp-colors.$gray-700;
63
65
  }
64
66
 
65
67
  &__suggestions-list {
66
- border-top-color: $gray-900;
68
+ border-top-color: wp-colors.$gray-700;
67
69
  margin: 4px -4px -2px;
68
70
  }
69
71
 
@@ -74,32 +76,30 @@
74
76
 
75
77
  p.newspack-autocomplete-with-suggestions__label {
76
78
  font-size: inherit;
77
- margin-bottom: 4px;
79
+ margin: 0 0 8px;
78
80
  }
79
81
 
80
82
  &__selected-items {
81
- border-bottom: 1px solid $gray-300;
83
+ border-bottom: 1px solid wp-colors.$gray-700;
84
+ display: flex;
85
+ flex-wrap: wrap;
86
+ gap: 8px;
82
87
  margin-bottom: 16px;
83
88
  padding-bottom: 12px;
84
89
 
85
- .newspack-autocomplete-with-suggestions__label {
86
- font-weight: bold;
87
-
88
- .components-button.is-link {
89
- color: $alert-red;
90
- font-weight: normal;
91
- }
90
+ p.newspack-autocomplete-with-suggestions__label {
91
+ flex: 0 0 100%;
92
+ margin: 0;
92
93
  }
93
94
  }
94
95
 
95
96
  &__selected-item-button.components-button.is-tertiary {
96
- background-color: $gray-300;
97
+ background-color: wp-colors.$gray-300;
97
98
  border-radius: 2px;
98
- color: #1e1e1e;
99
+ color: wp-colors.$gray-900;
99
100
  font-size: 13px;
100
101
  height: auto;
101
- margin-bottom: 4px;
102
- margin-right: 4px;
102
+ margin: 0;
103
103
  padding-left: 8px;
104
104
  padding-right: 8px;
105
105
 
@@ -117,7 +117,7 @@
117
117
  &__search-suggestions,
118
118
  &__search-suggestions-multiselect {
119
119
  border-radius: 2px;
120
- border: 1px solid $gray-900;
120
+ border: 1px solid wp-colors.$gray-700;
121
121
  max-height: 178px;
122
122
  overflow-x: visible;
123
123
  overflow-y: auto;
@@ -129,14 +129,14 @@
129
129
  margin: auto;
130
130
 
131
131
  &.is-link {
132
- color: $gray-900;
132
+ color: wp-colors.$gray-900;
133
133
  padding: 8px;
134
134
  text-decoration: none;
135
135
  width: 100%;
136
136
 
137
137
  &:active:not( :disabled ),
138
138
  &:hover:not( :disabled ) {
139
- background: $gray-900;
139
+ background: wp-colors.$gray-900;
140
140
  background: var( --wp-admin-theme-color );
141
141
  color: white;
142
142
  }
@@ -151,7 +151,7 @@
151
151
 
152
152
  &__search-suggestions {
153
153
  border-radius: 2px;
154
- border: 1px solid $gray-900;
154
+ border: 1px solid wp-colors.$gray-700;
155
155
  padding: 0;
156
156
 
157
157
  .components-button {
@@ -159,7 +159,7 @@
159
159
 
160
160
  &:focus:not( :disabled ) {
161
161
  border-radius: 0;
162
- box-shadow: inset 0 0 0 1.5px $gray-900;
162
+ box-shadow: inset 0 0 0 1.5px wp-colors.$gray-900;
163
163
  box-shadow: inset 0 0 0 var( --wp-admin-border-width-focus ) var( --wp-admin-theme-color );
164
164
  }
165
165