newspack-components 2.2.1 → 3.0.0-alpha.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 (168) hide show
  1. package/dist/cjs/action-card/index.js +3 -4
  2. package/dist/cjs/autocomplete-tokenfield/index.js +52 -15
  3. package/dist/cjs/autocomplete-tokenfield/style.scss +11 -5
  4. package/dist/cjs/autocomplete-with-suggestions/index.js +45 -57
  5. package/dist/cjs/autocomplete-with-suggestions/style.scss +1 -9
  6. package/dist/cjs/button/index.js +8 -9
  7. package/dist/cjs/button-card/index.js +1 -2
  8. package/dist/cjs/card/index.js +1 -2
  9. package/dist/cjs/category-autocomplete/index.js +4 -8
  10. package/dist/cjs/color-picker/index.js +7 -9
  11. package/dist/cjs/consts.js +2 -7
  12. package/dist/cjs/custom-select-control/index.js +1 -2
  13. package/dist/cjs/footer/index.js +24 -29
  14. package/dist/cjs/form-token-field/index.js +1 -2
  15. package/dist/cjs/global-notices/index.js +1 -2
  16. package/dist/cjs/grid/index.js +14 -31
  17. package/dist/cjs/handoff/index.js +7 -8
  18. package/dist/cjs/hooks/index.js +2 -3
  19. package/dist/cjs/hooks/useObjectState.js +1 -2
  20. package/dist/cjs/hooks/useOnClickOutside.js +1 -2
  21. package/dist/cjs/hooks/usePrompt.js +1 -4
  22. package/dist/cjs/image-upload/index.js +5 -6
  23. package/dist/cjs/index.js +0 -14
  24. package/dist/cjs/info-button/index.js +1 -2
  25. package/dist/cjs/modal/index.js +1 -2
  26. package/dist/cjs/newspack-icon/index.js +1 -2
  27. package/dist/cjs/newspack-logo/index.js +1 -2
  28. package/dist/cjs/notice/index.js +2 -3
  29. package/dist/cjs/patrons-logo/index.js +4 -5
  30. package/dist/cjs/plugin-installer/index.js +9 -13
  31. package/dist/cjs/plugin-settings/SettingsSection.js +2 -4
  32. package/dist/cjs/plugin-settings/index.js +2 -3
  33. package/dist/cjs/plugin-toggle/index.js +16 -20
  34. package/dist/cjs/popover/index.js +1 -2
  35. package/dist/cjs/position-control/index.js +22 -23
  36. package/dist/cjs/progress-bar/index.js +1 -2
  37. package/dist/cjs/progress-bar/index.test.js +4 -5
  38. package/dist/cjs/proxied-imports/router.js +1 -2
  39. package/dist/cjs/radio-control/index.js +1 -2
  40. package/dist/cjs/section-header/index.js +13 -14
  41. package/dist/cjs/section-header/style.scss +4 -0
  42. package/dist/cjs/select-control/ButtonGroupControl.js +10 -12
  43. package/dist/cjs/select-control/GroupedSelectControl.js +21 -25
  44. package/dist/cjs/select-control/index.js +1 -2
  45. package/dist/cjs/settings/MinMaxSetting.js +17 -15
  46. package/dist/cjs/settings/SettingsCard.js +10 -12
  47. package/dist/cjs/settings/SettingsSection.js +20 -24
  48. package/dist/cjs/settings/index.js +2 -3
  49. package/dist/cjs/settings/style.scss +14 -1
  50. package/dist/cjs/sortable-newsletter-list-control/index.js +134 -0
  51. package/dist/cjs/sortable-newsletter-list-control/style.scss +45 -0
  52. package/dist/cjs/steps-list/index.js +1 -2
  53. package/dist/cjs/steps-list-item/index.js +1 -2
  54. package/dist/cjs/style-card/index.js +6 -7
  55. package/dist/cjs/style.scss +13 -1
  56. package/dist/cjs/tabbed-navigation/index.js +11 -14
  57. package/dist/cjs/text-control/index.js +32 -42
  58. package/dist/cjs/utils/index.js +15 -19
  59. package/dist/cjs/waiting/index.js +1 -2
  60. package/dist/cjs/web-preview/index.js +7 -8
  61. package/dist/cjs/with-wizard/index.js +6 -7
  62. package/dist/cjs/with-wizard-screen/index.js +20 -24
  63. package/dist/cjs/wizard/components/WizardError.js +7 -9
  64. package/dist/cjs/wizard/index.js +16 -21
  65. package/dist/cjs/wizard/store/index.js +36 -37
  66. package/dist/cjs/wizard/store/utils.js +1 -4
  67. package/dist/esm/action-card/index.js +3 -4
  68. package/dist/esm/autocomplete-tokenfield/index.js +52 -15
  69. package/dist/esm/autocomplete-tokenfield/style.scss +11 -5
  70. package/dist/esm/autocomplete-with-suggestions/index.js +46 -59
  71. package/dist/esm/autocomplete-with-suggestions/style.scss +1 -9
  72. package/dist/esm/button/index.js +7 -7
  73. package/dist/esm/button-card/index.js +1 -2
  74. package/dist/esm/category-autocomplete/index.js +4 -8
  75. package/dist/esm/color-picker/index.js +7 -9
  76. package/dist/esm/consts.js +0 -2
  77. package/dist/esm/footer/index.js +24 -29
  78. package/dist/esm/form-token-field/index.js +1 -2
  79. package/dist/esm/grid/index.js +13 -29
  80. package/dist/esm/handoff/index.js +7 -8
  81. package/dist/esm/hooks/useObjectState.js +1 -2
  82. package/dist/esm/hooks/useObjectState.test.js +1 -2
  83. package/dist/esm/hooks/usePrompt.js +1 -4
  84. package/dist/esm/image-upload/index.js +5 -7
  85. package/dist/esm/index.js +0 -2
  86. package/dist/esm/notice/index.js +2 -3
  87. package/dist/esm/patrons-logo/index.js +4 -5
  88. package/dist/esm/plugin-installer/index.js +9 -14
  89. package/dist/esm/plugin-settings/SettingsSection.js +2 -4
  90. package/dist/esm/plugin-settings/index.js +2 -3
  91. package/dist/esm/plugin-toggle/index.js +16 -20
  92. package/dist/esm/position-control/index.js +23 -25
  93. package/dist/esm/progress-bar/index.js +1 -2
  94. package/dist/esm/progress-bar/index.test.js +4 -5
  95. package/dist/esm/section-header/index.js +13 -14
  96. package/dist/esm/section-header/style.scss +4 -0
  97. package/dist/esm/select-control/ButtonGroupControl.js +9 -10
  98. package/dist/esm/select-control/GroupedSelectControl.js +22 -27
  99. package/dist/esm/settings/MinMaxSetting.js +17 -16
  100. package/dist/esm/settings/SettingsCard.js +9 -10
  101. package/dist/esm/settings/SettingsSection.js +20 -24
  102. package/dist/esm/settings/style.scss +14 -1
  103. package/dist/esm/sortable-newsletter-list-control/index.js +128 -0
  104. package/dist/esm/sortable-newsletter-list-control/style.scss +45 -0
  105. package/dist/esm/steps-list-item/index.js +1 -2
  106. package/dist/esm/style-card/index.js +6 -7
  107. package/dist/esm/style.scss +13 -1
  108. package/dist/esm/tabbed-navigation/index.js +11 -14
  109. package/dist/esm/text-control/index.js +32 -41
  110. package/dist/esm/utils/index.js +13 -16
  111. package/dist/esm/web-preview/index.js +7 -8
  112. package/dist/esm/with-wizard/index.js +7 -9
  113. package/dist/esm/with-wizard-screen/index.js +21 -27
  114. package/dist/esm/wizard/components/WizardError.js +7 -9
  115. package/dist/esm/wizard/index.js +16 -22
  116. package/dist/esm/wizard/store/index.js +35 -35
  117. package/dist/esm/wizard/store/utils.js +1 -4
  118. package/package.json +7 -8
  119. package/src/autocomplete-tokenfield/index.js +48 -15
  120. package/src/autocomplete-tokenfield/style.scss +11 -5
  121. package/src/autocomplete-with-suggestions/index.js +17 -22
  122. package/src/autocomplete-with-suggestions/style.scss +1 -9
  123. package/src/button/{index.js → index.tsx} +12 -5
  124. package/src/consts.js +0 -2
  125. package/src/footer/index.js +7 -7
  126. package/src/grid/index.tsx +34 -0
  127. package/src/handoff/index.js +7 -6
  128. package/src/hooks/{index.js → index.ts} +1 -1
  129. package/src/hooks/{usePrompt.js → usePrompt.ts} +4 -8
  130. package/src/image-upload/index.js +4 -4
  131. package/src/index.js +0 -2
  132. package/src/notice/index.js +1 -1
  133. package/src/patrons-logo/index.js +4 -1
  134. package/src/plugin-installer/index.js +7 -7
  135. package/src/plugin-settings/index.js +1 -1
  136. package/src/plugin-toggle/index.js +7 -5
  137. package/src/position-control/index.js +13 -13
  138. package/src/section-header/index.js +3 -3
  139. package/src/section-header/style.scss +4 -0
  140. package/src/select-control/GroupedSelectControl.js +1 -1
  141. package/src/settings/MinMaxSetting.js +8 -6
  142. package/src/settings/style.scss +14 -1
  143. package/src/sortable-newsletter-list-control/index.js +137 -0
  144. package/src/sortable-newsletter-list-control/style.scss +45 -0
  145. package/src/style-card/index.js +11 -5
  146. package/src/style.scss +13 -1
  147. package/src/tabbed-navigation/index.js +1 -1
  148. package/src/text-control/index.tsx +65 -0
  149. package/src/web-preview/index.js +6 -6
  150. package/src/with-wizard/index.js +4 -4
  151. package/src/with-wizard-screen/index.js +1 -1
  152. package/src/wizard/components/WizardError.js +1 -1
  153. package/src/wizard/index.js +3 -3
  154. package/src/wizard/store/index.js +9 -2
  155. package/dist/cjs/accordion/index.js +0 -46
  156. package/dist/cjs/accordion/style.scss +0 -27
  157. package/dist/cjs/date-range-picker/index.js +0 -41
  158. package/dist/cjs/date-range-picker/style.scss +0 -148
  159. package/dist/esm/accordion/index.js +0 -38
  160. package/dist/esm/accordion/style.scss +0 -27
  161. package/dist/esm/date-range-picker/index.js +0 -32
  162. package/dist/esm/date-range-picker/style.scss +0 -148
  163. package/src/accordion/index.js +0 -32
  164. package/src/accordion/style.scss +0 -27
  165. package/src/date-range-picker/index.js +0 -31
  166. package/src/date-range-picker/style.scss +0 -148
  167. package/src/grid/index.js +0 -44
  168. package/src/text-control/index.js +0 -56
@@ -24,48 +24,38 @@ const __ = _i18n.__;
24
24
  /**
25
25
  * External dependencies
26
26
  */
27
- class TextControl extends _element.Component {
28
- constructor(props) {
29
- super(props);
30
- this.wrapperRef = (0, _element.createRef)();
31
- }
32
- componentDidMount() {
33
- if (this.wrapperRef.current) {
34
- const labelEl = this.wrapperRef.current.querySelector('label');
35
- if (labelEl) {
36
- labelEl.setAttribute('data-required-text', __('(required)', 'newspack'));
37
- }
27
+ const TextControl = ({
28
+ className = '',
29
+ required = false,
30
+ isWide = false,
31
+ withMargin = true,
32
+ ...otherProps
33
+ }) => {
34
+ const wrapperRef = (0, _element.useRef)(null);
35
+ (0, _element.useEffect)(() => {
36
+ if (wrapperRef.current === null) {
37
+ return;
38
38
  }
39
- }
40
- /**
41
- * Render.
42
- */
43
- render() {
44
- const {
45
- className,
46
- required,
47
- isWide,
48
- withMargin = true,
49
- ...otherProps
50
- } = this.props;
51
- const classes = (0, _classnames.default)('newspack-text-control', {
52
- 'newspack-text-control--wide': isWide
53
- }, {
54
- 'newspack-text-control--with-margin': withMargin
55
- }, className);
56
- return required ? (0, _jsxRuntime.jsx)("div", {
57
- ref: this.wrapperRef,
58
- className: "newspack-text-control--required",
59
- children: (0, _jsxRuntime.jsx)(_components.TextControl, {
60
- className: classes,
61
- required: required,
62
- ...otherProps
63
- })
64
- }) : (0, _jsxRuntime.jsx)(_components.TextControl, {
39
+ const labelEl = wrapperRef.current.querySelector('label');
40
+ if (labelEl) {
41
+ labelEl.setAttribute('data-required-text', __('(required)', 'newspack-plugin'));
42
+ }
43
+ }, [wrapperRef.current]);
44
+ const classes = (0, _classnames.default)('newspack-text-control', {
45
+ 'newspack-text-control--wide': isWide,
46
+ 'newspack-text-control--with-margin': withMargin
47
+ }, className);
48
+ return required ? (0, _jsxRuntime.jsx)("div", {
49
+ ref: wrapperRef,
50
+ className: "newspack-text-control--required",
51
+ children: (0, _jsxRuntime.jsx)(_components.TextControl, {
65
52
  className: classes,
53
+ required: required,
66
54
  ...otherProps
67
- });
68
- }
69
- }
70
- var _default = TextControl;
71
- exports.default = _default;
55
+ })
56
+ }) : (0, _jsxRuntime.jsx)(_components.TextControl, {
57
+ className: classes,
58
+ ...otherProps
59
+ });
60
+ };
61
+ var _default = exports.default = TextControl;
@@ -10,22 +10,19 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
10
  * WordPress dependencies.
11
11
  */
12
12
 
13
- const InteractiveDiv = _ref => {
14
- let {
15
- style = {},
16
- ...props
17
- } = _ref;
18
- return (0, _jsxRuntime.jsx)("div", {
19
- tabIndex: "0",
20
- role: "button",
21
- onKeyDown: event => _keycodes.ENTER === event.keyCode && props.onClick(),
22
- style: {
23
- cursor: 'pointer',
24
- ...style
25
- },
26
- ...props
27
- });
28
- };
13
+ const InteractiveDiv = ({
14
+ style = {},
15
+ ...props
16
+ }) => (0, _jsxRuntime.jsx)("div", {
17
+ tabIndex: "0",
18
+ role: "button",
19
+ onKeyDown: event => _keycodes.ENTER === event.keyCode && props.onClick(),
20
+ style: {
21
+ cursor: 'pointer',
22
+ ...style
23
+ },
24
+ ...props
25
+ });
29
26
  const confirmAction = message => {
30
27
  // eslint-disable-next-line no-alert
31
28
  if (confirm(message)) {
@@ -33,8 +30,7 @@ const confirmAction = message => {
33
30
  }
34
31
  return false;
35
32
  };
36
- var _default = {
33
+ var _default = exports.default = {
37
34
  InteractiveDiv,
38
35
  confirmAction
39
- };
40
- exports.default = _default;
36
+ };
@@ -49,5 +49,4 @@ class Waiting extends _element.Component {
49
49
  });
50
50
  }
51
51
  }
52
- var _default = Waiting;
53
- exports.default = _default;
52
+ var _default = exports.default = Waiting;
@@ -71,21 +71,21 @@ class WebPreview extends _element.Component {
71
71
  }),
72
72
  variant: 'desktop' === device && 'primary',
73
73
  icon: _icons.desktop,
74
- label: __('Preview Desktop Size', 'newspack')
74
+ label: __('Preview Desktop Size', 'newspack-plugin')
75
75
  }), (0, _jsxRuntime.jsx)(_components.Button, {
76
76
  onClick: () => this.setState({
77
77
  device: 'tablet'
78
78
  }),
79
79
  variant: 'tablet' === device && 'primary',
80
80
  icon: _icons.tablet,
81
- label: __('Preview Tablet Size', 'newspack')
81
+ label: __('Preview Tablet Size', 'newspack-plugin')
82
82
  }), (0, _jsxRuntime.jsx)(_components.Button, {
83
83
  onClick: () => this.setState({
84
84
  device: 'phone'
85
85
  }),
86
86
  variant: 'phone' === device && 'primary',
87
87
  icon: _icons.mobile,
88
- label: __('Preview Phone Size', 'newspack')
88
+ label: __('Preview Phone Size', 'newspack-plugin')
89
89
  })]
90
90
  })
91
91
  }), (0, _jsxRuntime.jsx)("div", {
@@ -99,7 +99,7 @@ class WebPreview extends _element.Component {
99
99
  });
100
100
  },
101
101
  icon: _icons.closeSmall,
102
- label: __('Close Preview', 'newspack')
102
+ label: __('Close Preview', 'newspack-plugin')
103
103
  })
104
104
  })]
105
105
  }), (0, _jsxRuntime.jsxs)("div", {
@@ -108,7 +108,7 @@ class WebPreview extends _element.Component {
108
108
  className: "newspack-web-preview__is-waiting",
109
109
  children: [(0, _jsxRuntime.jsx)(_.Waiting, {
110
110
  isLeft: true
111
- }), __('Loading…', 'newspack')]
111
+ }), __('Loading…', 'newspack-plugin')]
112
112
  }), (0, _jsxRuntime.jsx)("iframe", {
113
113
  ref: this.iframeRef,
114
114
  title: "web-preview",
@@ -182,8 +182,7 @@ class WebPreview extends _element.Component {
182
182
  }
183
183
  WebPreview.defaultProps = {
184
184
  url: '//newspack.com',
185
- label: __('Preview', 'newspack'),
185
+ label: __('Preview', 'newspack-plugin'),
186
186
  onLoad: () => {}
187
187
  };
188
- var _default = WebPreview;
189
- exports.default = _default;
188
+ var _default = exports.default = WebPreview;
@@ -120,7 +120,7 @@ function withWizard(WrappedComponent, requiredPlugins) {
120
120
  children: (0, _jsxRuntime.jsx)(_.Button, {
121
121
  isPrimary: true,
122
122
  href: fallbackURL,
123
- children: __('Return to Dashboard', 'newspack')
123
+ children: __('Return to Dashboard', 'newspack-plugin')
124
124
  })
125
125
  })]
126
126
  });
@@ -151,10 +151,9 @@ function withWizard(WrappedComponent, requiredPlugins) {
151
151
  /**
152
152
  * Called when plugin installation is complete. Updates state and calls onWizardReady on the wrapped component.
153
153
  */
154
- (0, _defineProperty2.default)(this, "pluginInstallationStatus", _ref => {
155
- let {
156
- complete
157
- } = _ref;
154
+ (0, _defineProperty2.default)(this, "pluginInstallationStatus", ({
155
+ complete
156
+ }) => {
158
157
  if (this.state.loading) {
159
158
  this.doneLoading();
160
159
  }
@@ -240,7 +239,7 @@ function withWizard(WrappedComponent, requiredPlugins) {
240
239
  children: [(0, _jsxRuntime.jsx)(_.Button, {
241
240
  isLink: true,
242
241
  href: newspack_urls.dashboard,
243
- label: __('Return to Dashboard', 'newspack'),
242
+ label: __('Return to Dashboard', 'newspack-plugin'),
244
243
  showTooltip: true,
245
244
  icon: _icons.home,
246
245
  iconSize: 36,
@@ -249,7 +248,7 @@ function withWizard(WrappedComponent, requiredPlugins) {
249
248
  })
250
249
  }), (0, _jsxRuntime.jsx)("div", {
251
250
  children: (0, _jsxRuntime.jsx)("h2", {
252
- children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack')
251
+ children: requiredPlugins.length > 1 ? __('Required plugins', 'newspack-plugin') : __('Required plugin', 'newspack-plugin')
253
252
  })
254
253
  })]
255
254
  })
@@ -25,10 +25,9 @@ const __ = _i18n.__;
25
25
  /**
26
26
  * Higher-Order Component to provide plugin management and error handling to Newspack Wizards.
27
27
  */
28
- function withWizardScreen(WrappedComponent) {
29
- let {
30
- hidePrimaryButton
31
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28
+ function withWizardScreen(WrappedComponent, {
29
+ hidePrimaryButton
30
+ } = {}) {
32
31
  const WrappedWithWizardScreen = props => {
33
32
  const {
34
33
  className,
@@ -48,25 +47,22 @@ function withWizardScreen(WrappedComponent) {
48
47
  const SecondaryCTAComponent = retrievedSecondaryButtonProps.plugin ? _.Handoff : _.Button;
49
48
  const shouldRenderPrimaryButton = buttonText && buttonAction;
50
49
  const shouldRenderSecondaryButton = secondaryButtonText && secondaryButtonAction;
51
- const renderPrimaryButton = function () {
52
- let overridingProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
53
- return retrievedButtonProps.plugin ? (0, _jsxRuntime.jsx)(_.Handoff, {
54
- isPrimary: true,
55
- ...retrievedButtonProps,
56
- ...overridingProps,
57
- children: buttonText
58
- }) : (0, _jsxRuntime.jsx)(_.Button, {
59
- isPrimary: !buttonDisabled,
60
- isSecondary: !!buttonDisabled,
61
- disabled: buttonDisabled
62
- // Allow overridingProps to set children.
63
- // eslint-disable-next-line react/no-children-prop
64
- ,
65
- children: buttonText,
66
- ...retrievedButtonProps,
67
- ...overridingProps
68
- });
69
- };
50
+ const renderPrimaryButton = (overridingProps = {}) => retrievedButtonProps.plugin ? (0, _jsxRuntime.jsx)(_.Handoff, {
51
+ isPrimary: true,
52
+ ...retrievedButtonProps,
53
+ ...overridingProps,
54
+ children: buttonText
55
+ }) : (0, _jsxRuntime.jsx)(_.Button, {
56
+ isPrimary: !buttonDisabled,
57
+ isSecondary: !!buttonDisabled,
58
+ disabled: buttonDisabled
59
+ // Allow overridingProps to set children.
60
+ // eslint-disable-next-line react/no-children-prop
61
+ ,
62
+ children: buttonText,
63
+ ...retrievedButtonProps,
64
+ ...overridingProps
65
+ });
70
66
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
71
67
  children: [newspack_aux_data.is_debug_mode && (0, _jsxRuntime.jsx)(_.Notice, {
72
68
  debugMode: true
@@ -79,7 +75,7 @@ function withWizardScreen(WrappedComponent) {
79
75
  children: [(0, _jsxRuntime.jsx)(_.Button, {
80
76
  isLink: true,
81
77
  href: newspack_urls.dashboard,
82
- label: __('Return to Dashboard', 'newspack'),
78
+ label: __('Return to Dashboard', 'newspack-plugin'),
83
79
  showTooltip: true,
84
80
  icon: _icons.category,
85
81
  iconSize: 36,
@@ -16,12 +16,11 @@ const __ = _i18n.__;
16
16
  /**
17
17
  * Internal dependencies.
18
18
  */
19
- const parseError = _ref => {
20
- let {
21
- data,
22
- message,
23
- code
24
- } = _ref;
19
+ const parseError = ({
20
+ data,
21
+ message,
22
+ code
23
+ }) => {
25
24
  let level = 'fatal';
26
25
  if (!!data && 'level' in data) {
27
26
  level = data.level;
@@ -58,7 +57,7 @@ const WizardError = () => {
58
57
  children: (0, _jsxRuntime.jsx)(_.Button, {
59
58
  isPrimary: true,
60
59
  href: fallbackURL,
61
- children: __('Return to Dashboard', 'newspack')
60
+ children: __('Return to Dashboard', 'newspack-plugin')
62
61
  })
63
62
  })]
64
63
  });
@@ -70,5 +69,4 @@ const WizardError = () => {
70
69
  rawHTML: true
71
70
  });
72
71
  };
73
- var _default = WizardError;
74
- exports.default = _default;
72
+ var _default = exports.default = WizardError;
@@ -34,17 +34,16 @@ const {
34
34
  Route,
35
35
  Switch
36
36
  } = _router.default;
37
- const Wizard = _ref => {
38
- let {
39
- sections = [],
40
- apiSlug,
41
- headerText,
42
- subHeaderText,
43
- hasSimpleFooter,
44
- className,
45
- renderAboveSections,
46
- requiredPlugins = []
47
- } = _ref;
37
+ const Wizard = ({
38
+ sections = [],
39
+ apiSlug,
40
+ headerText,
41
+ subHeaderText,
42
+ hasSimpleFooter,
43
+ className,
44
+ renderAboveSections,
45
+ requiredPlugins = []
46
+ }) => {
48
47
  const isLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isLoading());
49
48
  const isQuietLoading = (0, _data.useSelect)(select => select(_store.WIZARD_STORE_NAMESPACE).isQuietLoading());
50
49
 
@@ -54,17 +53,14 @@ const Wizard = _ref => {
54
53
  let displayedSections = sections.filter(section => !section.isHidden);
55
54
  const [pluginRequirementsSatisfied, setPluginRequirementsSatisfied] = (0, _element.useState)(requiredPlugins.length === 0);
56
55
  if (!pluginRequirementsSatisfied) {
57
- headerText = requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack');
56
+ headerText = requiredPlugins.length > 1 ? __('Required plugins', 'newspack-plugin') : __('Required plugin', 'newspack-plugin');
58
57
  displayedSections = [{
59
58
  path: '/',
60
59
  render: () => (0, _jsxRuntime.jsx)(_.PluginInstaller, {
61
60
  plugins: requiredPlugins,
62
- onStatus: _ref2 => {
63
- let {
64
- complete
65
- } = _ref2;
66
- return setPluginRequirementsSatisfied(complete);
67
- }
61
+ onStatus: ({
62
+ complete
63
+ }) => setPluginRequirementsSatisfied(complete)
68
64
  })
69
65
  }];
70
66
  }
@@ -86,7 +82,7 @@ const Wizard = _ref => {
86
82
  children: [(0, _jsxRuntime.jsx)(_.Button, {
87
83
  isLink: true,
88
84
  href: newspack_urls.dashboard,
89
- label: __('Return to Dashboard', 'newspack'),
85
+ label: __('Return to Dashboard', 'newspack-plugin'),
90
86
  showTooltip: true,
91
87
  icon: _icons.category,
92
88
  iconSize: 36,
@@ -127,5 +123,4 @@ const Wizard = _ref => {
127
123
  };
128
124
  Wizard.useWizardData = _utils.useWizardData;
129
125
  Wizard.STORE_NAMESPACE = _store.WIZARD_STORE_NAMESPACE;
130
- var _default = Wizard;
131
- exports.default = _default;
126
+ var _default = exports.default = Wizard;
@@ -19,8 +19,7 @@ var _utils = require("./utils.js");
19
19
  * WordPress dependencies.
20
20
  */
21
21
 
22
- const WIZARD_STORE_NAMESPACE = 'newspack/wizards';
23
- exports.WIZARD_STORE_NAMESPACE = WIZARD_STORE_NAMESPACE;
22
+ const WIZARD_STORE_NAMESPACE = exports.WIZARD_STORE_NAMESPACE = 'newspack/wizards';
24
23
  const DEFAULT_STATE = {
25
24
  isLoading: true,
26
25
  isQuietLoading: false,
@@ -34,12 +33,10 @@ const DEFAULT_STATE = {
34
33
  * unless the state was cloned first.
35
34
  */
36
35
  const clone = objectToClone => JSON.parse(JSON.stringify(objectToClone));
37
- const reducer = function () {
38
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
39
- let {
40
- type,
41
- payload = {}
42
- } = arguments.length > 1 ? arguments[1] : undefined;
36
+ const reducer = (state = DEFAULT_STATE, {
37
+ type,
38
+ payload = {}
39
+ }) => {
43
40
  switch (type) {
44
41
  case 'START_LOADING_DATA':
45
42
  if (payload.isQuietLoading) {
@@ -80,36 +77,38 @@ const actions = {
80
77
  updateWizardSettings: (0, _utils.createAction)('UPDATE_WIZARD_SETTINGS'),
81
78
  setError: (0, _utils.createAction)('SET_ERROR'),
82
79
  // Async actions. These will not show up in Redux devtools.
83
- saveWizardSettings(_ref) {
84
- let {
85
- slug,
86
- section = '',
87
- payloadPath = false,
88
- updatePayload = null
89
- } = _ref;
90
- return function* () {
91
- // Optionally data can be updated before saving - an immediate update case
92
- // (without an explicit "save" action).
93
- if (updatePayload) {
94
- yield actions.updateWizardSettings({
95
- slug,
96
- ...updatePayload
97
- });
98
- }
99
- const wizardState = (0, _data.select)(WIZARD_STORE_NAMESPACE).getWizardAPIData(slug);
100
- const updatedData = yield actions.fetchFromAPI({
101
- path: `/newspack/v1/wizard/${slug}/${section}`,
102
- method: 'POST',
103
- data: payloadPath ? (0, _get.default)(wizardState, payloadPath) : wizardState,
104
- isQuietFetch: true
80
+ *saveWizardSettings({
81
+ slug,
82
+ section = '',
83
+ payloadPath = false,
84
+ auxData = {},
85
+ updatePayload = null
86
+ }) {
87
+ // Optionally data can be updated before saving - an immediate update case
88
+ // (without an explicit "save" action).
89
+ if (updatePayload) {
90
+ yield actions.updateWizardSettings({
91
+ slug,
92
+ ...updatePayload
105
93
  });
106
- if (!(0, _isEmpty.default)(updatedData) && !updatedData.error) {
107
- return actions.setAPIDataForWizard({
108
- slug,
109
- data: updatedData
110
- });
111
- }
112
- }();
94
+ }
95
+ const wizardState = (0, _data.select)(WIZARD_STORE_NAMESPACE).getWizardAPIData(slug);
96
+ const data = payloadPath ? (0, _get.default)(wizardState, payloadPath) : wizardState;
97
+ const updatedData = yield actions.fetchFromAPI({
98
+ path: `/newspack/v1/wizard/${slug}/${section}`,
99
+ method: 'POST',
100
+ data: {
101
+ ...data,
102
+ ...auxData
103
+ },
104
+ isQuietFetch: true
105
+ });
106
+ if (!(0, _isEmpty.default)(updatedData) && !updatedData.error) {
107
+ return actions.setAPIDataForWizard({
108
+ slug,
109
+ data: updatedData
110
+ });
111
+ }
113
112
  },
114
113
  *wizardApiFetch(fetchConfig) {
115
114
  // Just a proxy to fetchFromAPI, but it has to be a generator.
@@ -19,8 +19,5 @@ const createAction = type => payload => ({
19
19
  payload
20
20
  });
21
21
  exports.createAction = createAction;
22
- const useWizardData = function (wizardName) {
23
- let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24
- return (0, _data.useSelect)(select => select(_.WIZARD_STORE_NAMESPACE).getWizardAPIData(`newspack-${wizardName}-wizard`)) || defaultValue;
25
- };
22
+ const useWizardData = (wizardName, defaultValue = {}) => (0, _data.useSelect)(select => select(_.WIZARD_STORE_NAMESPACE).getWizardAPIData(`newspack-${wizardName}-wizard`)) || defaultValue;
26
23
  exports.useWizardData = useWizardData;
@@ -20,11 +20,10 @@ import './style.scss';
20
20
  * External dependencies
21
21
  */
22
22
  import classnames from 'classnames';
23
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
24
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
23
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
25
24
  class ActionCard extends Component {
26
- constructor() {
27
- super(...arguments);
25
+ constructor(...args) {
26
+ super(...args);
28
27
  _defineProperty(this, "state", {
29
28
  expanded: false
30
29
  });
@@ -18,8 +18,7 @@ import './style.scss';
18
18
  /**
19
19
  * An multi-selecting, api-driven autocomplete input suitable for use in block attributes.
20
20
  */
21
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
22
- import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
21
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
23
22
  class AutocompleteTokenField extends Component {
24
23
  constructor(props) {
25
24
  super(props);
@@ -65,6 +64,31 @@ class AutocompleteTokenField extends Component {
65
64
  }
66
65
  }
67
66
 
67
+ /**
68
+ * When the component updates, fetch information about the tokens so we can populate
69
+ * the tokens with the correct labels.
70
+ */
71
+ componentDidUpdate(prevProps) {
72
+ const {
73
+ tokens,
74
+ fetchSavedInfo
75
+ } = this.props;
76
+ if (tokens !== prevProps.tokens && this.isFetchingInfoOnLoad()) {
77
+ fetchSavedInfo(tokens).then(results => {
78
+ const {
79
+ validValues
80
+ } = this.state;
81
+ results.forEach(suggestion => {
82
+ validValues[suggestion.value] = suggestion.label;
83
+ });
84
+ this.setState({
85
+ validValues,
86
+ loading: false
87
+ });
88
+ });
89
+ }
90
+ }
91
+
68
92
  /**
69
93
  * Clean up any unfinished autocomplete api call requests.
70
94
  */
@@ -111,8 +135,10 @@ class AutocompleteTokenField extends Component {
111
135
  return labels.reduce((acc, label) => {
112
136
  Object.keys(validValues).forEach(key => {
113
137
  if (validValues[key] === label) {
138
+ // Preserve numeric or string type of values. Object.keys will convert numbers to strings.
139
+ const value = isNaN(parseInt(key)) ? key.toString() : parseInt(key);
114
140
  acc.push({
115
- value: key,
141
+ value,
116
142
  label
117
143
  });
118
144
  }
@@ -120,7 +146,7 @@ class AutocompleteTokenField extends Component {
120
146
  return acc;
121
147
  }, []);
122
148
  }
123
- return labels.map(label => Object.keys(validValues).find(key => validValues[key] === label));
149
+ return labels.map(label => Object.keys(validValues).map(key => isNaN(parseInt(key)) ? key.toString() : parseInt(key)).find(key => validValues[key] === label));
124
150
  }
125
151
 
126
152
  /**
@@ -146,14 +172,16 @@ class AutocompleteTokenField extends Component {
146
172
  if (this.suggestionsRequest !== request) {
147
173
  return;
148
174
  }
175
+ const {
176
+ validValues
177
+ } = this.state;
149
178
  const currentSuggestions = [...suggestions];
150
- const currentValidValues = {};
151
179
  suggestions.forEach(suggestion => {
152
- currentValidValues[suggestion.value] = suggestion.label;
180
+ validValues[suggestion.value] = suggestion.label;
153
181
  });
154
182
  this.setState({
155
183
  suggestions: currentSuggestions,
156
- validValues: currentValidValues,
184
+ validValues,
157
185
  loading: false
158
186
  });
159
187
  }).catch(() => {
@@ -198,22 +226,31 @@ class AutocompleteTokenField extends Component {
198
226
  const {
199
227
  help,
200
228
  label = '',
229
+ placeholder = '',
201
230
  maxLength
202
231
  } = this.props;
203
232
  const {
204
233
  suggestions,
205
234
  loading
206
235
  } = this.state;
236
+ const classNames = ['newspack-autocomplete-tokenfield__input-container'];
237
+ if (label) {
238
+ classNames.push('has-label');
239
+ }
207
240
  return _jsxs("div", {
208
241
  className: "newspack-autocomplete-tokenfield",
209
- children: [_jsx(FormTokenField, {
210
- value: this.getTokens(),
211
- suggestions: suggestions.map(suggestion => suggestion.label),
212
- onChange: tokens => this.handleOnChange(tokens),
213
- onInputChange: input => this.debouncedUpdateSuggestions(input),
214
- label: label,
215
- maxLength: maxLength
216
- }), loading && _jsx(Spinner, {}), help && _jsx("p", {
242
+ children: [_jsxs("div", {
243
+ className: classNames.join(' '),
244
+ children: [_jsx(FormTokenField, {
245
+ value: this.getTokens(),
246
+ suggestions: suggestions.map(suggestion => suggestion.label),
247
+ onChange: tokens => this.handleOnChange(tokens),
248
+ onInputChange: input => this.debouncedUpdateSuggestions(input),
249
+ label: label,
250
+ maxLength: maxLength,
251
+ placeholder: placeholder
252
+ }), loading && _jsx(Spinner, {})]
253
+ }), help && _jsx("p", {
217
254
  className: "newspack-autocomplete-tokenfield__help",
218
255
  children: help
219
256
  })]
@@ -5,13 +5,19 @@
5
5
  @use '~@wordpress/base-styles/colors' as wp-colors;
6
6
 
7
7
  .newspack-autocomplete-tokenfield {
8
- position: relative;
9
-
10
8
  .components-spinner {
11
- margin: 8px;
9
+ margin: 0;
12
10
  position: absolute;
13
- right: 0;
14
- top: calc( 1.4em + 8px );
11
+ right: 8px;
12
+ top: 8px;
13
+ }
14
+
15
+ &__input-container {
16
+ position: relative;
17
+
18
+ &.has-label .components-spinner {
19
+ top: 32px;
20
+ }
15
21
  }
16
22
 
17
23
  /* Workaround for hard-coded help text in FormTokenField. */