newspack-components 2.0.3 → 2.1.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 (248) hide show
  1. package/copy-styles.js +1 -1
  2. package/dist/cjs/action-card/index.js +29 -20
  3. package/dist/cjs/action-card/style.scss +52 -27
  4. package/dist/cjs/autocomplete-tokenfield/style.scss +4 -4
  5. package/dist/cjs/autocomplete-with-suggestions/index.js +3 -2
  6. package/dist/cjs/autocomplete-with-suggestions/style.scss +19 -20
  7. package/dist/cjs/button/index.js +2 -13
  8. package/dist/cjs/button/style.scss +3 -344
  9. package/dist/cjs/button-card/index.js +11 -6
  10. package/dist/cjs/button-card/style.scss +60 -30
  11. package/dist/cjs/card/index.js +3 -1
  12. package/dist/cjs/card/style.scss +29 -62
  13. package/dist/cjs/category-autocomplete/index.js +52 -13
  14. package/dist/cjs/category-autocomplete/style.scss +20 -22
  15. package/dist/cjs/color-picker/index.js +17 -35
  16. package/dist/cjs/color-picker/style.scss +20 -160
  17. package/dist/cjs/custom-select-control/style.scss +12 -42
  18. package/dist/cjs/footer/index.js +21 -7
  19. package/dist/cjs/footer/style.scss +9 -10
  20. package/dist/cjs/form-token-field/index.js +2 -2
  21. package/dist/cjs/form-token-field/style.scss +8 -103
  22. package/dist/cjs/global-notices/index.js +2 -1
  23. package/dist/cjs/grid/style.scss +14 -1
  24. package/dist/cjs/handoff/index.js +7 -7
  25. package/dist/cjs/image-upload/index.js +1 -1
  26. package/dist/cjs/image-upload/style.scss +10 -11
  27. package/dist/cjs/index.js +7 -53
  28. package/dist/cjs/modal/index.js +0 -3
  29. package/dist/cjs/modal/style.scss +19 -131
  30. package/dist/cjs/newspack-icon/index.js +4 -2
  31. package/dist/cjs/newspack-icon/style.scss +15 -0
  32. package/dist/cjs/notice/index.js +8 -9
  33. package/dist/cjs/notice/style.scss +38 -10
  34. package/dist/cjs/plugin-installer/index.js +1 -1
  35. package/dist/cjs/plugin-settings/SettingsSection.js +74 -43
  36. package/dist/cjs/plugin-settings/index.js +34 -30
  37. package/dist/cjs/plugin-settings/style.scss +7 -0
  38. package/dist/cjs/plugin-toggle/index.js +22 -1
  39. package/dist/cjs/popover/style.scss +2 -2
  40. package/dist/cjs/radio-control/style.scss +1 -2
  41. package/dist/cjs/section-header/index.js +18 -5
  42. package/dist/cjs/section-header/style.scss +22 -1
  43. package/dist/cjs/select-control/ButtonGroupControl.js +8 -8
  44. package/dist/cjs/select-control/GroupedSelectControl.js +33 -30
  45. package/dist/cjs/select-control/index.js +1 -2
  46. package/dist/cjs/select-control/style.scss +46 -87
  47. package/dist/cjs/settings/MinMaxSetting.js +4 -2
  48. package/dist/cjs/settings/SettingsCard.js +6 -1
  49. package/dist/cjs/settings/SettingsSection.js +4 -4
  50. package/dist/cjs/settings/style.scss +32 -4
  51. package/dist/cjs/style-card/index.js +10 -6
  52. package/dist/cjs/style-card/style.scss +12 -8
  53. package/dist/cjs/style.scss +44 -0
  54. package/dist/cjs/tabbed-navigation/index.js +13 -20
  55. package/dist/cjs/tabbed-navigation/style.scss +56 -34
  56. package/dist/cjs/text-control/index.js +0 -3
  57. package/dist/cjs/text-control/style.scss +0 -126
  58. package/dist/cjs/waiting/index.js +9 -25
  59. package/dist/cjs/waiting/style.scss +9 -20
  60. package/dist/cjs/web-preview/index.js +18 -30
  61. package/dist/cjs/web-preview/style.scss +33 -26
  62. package/dist/cjs/with-wizard/index.js +4 -2
  63. package/dist/cjs/with-wizard/style.scss +44 -89
  64. package/dist/cjs/with-wizard-screen/index.js +17 -21
  65. package/dist/cjs/with-wizard-screen/style.scss +74 -121
  66. package/dist/cjs/wizard/components/WizardError.js +86 -0
  67. package/dist/cjs/wizard/index.js +145 -0
  68. package/dist/cjs/wizard/store/index.js +178 -0
  69. package/dist/cjs/wizard/store/utils.js +31 -0
  70. package/dist/esm/action-card/index.js +30 -21
  71. package/dist/esm/action-card/style.scss +52 -27
  72. package/dist/esm/autocomplete-tokenfield/style.scss +4 -4
  73. package/dist/esm/autocomplete-with-suggestions/index.js +3 -2
  74. package/dist/esm/autocomplete-with-suggestions/style.scss +19 -20
  75. package/dist/esm/button/index.js +2 -12
  76. package/dist/esm/button/style.scss +3 -344
  77. package/dist/esm/button-card/index.js +10 -6
  78. package/dist/esm/button-card/style.scss +60 -30
  79. package/dist/esm/card/index.js +3 -1
  80. package/dist/esm/card/style.scss +29 -62
  81. package/dist/esm/category-autocomplete/index.js +54 -14
  82. package/dist/esm/category-autocomplete/style.scss +20 -22
  83. package/dist/esm/color-picker/index.js +15 -34
  84. package/dist/esm/color-picker/style.scss +20 -160
  85. package/dist/esm/custom-select-control/style.scss +12 -42
  86. package/dist/esm/footer/index.js +21 -7
  87. package/dist/esm/footer/style.scss +9 -10
  88. package/dist/esm/form-token-field/index.js +2 -2
  89. package/dist/esm/form-token-field/style.scss +8 -103
  90. package/dist/esm/global-notices/index.js +2 -1
  91. package/dist/esm/grid/style.scss +14 -1
  92. package/dist/esm/handoff/index.js +7 -7
  93. package/dist/esm/image-upload/index.js +1 -1
  94. package/dist/esm/image-upload/style.scss +10 -11
  95. package/dist/esm/index.js +3 -8
  96. package/dist/esm/modal/index.js +0 -3
  97. package/dist/esm/modal/style.scss +19 -131
  98. package/dist/esm/newspack-icon/index.js +4 -2
  99. package/dist/esm/newspack-icon/style.scss +15 -0
  100. package/dist/esm/notice/index.js +8 -3
  101. package/dist/esm/notice/style.scss +38 -10
  102. package/dist/esm/plugin-installer/index.js +2 -1
  103. package/dist/esm/plugin-settings/SettingsSection.js +72 -44
  104. package/dist/esm/plugin-settings/index.js +34 -30
  105. package/dist/esm/plugin-settings/style.scss +7 -0
  106. package/dist/esm/plugin-toggle/index.js +23 -1
  107. package/dist/esm/popover/style.scss +2 -2
  108. package/dist/esm/radio-control/style.scss +1 -2
  109. package/dist/esm/section-header/index.js +17 -5
  110. package/dist/esm/section-header/style.scss +22 -1
  111. package/dist/esm/select-control/ButtonGroupControl.js +8 -8
  112. package/dist/esm/select-control/GroupedSelectControl.js +33 -30
  113. package/dist/esm/select-control/index.js +1 -2
  114. package/dist/esm/select-control/style.scss +46 -87
  115. package/dist/esm/settings/MinMaxSetting.js +3 -2
  116. package/dist/esm/settings/SettingsCard.js +6 -1
  117. package/dist/esm/settings/SettingsSection.js +5 -5
  118. package/dist/esm/settings/style.scss +32 -4
  119. package/dist/esm/style-card/index.js +11 -8
  120. package/dist/esm/style-card/style.scss +12 -8
  121. package/dist/esm/style.scss +44 -0
  122. package/dist/esm/tabbed-navigation/index.js +14 -22
  123. package/dist/esm/tabbed-navigation/style.scss +56 -34
  124. package/dist/esm/text-control/index.js +0 -3
  125. package/dist/esm/text-control/style.scss +0 -126
  126. package/dist/esm/waiting/index.js +9 -22
  127. package/dist/esm/waiting/style.scss +9 -20
  128. package/dist/esm/web-preview/index.js +12 -25
  129. package/dist/esm/web-preview/style.scss +33 -26
  130. package/dist/esm/with-wizard/index.js +4 -2
  131. package/dist/esm/with-wizard/style.scss +44 -89
  132. package/dist/esm/with-wizard-screen/index.js +18 -22
  133. package/dist/esm/with-wizard-screen/style.scss +74 -121
  134. package/dist/esm/wizard/components/WizardError.js +78 -0
  135. package/dist/esm/wizard/index.js +128 -0
  136. package/dist/esm/wizard/store/index.js +161 -0
  137. package/dist/esm/wizard/store/utils.js +17 -0
  138. package/package.json +1 -1
  139. package/shared/scss/_colors.scss +15 -0
  140. package/src/action-card/index.js +28 -18
  141. package/src/action-card/style.scss +52 -27
  142. package/src/autocomplete-tokenfield/style.scss +4 -4
  143. package/src/autocomplete-with-suggestions/index.js +4 -2
  144. package/src/autocomplete-with-suggestions/style.scss +19 -20
  145. package/src/button/index.js +2 -9
  146. package/src/button/style.scss +3 -344
  147. package/src/button-card/index.js +19 -5
  148. package/src/button-card/style.scss +60 -30
  149. package/src/card/index.js +4 -0
  150. package/src/card/style.scss +29 -62
  151. package/src/category-autocomplete/index.js +51 -18
  152. package/src/category-autocomplete/style.scss +20 -22
  153. package/src/color-picker/index.js +16 -22
  154. package/src/color-picker/style.scss +20 -160
  155. package/src/custom-select-control/style.scss +12 -42
  156. package/src/footer/index.js +19 -8
  157. package/src/footer/style.scss +9 -10
  158. package/src/form-token-field/index.js +1 -1
  159. package/src/form-token-field/style.scss +8 -103
  160. package/src/global-notices/index.js +1 -1
  161. package/src/grid/style.scss +14 -1
  162. package/src/handoff/index.js +7 -7
  163. package/src/image-upload/style.scss +10 -11
  164. package/src/index.js +3 -7
  165. package/src/modal/index.js +2 -5
  166. package/src/modal/style.scss +19 -131
  167. package/src/newspack-icon/index.js +7 -2
  168. package/src/newspack-icon/style.scss +15 -0
  169. package/src/notice/index.js +7 -1
  170. package/src/notice/style.scss +38 -10
  171. package/src/plugin-installer/index.js +2 -2
  172. package/src/plugin-settings/SettingsSection.js +64 -26
  173. package/src/plugin-settings/index.js +23 -7
  174. package/src/plugin-settings/style.scss +7 -0
  175. package/src/plugin-toggle/index.js +35 -9
  176. package/src/popover/style.scss +2 -2
  177. package/src/radio-control/style.scss +1 -2
  178. package/src/section-header/index.js +25 -6
  179. package/src/section-header/style.scss +22 -1
  180. package/src/select-control/ButtonGroupControl.js +13 -6
  181. package/src/select-control/GroupedSelectControl.js +26 -24
  182. package/src/select-control/index.js +1 -2
  183. package/src/select-control/style.scss +46 -87
  184. package/src/settings/MinMaxSetting.js +2 -1
  185. package/src/settings/SettingsCard.js +9 -7
  186. package/src/settings/SettingsSection.js +4 -4
  187. package/src/settings/style.scss +32 -4
  188. package/src/style-card/index.js +14 -16
  189. package/src/style-card/style.scss +12 -8
  190. package/src/style.scss +44 -0
  191. package/src/tabbed-navigation/index.js +12 -24
  192. package/src/tabbed-navigation/style.scss +56 -34
  193. package/src/text-control/index.js +1 -2
  194. package/src/text-control/style.scss +0 -126
  195. package/src/waiting/index.js +7 -18
  196. package/src/waiting/style.scss +9 -20
  197. package/src/web-preview/index.js +12 -33
  198. package/src/web-preview/style.scss +33 -26
  199. package/src/with-wizard/index.js +7 -5
  200. package/src/with-wizard/style.scss +44 -89
  201. package/src/with-wizard-screen/index.js +14 -17
  202. package/src/with-wizard-screen/style.scss +74 -121
  203. package/src/wizard/components/WizardError.js +57 -0
  204. package/src/wizard/index.js +133 -0
  205. package/src/wizard/store/index.js +126 -0
  206. package/src/wizard/store/utils.js +16 -0
  207. package/dist/cjs/button-group/index.js +0 -57
  208. package/dist/cjs/button-group/style.scss +0 -73
  209. package/dist/cjs/checkbox-control/index.js +0 -63
  210. package/dist/cjs/checkbox-control/style.scss +0 -78
  211. package/dist/cjs/preview-box/index.js +0 -36
  212. package/dist/cjs/preview-box/style.scss +0 -18
  213. package/dist/cjs/textarea-control/index.js +0 -54
  214. package/dist/cjs/textarea-control/style.scss +0 -76
  215. package/dist/cjs/toggle-control/index.js +0 -58
  216. package/dist/cjs/toggle-control/style.scss +0 -74
  217. package/dist/cjs/toggle-group/index.js +0 -71
  218. package/dist/cjs/toggle-group/style.scss +0 -28
  219. package/dist/cjs/wizard-pagination/index.js +0 -71
  220. package/dist/cjs/wizard-pagination/style.scss +0 -74
  221. package/dist/esm/button-group/index.js +0 -43
  222. package/dist/esm/button-group/style.scss +0 -73
  223. package/dist/esm/checkbox-control/index.js +0 -49
  224. package/dist/esm/checkbox-control/style.scss +0 -78
  225. package/dist/esm/preview-box/index.js +0 -30
  226. package/dist/esm/preview-box/style.scss +0 -18
  227. package/dist/esm/textarea-control/index.js +0 -40
  228. package/dist/esm/textarea-control/style.scss +0 -76
  229. package/dist/esm/toggle-control/index.js +0 -44
  230. package/dist/esm/toggle-control/style.scss +0 -74
  231. package/dist/esm/toggle-group/index.js +0 -58
  232. package/dist/esm/toggle-group/style.scss +0 -28
  233. package/dist/esm/wizard-pagination/index.js +0 -57
  234. package/dist/esm/wizard-pagination/style.scss +0 -74
  235. package/src/button-group/index.js +0 -35
  236. package/src/button-group/style.scss +0 -73
  237. package/src/checkbox-control/index.js +0 -38
  238. package/src/checkbox-control/style.scss +0 -78
  239. package/src/preview-box/index.js +0 -18
  240. package/src/preview-box/style.scss +0 -18
  241. package/src/textarea-control/index.js +0 -32
  242. package/src/textarea-control/style.scss +0 -76
  243. package/src/toggle-control/index.js +0 -38
  244. package/src/toggle-control/style.scss +0 -74
  245. package/src/toggle-group/index.js +0 -43
  246. package/src/toggle-group/style.scss +0 -28
  247. package/src/wizard-pagination/index.js +0 -59
  248. package/src/wizard-pagination/style.scss +0 -74
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+
14
+ var _data = require("@wordpress/data");
15
+
16
+ var _element = require("@wordpress/element");
17
+
18
+ var _i18n = require("@wordpress/i18n");
19
+
20
+ var _icons = require("@wordpress/icons");
21
+
22
+ var _ = require("../");
23
+
24
+ var _router = _interopRequireDefault(require("../proxied-imports/router"));
25
+
26
+ var _store = _interopRequireWildcard(require("./store"));
27
+
28
+ var _utils = require("./store/utils");
29
+
30
+ var _WizardError = _interopRequireDefault(require("./components/WizardError"));
31
+
32
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
33
+
34
+ /**
35
+ * External dependencies.
36
+ */
37
+
38
+ /**
39
+ * WordPress dependencies.
40
+ */
41
+ const __ = _i18n.__;
42
+ (0, _store.default)();
43
+ const {
44
+ HashRouter,
45
+ Redirect,
46
+ Route,
47
+ Switch
48
+ } = _router.default;
49
+
50
+ const Wizard = _ref => {
51
+ let {
52
+ sections = [],
53
+ apiSlug,
54
+ headerText,
55
+ subHeaderText,
56
+ hasSimpleFooter,
57
+ className,
58
+ renderAboveSections,
59
+ requiredPlugins = []
60
+ } = _ref;
61
+ const isLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isLoading());
62
+ const isQuietLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isQuietLoading()); // Trigger initial data fetch. Some sections might not use the wizard data,
63
+ // but for consistency, fetching is triggered regardless of the section.
64
+
65
+ (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).getWizardAPIData(apiSlug));
66
+ let displayedSections = sections.filter(section => !section.isHidden);
67
+ const [pluginRequirementsSatisfied, setPluginRequirementsSatisfied] = (0, _element.useState)(requiredPlugins.length === 0);
68
+
69
+ if (!pluginRequirementsSatisfied) {
70
+ headerText = requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack');
71
+ displayedSections = [{
72
+ path: '/',
73
+ render: () => (0, _jsxRuntime.jsx)(_.PluginInstaller, {
74
+ plugins: requiredPlugins,
75
+ onStatus: _ref2 => {
76
+ let {
77
+ complete
78
+ } = _ref2;
79
+ return setPluginRequirementsSatisfied(complete);
80
+ }
81
+ })
82
+ }];
83
+ }
84
+
85
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
86
+ children: [(0, _jsxRuntime.jsx)(_WizardError.default, {}), (0, _jsxRuntime.jsx)("div", {
87
+ className: (0, _classnames.default)(isLoading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded', {
88
+ 'newspack-wizard__is-loading-quiet': isQuietLoading
89
+ }),
90
+ children: (0, _jsxRuntime.jsxs)(HashRouter, {
91
+ hashType: "slash",
92
+ children: [newspack_aux_data.is_debug_mode && (0, _jsxRuntime.jsx)(_.Notice, {
93
+ debugMode: true
94
+ }), (0, _jsxRuntime.jsx)("div", {
95
+ className: "bg-white",
96
+ children: (0, _jsxRuntime.jsx)("div", {
97
+ className: "newspack-wizard__header__inner",
98
+ children: (0, _jsxRuntime.jsxs)("div", {
99
+ className: "newspack-wizard__title",
100
+ children: [(0, _jsxRuntime.jsx)(_.Button, {
101
+ isLink: true,
102
+ href: newspack_urls.dashboard,
103
+ label: __('Return to Dashboard', 'newspack'),
104
+ showTooltip: true,
105
+ icon: _icons.category,
106
+ iconSize: 36,
107
+ children: (0, _jsxRuntime.jsx)(_.NewspackIcon, {
108
+ size: 36
109
+ })
110
+ }), (0, _jsxRuntime.jsxs)("div", {
111
+ children: [headerText && (0, _jsxRuntime.jsx)("h2", {
112
+ children: headerText
113
+ }), subHeaderText && (0, _jsxRuntime.jsx)("span", {
114
+ children: subHeaderText
115
+ })]
116
+ })]
117
+ })
118
+ })
119
+ }), displayedSections.length > 1 && (0, _jsxRuntime.jsx)(_.TabbedNavigation, {
120
+ items: displayedSections
121
+ }), (0, _jsxRuntime.jsxs)(Switch, {
122
+ children: [displayedSections.map((section, index) => {
123
+ const SectionComponent = section.render;
124
+ return (0, _jsxRuntime.jsx)(Route, {
125
+ path: section.path,
126
+ children: (0, _jsxRuntime.jsxs)("div", {
127
+ className: (0, _classnames.default)('newspack-wizard newspack-wizard__content', className),
128
+ children: ['function' === typeof renderAboveSections ? renderAboveSections() : null, (0, _jsxRuntime.jsx)(SectionComponent, {})]
129
+ })
130
+ }, index);
131
+ }), (0, _jsxRuntime.jsx)(Redirect, {
132
+ to: displayedSections[0].path
133
+ })]
134
+ })]
135
+ })
136
+ }), !isLoading && (0, _jsxRuntime.jsx)(_.Footer, {
137
+ simple: hasSimpleFooter
138
+ })]
139
+ });
140
+ };
141
+
142
+ Wizard.useWizardData = _utils.useWizardData;
143
+ Wizard.STORE_NAMESPACE = _store.WIZARD_STORE_NAMESPACE;
144
+ var _default = Wizard;
145
+ exports.default = _default;
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.WIZARD_STORE_NAMESPACE = void 0;
9
+
10
+ var _lodash = require("lodash");
11
+
12
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
13
+
14
+ var _data = require("@wordpress/data");
15
+
16
+ var _utils = require("./utils.js");
17
+
18
+ /**
19
+ * External dependencies.
20
+ */
21
+
22
+ /**
23
+ * WordPress dependencies.
24
+ */
25
+ const WIZARD_STORE_NAMESPACE = 'newspack/wizards';
26
+ exports.WIZARD_STORE_NAMESPACE = WIZARD_STORE_NAMESPACE;
27
+ const DEFAULT_STATE = {
28
+ isLoading: true,
29
+ isQuietLoading: false,
30
+ apiData: {},
31
+ error: null
32
+ };
33
+ /**
34
+ * wordpress/data does not trigger a component re-render
35
+ * on deep state change (via lodash's set function)
36
+ * unless the state was cloned first.
37
+ */
38
+
39
+ const clone = objectToClone => JSON.parse(JSON.stringify(objectToClone));
40
+
41
+ const reducer = function () {
42
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
43
+ let {
44
+ type,
45
+ payload = {}
46
+ } = arguments.length > 1 ? arguments[1] : undefined;
47
+
48
+ switch (type) {
49
+ case 'START_LOADING_DATA':
50
+ if (payload.isQuietLoading) {
51
+ return { ...state,
52
+ isQuietLoading: true
53
+ };
54
+ }
55
+
56
+ return { ...state,
57
+ isLoading: true
58
+ };
59
+
60
+ case 'FINISH_LOADING_DATA':
61
+ return { ...state,
62
+ isLoading: false,
63
+ isQuietLoading: false
64
+ };
65
+
66
+ case 'SET_API_DATA':
67
+ return (0, _lodash.set)(clone(state), ['apiData', payload.slug], payload.data);
68
+
69
+ case 'UPDATE_WIZARD_SETTINGS':
70
+ return (0, _lodash.set)(clone(state), ['apiData', payload.slug, ...payload.path], payload.value);
71
+
72
+ case 'SET_ERROR':
73
+ return { ...state,
74
+ error: payload
75
+ };
76
+
77
+ default:
78
+ return state;
79
+ }
80
+ };
81
+
82
+ const actions = {
83
+ // Regular actions.
84
+ startLoadingData: (0, _utils.createAction)('START_LOADING_DATA'),
85
+ finishLoadingData: (0, _utils.createAction)('FINISH_LOADING_DATA'),
86
+ fetchFromAPI: (0, _utils.createAction)('FETCH_FROM_API'),
87
+ setAPIDataForWizard: (0, _utils.createAction)('SET_API_DATA'),
88
+ updateWizardSettings: (0, _utils.createAction)('UPDATE_WIZARD_SETTINGS'),
89
+ setError: (0, _utils.createAction)('SET_ERROR'),
90
+
91
+ // Async actions. These will not show up in Redux devtools.
92
+ *saveWizardSettings(_ref) {
93
+ let {
94
+ slug,
95
+ section = '',
96
+ payloadPath = false,
97
+ updatePayload = null
98
+ } = _ref;
99
+
100
+ // Optionally data can be updated before saving - an immediate update case
101
+ // (without an explicit "save" action).
102
+ if (updatePayload) {
103
+ yield actions.updateWizardSettings({
104
+ slug,
105
+ ...updatePayload
106
+ });
107
+ }
108
+
109
+ const wizardState = (0, _data.select)(WIZARD_STORE_NAMESPACE).getWizardAPIData(slug);
110
+ const updatedData = yield actions.fetchFromAPI({
111
+ path: `/newspack/v1/wizard/${slug}/${section}`,
112
+ method: 'POST',
113
+ data: payloadPath ? (0, _lodash.get)(wizardState, payloadPath) : wizardState,
114
+ isQuietFetch: true
115
+ });
116
+
117
+ if (!(0, _lodash.isEmpty)(updatedData)) {
118
+ return actions.setAPIDataForWizard({
119
+ slug,
120
+ data: updatedData
121
+ });
122
+ }
123
+ },
124
+
125
+ *wizardApiFetch(fetchConfig) {
126
+ // Just a proxy to fetchFromAPI, but it has to be a generator.
127
+ const result = yield actions.fetchFromAPI(fetchConfig);
128
+ return result;
129
+ }
130
+
131
+ };
132
+ const selectors = {
133
+ isLoading: state => state.isLoading,
134
+ isQuietLoading: state => state.isQuietLoading,
135
+ getWizardAPIData: (state, slug) => state.apiData[slug] || {},
136
+ getError: state => state.error
137
+ };
138
+ const store = (0, _data.createReduxStore)(WIZARD_STORE_NAMESPACE, {
139
+ reducer,
140
+ actions,
141
+ selectors,
142
+ controls: {
143
+ FETCH_FROM_API: action => {
144
+ (0, _data.dispatch)(WIZARD_STORE_NAMESPACE).startLoadingData({
145
+ isQuietLoading: Boolean(action.payload.isQuietFetch)
146
+ });
147
+ return (0, _apiFetch.default)(action.payload).catch(error => {
148
+ (0, _data.dispatch)(WIZARD_STORE_NAMESPACE).setError(error);
149
+ return {
150
+ error
151
+ };
152
+ }).finally(result => {
153
+ (0, _data.dispatch)(WIZARD_STORE_NAMESPACE).finishLoadingData();
154
+ return result;
155
+ });
156
+ }
157
+ },
158
+ resolvers: {
159
+ *getWizardAPIData(slug) {
160
+ if (slug) {
161
+ const data = yield actions.fetchFromAPI({
162
+ path: `/newspack/v1/wizard/${slug}`
163
+ });
164
+ return actions.setAPIDataForWizard({
165
+ slug,
166
+ data
167
+ });
168
+ }
169
+
170
+ return actions.finishLoadingData();
171
+ }
172
+
173
+ }
174
+ });
175
+
176
+ var _default = () => (0, _data.register)(store);
177
+
178
+ exports.default = _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useWizardData = exports.createAction = void 0;
7
+
8
+ var _data = require("@wordpress/data");
9
+
10
+ var _ = require(".");
11
+
12
+ /**
13
+ * WordPress dependencies.
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ const createAction = type => payload => ({
20
+ type,
21
+ payload
22
+ });
23
+
24
+ exports.createAction = createAction;
25
+
26
+ const useWizardData = function (wizardName) {
27
+ let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28
+ return (0, _data.useSelect)(select => select(_.WIZARD_STORE_NAMESPACE).getWizardAPIData(`newspack-${wizardName}-wizard`)) || defaultValue;
29
+ };
30
+
31
+ exports.useWizardData = useWizardData;
@@ -8,13 +8,13 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
8
  * WordPress dependencies
9
9
  */
10
10
  import { Component } from '@wordpress/element';
11
- import { ExternalLink } from '@wordpress/components';
11
+ import { ExternalLink, ToggleControl } from '@wordpress/components';
12
12
  import { Icon, check } from '@wordpress/icons';
13
13
  /**
14
14
  * Internal dependencies
15
15
  */
16
16
 
17
- import { Button, Card, Handoff, Notice, ToggleControl, Waiting } from '../';
17
+ import { Button, Card, Grid, Handoff, Notice, Waiting } from '../';
18
18
  import './style.scss';
19
19
  /**
20
20
  * External dependencies
@@ -56,8 +56,10 @@ class ActionCard extends Component {
56
56
  actionContent,
57
57
  actionText,
58
58
  secondaryActionText,
59
+ secondaryDestructive,
59
60
  image,
60
61
  imageLink,
62
+ indent,
61
63
  isSmall,
62
64
  isMedium,
63
65
  simple,
@@ -67,10 +69,11 @@ class ActionCard extends Component {
67
69
  titleLink,
68
70
  toggleChecked,
69
71
  toggleOnChange,
70
- hasGreyHeader
72
+ hasGreyHeader,
73
+ isPending
71
74
  } = this.props;
72
75
  const hasChildren = notification || children;
73
- const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasChildren && 'newspack-card--has-children', isSmall && 'is-small', isMedium && 'is-medium', className);
76
+ const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasChildren && 'newspack-card--has-children', indent && 'newspack-card--indent', isSmall && 'is-small', isMedium && 'is-medium', className);
74
77
  const titleProps = toggleOnChange && !titleLink && !disabled ? {
75
78
  onClick: () => toggleOnChange(!toggleChecked),
76
79
  tabIndex: '0'
@@ -99,28 +102,33 @@ class ActionCard extends Component {
99
102
  }), checkbox && !toggleOnChange && _jsx("div", {
100
103
  className: "newspack-action-card__region newspack-action-card__region-left",
101
104
  children: _jsx("span", {
102
- className: classnames('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked'),
105
+ className: classnames('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked', isPending && 'newspack-checkbox-icon--pending'),
103
106
  children: 'checked' === checkbox && _jsx(Icon, {
104
107
  icon: check
105
108
  })
106
109
  })
107
- }), _jsxs("div", {
110
+ }), _jsx("div", {
108
111
  className: "newspack-action-card__region newspack-action-card__region-center",
109
- children: [_jsxs("h2", {
110
- children: [_jsx("span", {
111
- className: "newspack-action-card__title",
112
- ...titleProps,
113
- children: titleLink ? _jsx("a", {
114
- href: titleLink,
115
- children: title
116
- }) : title
117
- }), (badges === null || badges === void 0 ? void 0 : badges.length) && badges.map((badgeText, i) => _jsx("span", {
118
- className: "newspack-action-card__badge",
119
- children: badgeText
120
- }, `badge-${i}`))]
121
- }), _jsxs("p", {
122
- children: [typeof description === 'string' && description, typeof description === 'function' && description()]
123
- })]
112
+ children: _jsxs(Grid, {
113
+ columns: 1,
114
+ gutter: 8,
115
+ noMargin: true,
116
+ children: [_jsxs("h2", {
117
+ children: [_jsx("span", {
118
+ className: "newspack-action-card__title",
119
+ ...titleProps,
120
+ children: titleLink ? _jsx("a", {
121
+ href: titleLink,
122
+ children: title
123
+ }) : title
124
+ }), badges?.length && badges.map((badgeText, i) => _jsx("span", {
125
+ className: "newspack-action-card__badge",
126
+ children: badgeText
127
+ }, `badge-${i}`))]
128
+ }), description && _jsxs("p", {
129
+ children: [typeof description === 'string' && description, typeof description === 'function' && description()]
130
+ })]
131
+ })
124
132
  }), (actionText || isDisplayingSecondaryAction || actionContent) && _jsxs("div", {
125
133
  className: "newspack-action-card__region newspack-action-card__region-right",
126
134
  children: [actionContent && actionContent, actionText && (handoff ? _jsx(Handoff, {
@@ -148,6 +156,7 @@ class ActionCard extends Component {
148
156
  isLink: true,
149
157
  onClick: onSecondaryActionClick,
150
158
  className: "newspack-action-card__secondary_button",
159
+ isDestructive: secondaryDestructive,
151
160
  children: secondaryActionText
152
161
  })]
153
162
  })]
@@ -3,7 +3,6 @@
3
3
  */
4
4
 
5
5
  @import '~@wordpress/base-styles/colors';
6
- @import '../../../shared/scss/colors';
7
6
 
8
7
  .newspack-card.newspack-action-card {
9
8
  padding: 0;
@@ -34,7 +33,7 @@
34
33
  }
35
34
 
36
35
  &.newspack-card__is-primary {
37
- box-shadow: inset 4px 0 0 $primary-500;
36
+ box-shadow: inset 4px 0 0 var( --wp-admin-theme-color );
38
37
  }
39
38
 
40
39
  &.newspack-card__is-secondary {
@@ -150,20 +149,49 @@
150
149
 
151
150
  &.newspack-card--has-grey-header {
152
151
  overflow: hidden;
152
+
153
153
  &.newspack-card--has-children {
154
154
  .newspack-action-card__region-top {
155
155
  border-bottom: 1px solid $gray-300;
156
156
  }
157
157
  }
158
+
158
159
  .newspack-action-card__region-top {
159
- background-color: $gray-100;
160
+ background-color: rgba( black, 0.025 );
161
+ }
162
+
163
+ .newspack-action-card__region-center {
164
+ p {
165
+ color: darken( $gray-700, 0.75% );
166
+ }
167
+ }
168
+ }
169
+
170
+ // Indent
171
+
172
+ &.newspack-card--indent {
173
+ margin-left: 56px;
174
+ position: relative;
175
+
176
+ &::before {
177
+ border: 0 solid $gray-300;
178
+ border-left-width: 1px;
179
+ border-bottom-width: 1px;
180
+ border-radius: 0 0 0 2px;
181
+ bottom: 50%;
182
+ content: '';
183
+ display: block;
184
+ left: -28px;
185
+ position: absolute;
186
+ right: 100%;
187
+ top: -17px;
160
188
  }
161
189
  }
162
190
 
163
191
  // Typography
164
192
 
165
193
  h2,
166
- p {
194
+ p:not( [class*='components-base-control'] ) {
167
195
  margin: 0;
168
196
  max-width: 100%;
169
197
  width: 100%;
@@ -186,7 +214,7 @@
186
214
  &:active,
187
215
  &:focus,
188
216
  &:hover {
189
- color: $primary-500;
217
+ color: var( --wp-admin-theme-color );
190
218
  }
191
219
  }
192
220
  }
@@ -270,6 +298,14 @@
270
298
  align-items: flex-start;
271
299
  flex: 1 1 auto;
272
300
  flex-wrap: wrap;
301
+
302
+ .newspack-grid {
303
+ width: 100%;
304
+ }
305
+
306
+ p {
307
+ color: $gray-700;
308
+ }
273
309
  }
274
310
 
275
311
  .newspack-action-card__region-right {
@@ -289,6 +325,10 @@
289
325
  > * {
290
326
  text-align: inherit;
291
327
  }
328
+
329
+ .newspack-action-card__secondary_button {
330
+ margin-top: 8px;
331
+ }
292
332
  }
293
333
 
294
334
  // Waiting
@@ -326,34 +366,19 @@
326
366
  margin: 0;
327
367
  }
328
368
 
329
- // Buttons
330
-
331
- .newspack-button {
332
- &.newspack-action-card__secondary_button {
333
- &.is-link {
334
- color: $alert-red;
335
-
336
- &:active,
337
- &:focus,
338
- &:hover {
339
- color: darken( $alert-red, 20% );
340
- }
341
- }
342
- }
343
- }
344
-
345
369
  // Badge
346
370
 
347
371
  .newspack-action-card__badge {
348
- border: 1px solid $gray-300;
349
- border-radius: 12px;
372
+ background: $gray-100;
373
+ border-radius: 2px;
374
+ color: $gray-900;
350
375
  display: block;
351
376
  flex: 0 0 auto;
352
- font-size: 12px;
377
+ font-size: 10px;
353
378
  font-weight: bold;
354
- line-height: 16px;
355
- margin: 3px 8px 3px 0;
356
- padding: 0 8px;
379
+ line-height: 1.4;
380
+ margin: 0 8px 0 0;
381
+ padding: 2px 8px;
357
382
  text-transform: uppercase;
358
383
 
359
384
  + .newspack-action-card__badge {
@@ -2,16 +2,16 @@
2
2
  * Autocomplete Token Field
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
5
  @import '~@wordpress/base-styles/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. */
@@ -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
  }
@@ -144,7 +144,7 @@ const AutocompleteWithSuggestions = _ref => {
144
144
  return posts.reduce((acc, post) => {
145
145
  acc.push({
146
146
  value: parseInt(post.id),
147
- label: decodeEntities(post === null || post === void 0 ? void 0 : post.title.rendered) || __('(no title)', 'newspack')
147
+ label: decodeEntities(post?.title.rendered) || __('(no title)', 'newspack')
148
148
  });
149
149
  return acc;
150
150
  }, []);
@@ -197,6 +197,7 @@ const AutocompleteWithSuggestions = _ref => {
197
197
  children: [selectedMessage, 1 < selections.length && _x(' – ', 'separator character', 'newspack'), 1 < selections.length && _jsx(Button, {
198
198
  onClick: () => onChange([]),
199
199
  isLink: true,
200
+ isDestructive: true,
200
201
  children: __('Clear all', 'newspack')
201
202
  })]
202
203
  }), selections.map(selection => _jsx(Button, {
@@ -234,7 +235,7 @@ const AutocompleteWithSuggestions = _ref => {
234
235
  const renderSuggestion = suggestion => {
235
236
  if (multiSelect) {
236
237
  const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems];
237
- const isSelected = !!selections.find(_selection => parseInt(_selection.value) === parseInt(suggestion.value));
238
+ const isSelected = !!selections.find(_selection => parseInt(_selection.value) === parseInt(suggestion.value) && _selection.label === suggestion.label);
238
239
  return _jsx(CheckboxControl, {
239
240
  checked: isSelected,
240
241
  onChange: () => handleOnChange([suggestion]),