newspack-components 3.0.0-alpha.2 → 3.0.0-alpha.4

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 (227) hide show
  1. package/babel.config.cjs.js +26 -0
  2. package/babel.config.js +1 -0
  3. package/copy-styles.js +10 -2
  4. package/dist/cjs/button/index.js +56 -0
  5. package/dist/cjs/grid/index.js +37 -0
  6. package/dist/cjs/hooks/index.js +25 -0
  7. package/dist/cjs/hooks/usePrompt.js +49 -0
  8. package/dist/cjs/text-control/index.js +64 -0
  9. package/dist/esm/accordion/index.js +42 -0
  10. package/dist/esm/accordion/style.scss +31 -0
  11. package/dist/esm/action-card/index.js +218 -0
  12. package/dist/esm/action-card/style.scss +483 -0
  13. package/dist/esm/autocomplete-tokenfield/index.js +261 -0
  14. package/dist/esm/autocomplete-tokenfield/style.scss +49 -0
  15. package/dist/esm/autocomplete-with-suggestions/index.js +274 -0
  16. package/dist/esm/autocomplete-with-suggestions/style.scss +163 -0
  17. package/dist/esm/button/index.js +48 -0
  18. package/dist/esm/button/style.scss +11 -0
  19. package/dist/esm/button-card/index.js +64 -0
  20. package/dist/esm/button-card/style.scss +180 -0
  21. package/dist/esm/card/index.js +43 -0
  22. package/dist/esm/card/style.scss +168 -0
  23. package/dist/esm/category-autocomplete/index.js +183 -0
  24. package/dist/esm/category-autocomplete/style.scss +34 -0
  25. package/dist/esm/color-picker/index.js +59 -0
  26. package/dist/esm/color-picker/style.scss +37 -0
  27. package/dist/esm/consts.js +1 -0
  28. package/dist/esm/custom-select-control/index.js +37 -0
  29. package/dist/esm/custom-select-control/style.scss +93 -0
  30. package/dist/esm/date-range-picker/index.js +31 -0
  31. package/dist/esm/date-range-picker/style.scss +148 -0
  32. package/dist/esm/footer/index.js +99 -0
  33. package/dist/esm/footer/style.scss +82 -0
  34. package/dist/esm/form-token-field/index.js +49 -0
  35. package/dist/esm/form-token-field/style.scss +37 -0
  36. package/dist/esm/global-notices/index.js +30 -0
  37. package/dist/esm/grid/index.js +29 -0
  38. package/dist/esm/grid/style.scss +166 -0
  39. package/dist/esm/handoff/index.js +175 -0
  40. package/dist/esm/handoff-message/index.js +47 -0
  41. package/dist/esm/hooks/index.js +17 -0
  42. package/dist/esm/hooks/useObjectState.js +30 -0
  43. package/dist/esm/hooks/useObjectState.test.js +82 -0
  44. package/dist/esm/hooks/useOnClickOutside.js +31 -0
  45. package/dist/esm/hooks/usePrompt.js +40 -0
  46. package/dist/esm/image-upload/index.js +140 -0
  47. package/dist/esm/image-upload/index.test.js +34 -0
  48. package/dist/esm/image-upload/style.scss +103 -0
  49. package/dist/esm/index.js +47 -0
  50. package/dist/esm/info-button/index.js +42 -0
  51. package/dist/esm/info-button/style.scss +18 -0
  52. package/dist/esm/modal/index.js +39 -0
  53. package/dist/esm/modal/style.scss +56 -0
  54. package/dist/esm/newspack-icon/index.js +50 -0
  55. package/dist/esm/newspack-icon/style.scss +26 -0
  56. package/dist/esm/newspack-logo/index.js +46 -0
  57. package/dist/esm/newspack-logo/style.scss +30 -0
  58. package/dist/esm/notice/index.js +65 -0
  59. package/dist/esm/notice/style.scss +111 -0
  60. package/dist/esm/patrons-logo/index.js +70 -0
  61. package/dist/esm/plugin-installer/index.js +289 -0
  62. package/dist/esm/plugin-installer/style.scss +72 -0
  63. package/dist/esm/plugin-settings/SettingsSection.js +133 -0
  64. package/dist/esm/plugin-settings/index.js +220 -0
  65. package/dist/esm/plugin-settings/style.scss +7 -0
  66. package/dist/esm/plugin-toggle/index.js +216 -0
  67. package/dist/esm/plugin-toggle/style.scss +20 -0
  68. package/dist/esm/popover/index.js +41 -0
  69. package/dist/esm/popover/style.scss +161 -0
  70. package/dist/esm/position-control/index.js +106 -0
  71. package/dist/esm/position-control/style.scss +66 -0
  72. package/dist/esm/progress-bar/index.js +68 -0
  73. package/dist/esm/progress-bar/index.test.js +108 -0
  74. package/dist/esm/progress-bar/style.scss +42 -0
  75. package/dist/esm/proxied-imports/router.js +8 -0
  76. package/dist/esm/radio-control/index.js +37 -0
  77. package/dist/esm/radio-control/style.scss +92 -0
  78. package/dist/esm/section-header/index.js +67 -0
  79. package/dist/esm/section-header/style.scss +45 -0
  80. package/dist/esm/select-control/ButtonGroupControl.js +53 -0
  81. package/dist/esm/select-control/GroupedSelectControl.js +78 -0
  82. package/dist/esm/select-control/index.js +51 -0
  83. package/dist/esm/select-control/style.scss +108 -0
  84. package/dist/esm/settings/MinMaxSetting.js +53 -0
  85. package/dist/esm/settings/SettingsCard.js +38 -0
  86. package/dist/esm/settings/SettingsSection.js +26 -0
  87. package/dist/esm/settings/index.js +9 -0
  88. package/dist/esm/settings/style.scss +119 -0
  89. package/dist/esm/sortable-newsletter-list-control/index.js +127 -0
  90. package/dist/esm/sortable-newsletter-list-control/style.scss +45 -0
  91. package/dist/esm/steps-list/index.js +43 -0
  92. package/dist/esm/steps-list/style.scss +11 -0
  93. package/dist/esm/steps-list-item/index.js +47 -0
  94. package/dist/esm/steps-list-item/style.scss +47 -0
  95. package/dist/esm/style-card/index.js +74 -0
  96. package/dist/esm/style-card/style.scss +94 -0
  97. package/dist/esm/style.scss +55 -0
  98. package/dist/esm/tabbed-navigation/index.js +53 -0
  99. package/dist/esm/tabbed-navigation/style.scss +86 -0
  100. package/dist/esm/text-control/index.js +56 -0
  101. package/dist/esm/text-control/style.scss +32 -0
  102. package/dist/esm/utils/index.js +29 -0
  103. package/dist/esm/waiting/index.js +44 -0
  104. package/dist/esm/waiting/style.scss +27 -0
  105. package/dist/esm/web-preview/index.js +183 -0
  106. package/dist/esm/web-preview/style.scss +155 -0
  107. package/dist/esm/with-wizard/index.js +320 -0
  108. package/dist/esm/with-wizard/style.scss +282 -0
  109. package/dist/esm/with-wizard-screen/index.js +109 -0
  110. package/dist/esm/with-wizard-screen/style.scss +160 -0
  111. package/dist/esm/wizard/components/WizardError.js +66 -0
  112. package/dist/esm/wizard/index.js +119 -0
  113. package/dist/esm/wizard/store/index.js +155 -0
  114. package/dist/esm/wizard/store/utils.js +14 -0
  115. package/package.json +8 -4
  116. package/dist/button/index.js +0 -51
  117. package/dist/button/index.tsx +0 -48
  118. package/dist/grid/index.js +0 -44
  119. package/dist/grid/index.tsx +0 -34
  120. package/dist/hooks/index.js +0 -29
  121. package/dist/hooks/index.ts +0 -15
  122. package/dist/hooks/usePrompt.js +0 -47
  123. package/dist/hooks/usePrompt.ts +0 -46
  124. package/dist/plugin-toggle/README.md +0 -53
  125. package/dist/text-control/index.js +0 -76
  126. package/dist/text-control/index.tsx +0 -71
  127. /package/dist/{accordion → cjs/accordion}/index.js +0 -0
  128. /package/dist/{accordion → cjs/accordion}/style.scss +0 -0
  129. /package/dist/{action-card → cjs/action-card}/index.js +0 -0
  130. /package/dist/{action-card → cjs/action-card}/style.scss +0 -0
  131. /package/dist/{autocomplete-tokenfield → cjs/autocomplete-tokenfield}/index.js +0 -0
  132. /package/dist/{autocomplete-tokenfield → cjs/autocomplete-tokenfield}/style.scss +0 -0
  133. /package/dist/{autocomplete-with-suggestions → cjs/autocomplete-with-suggestions}/index.js +0 -0
  134. /package/dist/{autocomplete-with-suggestions → cjs/autocomplete-with-suggestions}/style.scss +0 -0
  135. /package/dist/{button → cjs/button}/style.scss +0 -0
  136. /package/dist/{button-card → cjs/button-card}/index.js +0 -0
  137. /package/dist/{button-card → cjs/button-card}/style.scss +0 -0
  138. /package/dist/{card → cjs/card}/index.js +0 -0
  139. /package/dist/{card → cjs/card}/style.scss +0 -0
  140. /package/dist/{category-autocomplete → cjs/category-autocomplete}/index.js +0 -0
  141. /package/dist/{category-autocomplete → cjs/category-autocomplete}/style.scss +0 -0
  142. /package/dist/{color-picker → cjs/color-picker}/index.js +0 -0
  143. /package/dist/{color-picker → cjs/color-picker}/style.scss +0 -0
  144. /package/dist/{consts.js → cjs/consts.js} +0 -0
  145. /package/dist/{custom-select-control → cjs/custom-select-control}/index.js +0 -0
  146. /package/dist/{custom-select-control → cjs/custom-select-control}/style.scss +0 -0
  147. /package/dist/{date-range-picker → cjs/date-range-picker}/index.js +0 -0
  148. /package/dist/{date-range-picker → cjs/date-range-picker}/style.scss +0 -0
  149. /package/dist/{footer → cjs/footer}/index.js +0 -0
  150. /package/dist/{footer → cjs/footer}/style.scss +0 -0
  151. /package/dist/{form-token-field → cjs/form-token-field}/index.js +0 -0
  152. /package/dist/{form-token-field → cjs/form-token-field}/style.scss +0 -0
  153. /package/dist/{global-notices → cjs/global-notices}/index.js +0 -0
  154. /package/dist/{grid → cjs/grid}/style.scss +0 -0
  155. /package/dist/{handoff → cjs/handoff}/index.js +0 -0
  156. /package/dist/{handoff-message → cjs/handoff-message}/index.js +0 -0
  157. /package/dist/{hooks → cjs/hooks}/useObjectState.js +0 -0
  158. /package/dist/{hooks → cjs/hooks}/useObjectState.test.js +0 -0
  159. /package/dist/{hooks → cjs/hooks}/useOnClickOutside.js +0 -0
  160. /package/dist/{image-upload → cjs/image-upload}/index.js +0 -0
  161. /package/dist/{image-upload → cjs/image-upload}/index.test.js +0 -0
  162. /package/dist/{image-upload → cjs/image-upload}/style.scss +0 -0
  163. /package/dist/{index.js → cjs/index.js} +0 -0
  164. /package/dist/{info-button → cjs/info-button}/index.js +0 -0
  165. /package/dist/{info-button → cjs/info-button}/style.scss +0 -0
  166. /package/dist/{modal → cjs/modal}/index.js +0 -0
  167. /package/dist/{modal → cjs/modal}/style.scss +0 -0
  168. /package/dist/{newspack-icon → cjs/newspack-icon}/index.js +0 -0
  169. /package/dist/{newspack-icon → cjs/newspack-icon}/style.scss +0 -0
  170. /package/dist/{newspack-logo → cjs/newspack-logo}/index.js +0 -0
  171. /package/dist/{newspack-logo → cjs/newspack-logo}/style.scss +0 -0
  172. /package/dist/{notice → cjs/notice}/index.js +0 -0
  173. /package/dist/{notice → cjs/notice}/style.scss +0 -0
  174. /package/dist/{patrons-logo → cjs/patrons-logo}/index.js +0 -0
  175. /package/dist/{plugin-installer → cjs/plugin-installer}/index.js +0 -0
  176. /package/dist/{plugin-installer → cjs/plugin-installer}/style.scss +0 -0
  177. /package/dist/{plugin-settings → cjs/plugin-settings}/SettingsSection.js +0 -0
  178. /package/dist/{plugin-settings → cjs/plugin-settings}/index.js +0 -0
  179. /package/dist/{plugin-settings → cjs/plugin-settings}/style.scss +0 -0
  180. /package/dist/{plugin-toggle → cjs/plugin-toggle}/index.js +0 -0
  181. /package/dist/{plugin-toggle → cjs/plugin-toggle}/style.scss +0 -0
  182. /package/dist/{popover → cjs/popover}/index.js +0 -0
  183. /package/dist/{popover → cjs/popover}/style.scss +0 -0
  184. /package/dist/{position-control → cjs/position-control}/index.js +0 -0
  185. /package/dist/{position-control → cjs/position-control}/style.scss +0 -0
  186. /package/dist/{progress-bar → cjs/progress-bar}/index.js +0 -0
  187. /package/dist/{progress-bar → cjs/progress-bar}/index.test.js +0 -0
  188. /package/dist/{progress-bar → cjs/progress-bar}/style.scss +0 -0
  189. /package/dist/{proxied-imports → cjs/proxied-imports}/router.js +0 -0
  190. /package/dist/{radio-control → cjs/radio-control}/index.js +0 -0
  191. /package/dist/{radio-control → cjs/radio-control}/style.scss +0 -0
  192. /package/dist/{section-header → cjs/section-header}/index.js +0 -0
  193. /package/dist/{section-header → cjs/section-header}/style.scss +0 -0
  194. /package/dist/{select-control → cjs/select-control}/ButtonGroupControl.js +0 -0
  195. /package/dist/{select-control → cjs/select-control}/GroupedSelectControl.js +0 -0
  196. /package/dist/{select-control → cjs/select-control}/index.js +0 -0
  197. /package/dist/{select-control → cjs/select-control}/style.scss +0 -0
  198. /package/dist/{settings → cjs/settings}/MinMaxSetting.js +0 -0
  199. /package/dist/{settings → cjs/settings}/SettingsCard.js +0 -0
  200. /package/dist/{settings → cjs/settings}/SettingsSection.js +0 -0
  201. /package/dist/{settings → cjs/settings}/index.js +0 -0
  202. /package/dist/{settings → cjs/settings}/style.scss +0 -0
  203. /package/dist/{sortable-newsletter-list-control → cjs/sortable-newsletter-list-control}/index.js +0 -0
  204. /package/dist/{sortable-newsletter-list-control → cjs/sortable-newsletter-list-control}/style.scss +0 -0
  205. /package/dist/{steps-list → cjs/steps-list}/index.js +0 -0
  206. /package/dist/{steps-list → cjs/steps-list}/style.scss +0 -0
  207. /package/dist/{steps-list-item → cjs/steps-list-item}/index.js +0 -0
  208. /package/dist/{steps-list-item → cjs/steps-list-item}/style.scss +0 -0
  209. /package/dist/{style-card → cjs/style-card}/index.js +0 -0
  210. /package/dist/{style-card → cjs/style-card}/style.scss +0 -0
  211. /package/dist/{style.scss → cjs/style.scss} +0 -0
  212. /package/dist/{tabbed-navigation → cjs/tabbed-navigation}/index.js +0 -0
  213. /package/dist/{tabbed-navigation → cjs/tabbed-navigation}/style.scss +0 -0
  214. /package/dist/{text-control → cjs/text-control}/style.scss +0 -0
  215. /package/dist/{utils → cjs/utils}/index.js +0 -0
  216. /package/dist/{waiting → cjs/waiting}/index.js +0 -0
  217. /package/dist/{waiting → cjs/waiting}/style.scss +0 -0
  218. /package/dist/{web-preview → cjs/web-preview}/index.js +0 -0
  219. /package/dist/{web-preview → cjs/web-preview}/style.scss +0 -0
  220. /package/dist/{with-wizard → cjs/with-wizard}/index.js +0 -0
  221. /package/dist/{with-wizard → cjs/with-wizard}/style.scss +0 -0
  222. /package/dist/{with-wizard-screen → cjs/with-wizard-screen}/index.js +0 -0
  223. /package/dist/{with-wizard-screen → cjs/with-wizard-screen}/style.scss +0 -0
  224. /package/dist/{wizard → cjs/wizard}/components/WizardError.js +0 -0
  225. /package/dist/{wizard → cjs/wizard}/index.js +0 -0
  226. /package/dist/{wizard → cjs/wizard}/store/index.js +0 -0
  227. /package/dist/{wizard → cjs/wizard}/store/utils.js +0 -0
@@ -0,0 +1,26 @@
1
+ module.exports = api => {
2
+ api.cache( true );
3
+ return {
4
+ extends: 'newspack-scripts/config/babel.config.js',
5
+ presets: [
6
+ [
7
+ '@babel/preset-env',
8
+ {
9
+ corejs: 3.6,
10
+ useBuiltIns: 'entry',
11
+ // Exclude transforms that make all code slower, see https://github.com/facebook/create-react-app/pull/5278
12
+ exclude: [ 'transform-typeof-symbol' ],
13
+ modules: 'commonjs',
14
+ },
15
+ ],
16
+ [
17
+ '@babel/preset-react',
18
+ {
19
+ runtime: 'automatic',
20
+ importSource: process.env.IMPORT_SOURCE,
21
+ },
22
+ ],
23
+ [ '@babel/preset-typescript', { allowDeclareFields: true } ],
24
+ ],
25
+ };
26
+ };
package/babel.config.js CHANGED
@@ -10,6 +10,7 @@ module.exports = api => {
10
10
  useBuiltIns: 'entry',
11
11
  // Exclude transforms that make all code slower, see https://github.com/facebook/create-react-app/pull/5278
12
12
  exclude: [ 'transform-typeof-symbol' ],
13
+ modules: false,
13
14
  },
14
15
  ],
15
16
  [
package/copy-styles.js CHANGED
@@ -9,7 +9,8 @@ const rcopy = require( 'recursive-copy' );
9
9
  const dir = process.cwd();
10
10
 
11
11
  const inputDir = path.join( dir, 'src' );
12
- const outputDir = path.join( dir, 'dist' );
12
+ const outputDirEsm = path.join( dir, 'dist', 'esm' );
13
+ const outputDirCommon = path.join( dir, 'dist', 'cjs' );
13
14
 
14
15
  console.log( 'Copying styles %s', dir );
15
16
 
@@ -20,7 +21,14 @@ const copyOptions = {
20
21
  debug: true,
21
22
  };
22
23
 
23
- rcopy( inputDir, outputDir, copyOptions )
24
+ rcopy( inputDir, outputDirEsm, copyOptions )
25
+ .then( results => {
26
+ console.log( 'copied %d files', results.length );
27
+ } )
28
+ .catch( err => {
29
+ console.error( err );
30
+ } );
31
+ rcopy( inputDir, outputDirCommon, copyOptions )
24
32
  .then( results => {
25
33
  console.log( 'copied %d files', results.length );
26
34
  } )
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _components = require("@wordpress/components");
9
+ var _element = require("@wordpress/element");
10
+ var _router = _interopRequireDefault(require("../proxied-imports/router"));
11
+ require("./style.scss");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ /**
14
+ * Button
15
+ */
16
+
17
+ /**
18
+ * WordPress dependencies.
19
+ */
20
+
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+
25
+ const {
26
+ useHistory
27
+ } = _router.default;
28
+ const Button = ({
29
+ href,
30
+ onClick,
31
+ ...otherProps
32
+ }) => {
33
+ const history = useHistory();
34
+ const [isAwaitingOnClick, setIsAwaitingOnClick] = (0, _element.useState)(false);
35
+
36
+ // If both onClick and href are present, await the onClick action an then redirect.
37
+ if (href && onClick) {
38
+ otherProps.onClick = async () => {
39
+ setIsAwaitingOnClick(true);
40
+ await onClick();
41
+ setIsAwaitingOnClick(false);
42
+ history.push((href || '').replace('#', ''));
43
+ };
44
+ } else {
45
+ otherProps.href = href;
46
+ otherProps.onClick = onClick;
47
+ }
48
+ if (isAwaitingOnClick) {
49
+ otherProps.disabled = true;
50
+ }
51
+ // @ts-ignore - @wordpress/components' Button can only have either href or onClick, not both.
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
53
+ ...otherProps
54
+ });
55
+ };
56
+ var _default = exports.default = Button;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ require("./style.scss");
9
+ var _classnames = _interopRequireDefault(require("classnames"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * Grid
13
+ */
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+
19
+ /**
20
+ * External dependencies
21
+ */
22
+
23
+ const Grid = ({
24
+ className = '',
25
+ columns = 2,
26
+ gutter = 32,
27
+ noMargin = false,
28
+ rowGap = 0,
29
+ ...otherProps
30
+ }) => {
31
+ const classes = (0, _classnames.default)('newspack-grid', noMargin && 'newspack-grid--no-margin', columns && 'newspack-grid__columns-' + columns, gutter && 'newspack-grid__gutter-' + gutter, rowGap && 'newspack-grid__row-gap-' + rowGap, className);
32
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
33
+ className: classes,
34
+ ...otherProps
35
+ });
36
+ };
37
+ var _default = exports.default = Grid;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _element = require("@wordpress/element");
9
+ var _usePrompt = _interopRequireDefault(require("./usePrompt"));
10
+ var _useObjectState = _interopRequireDefault(require("./useObjectState"));
11
+ var _useOnClickOutside = _interopRequireDefault(require("./useOnClickOutside"));
12
+ /**
13
+ * WordPress dependencies
14
+ */
15
+
16
+ const useUniqueId = prefix => {
17
+ const id = (0, _element.useRef)(`${prefix}-${Math.round(Math.random() * 99999)}`);
18
+ return id.current;
19
+ };
20
+ var _default = exports.default = {
21
+ usePrompt: _usePrompt.default,
22
+ useObjectState: _useObjectState.default,
23
+ useOnClickOutside: _useOnClickOutside.default,
24
+ useUniqueId
25
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _element = require("@wordpress/element");
9
+ var _router = _interopRequireDefault(require("../proxied-imports/router"));
10
+ // https://gist.github.com/sibelius/60a4e11da1f826b8d60dc3975a1ac805
11
+
12
+ /**
13
+ * External dependencies.
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies.
18
+ */
19
+
20
+ const {
21
+ useHistory
22
+ } = _router.default;
23
+ var _default = (when, message) => {
24
+ const history = useHistory();
25
+ const self = (0, _element.useRef)(null);
26
+ const onWindowOrTabClose = event => {
27
+ if (!when) {
28
+ return;
29
+ }
30
+ if (typeof event === 'undefined') {
31
+ event = window.event;
32
+ }
33
+ return message;
34
+ };
35
+ (0, _element.useEffect)(() => {
36
+ if (when) {
37
+ self.current = history.block(message);
38
+ window.addEventListener('beforeunload', onWindowOrTabClose);
39
+ }
40
+ return () => {
41
+ if (self.current) {
42
+ self.current();
43
+ }
44
+ window.removeEventListener('beforeunload', onWindowOrTabClose);
45
+ };
46
+ }, [message, when]);
47
+ return self.current || (() => {});
48
+ };
49
+ exports.default = _default;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _components = require("@wordpress/components");
9
+ var _element = require("@wordpress/element");
10
+ var _i18n = require("@wordpress/i18n");
11
+ require("./style.scss");
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ /**
15
+ * Text Control
16
+ */
17
+
18
+ /**
19
+ * WordPress dependencies
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+
26
+ /**
27
+ * External dependencies
28
+ */
29
+
30
+ const TextControl = ({
31
+ className = '',
32
+ required = false,
33
+ isWide = false,
34
+ withMargin = true,
35
+ ...otherProps
36
+ }) => {
37
+ const wrapperRef = (0, _element.useRef)(null);
38
+ (0, _element.useEffect)(() => {
39
+ if (wrapperRef.current === null) {
40
+ return;
41
+ }
42
+ const labelEl = wrapperRef.current.querySelector('label');
43
+ if (labelEl) {
44
+ labelEl.setAttribute('data-required-text', (0, _i18n.__)('(required)', 'newspack-plugin'));
45
+ }
46
+ }, [wrapperRef.current]);
47
+ const classes = (0, _classnames.default)('newspack-text-control', {
48
+ 'newspack-text-control--wide': isWide,
49
+ 'newspack-text-control--with-margin': withMargin
50
+ }, className);
51
+ return required ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
52
+ ref: wrapperRef,
53
+ className: "newspack-text-control--required",
54
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
55
+ className: classes,
56
+ required: required,
57
+ ...otherProps
58
+ })
59
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
60
+ className: classes,
61
+ ...otherProps
62
+ });
63
+ };
64
+ var _default = exports.default = TextControl;
@@ -0,0 +1,42 @@
1
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
2
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
3
+
4
+ /**
5
+ * WordPress dependencies
6
+ */
7
+ import { useState } from '@wordpress/element';
8
+ import { Icon, chevronRight } from '@wordpress/icons';
9
+
10
+ /**
11
+ * External dependencies
12
+ */
13
+ import classNames from 'classnames';
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+ import './style.scss';
19
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
+ const Accordion = ({
21
+ children,
22
+ title
23
+ }) => {
24
+ const [isOpen, setIsOpen] = useState(false);
25
+ return /*#__PURE__*/_jsxs("details", {
26
+ className: classNames('newspack-accordion', {
27
+ 'newspack-accordion--is-open': isOpen
28
+ }),
29
+ children: [/*#__PURE__*/_jsxs("summary", {
30
+ onClick: () => setIsOpen(!isOpen),
31
+ children: [title, /*#__PURE__*/_jsx(Icon, {
32
+ className: "newspack-accordion__icon",
33
+ icon: chevronRight,
34
+ size: 24
35
+ })]
36
+ }), /*#__PURE__*/_jsx("div", {
37
+ className: "newspack-accordion__content",
38
+ children: children
39
+ })]
40
+ });
41
+ };
42
+ export default Accordion;
@@ -0,0 +1,31 @@
1
+ @use "~@wordpress/base-styles/colors" as wp-colors;
2
+
3
+ .newspack-accordion {
4
+ border: 1px solid wp-colors.$gray-300;
5
+
6
+ &__icon {
7
+ transition: transform 200ms ease-out;
8
+ transform: rotate(90deg);
9
+ }
10
+
11
+ &--is-open {
12
+ .newspack-accordion {
13
+ &__icon {
14
+ transform: rotate(-90deg);
15
+ }
16
+ }
17
+ }
18
+ summary {
19
+ padding: 16px 32px;
20
+ display: flex;
21
+ align-items: center;
22
+ justify-content: space-between;
23
+ cursor: pointer;
24
+ font-size: 14px;
25
+ font-weight: bold;
26
+ }
27
+
28
+ &__content {
29
+ padding: 16px 32px;
30
+ }
31
+ }
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Action Card
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies
7
+ */
8
+ import { Component } from '@wordpress/element';
9
+ import { ExternalLink, ToggleControl } from '@wordpress/components';
10
+ import { Icon, check, chevronDown, chevronUp } from '@wordpress/icons';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import { Button, Card, Grid, Handoff, Notice, Waiting } from '../';
16
+ import './style.scss';
17
+
18
+ /**
19
+ * External dependencies
20
+ */
21
+ import classnames from 'classnames';
22
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
+ class ActionCard extends Component {
24
+ state = {
25
+ expanded: false
26
+ };
27
+
28
+ /**
29
+ * When the collapse prop is updated to true, collapse the card if already expanded.
30
+ */
31
+ componentDidUpdate(prevProps) {
32
+ if (!prevProps.collapse && this.props.collapse && this.state.expanded) {
33
+ this.setState({
34
+ expanded: false
35
+ });
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Render.
41
+ */
42
+ render() {
43
+ const {
44
+ badge,
45
+ className,
46
+ checkbox,
47
+ children,
48
+ disabled,
49
+ title,
50
+ description,
51
+ handoff,
52
+ editLink,
53
+ href,
54
+ notification,
55
+ notificationLevel,
56
+ notificationHTML,
57
+ actionContent,
58
+ actionText,
59
+ secondaryActionText,
60
+ secondaryDestructive,
61
+ image,
62
+ imageLink,
63
+ indent,
64
+ isSmall,
65
+ isMedium,
66
+ simple,
67
+ onClick,
68
+ onSecondaryActionClick,
69
+ isWaiting,
70
+ titleLink,
71
+ toggleChecked,
72
+ toggleOnChange,
73
+ hasGreyHeader,
74
+ hasWhiteHeader,
75
+ isPending,
76
+ expandable = false
77
+ } = this.props;
78
+ const {
79
+ expanded
80
+ } = this.state;
81
+ const hasChildren = notification || children;
82
+ const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasWhiteHeader && 'newspack-card--has-white-header', hasChildren && 'newspack-card--has-children', indent && 'newspack-card--indent', isSmall && 'is-small', isMedium && 'is-medium', checkbox && 'has-checkbox', expandable && 'is-expandable', actionContent && 'has-action-content', className);
83
+ const backgroundImageStyles = url => {
84
+ return url ? {
85
+ backgroundImage: `url(${url})`
86
+ } : {};
87
+ };
88
+ const titleProps = toggleOnChange && !titleLink && !disabled ? {
89
+ onClick: () => toggleOnChange(!toggleChecked),
90
+ tabIndex: '0'
91
+ } : {};
92
+ const hasInternalLink = href && href.indexOf('http') !== 0;
93
+ const isDisplayingSecondaryAction = secondaryActionText && onSecondaryActionClick;
94
+ const badges = !Array.isArray(badge) && badge ? [badge] : badge;
95
+ return /*#__PURE__*/_jsxs(Card, {
96
+ className: classes,
97
+ onClick: simple && onClick,
98
+ children: [/*#__PURE__*/_jsxs("div", {
99
+ className: "newspack-action-card__region newspack-action-card__region-top",
100
+ children: [toggleOnChange && /*#__PURE__*/_jsx(ToggleControl, {
101
+ checked: toggleChecked,
102
+ onChange: toggleOnChange,
103
+ disabled: disabled
104
+ }), image && !toggleOnChange && /*#__PURE__*/_jsx("div", {
105
+ className: "newspack-action-card__region newspack-action-card__region-left",
106
+ children: /*#__PURE__*/_jsx("a", {
107
+ href: imageLink,
108
+ children: /*#__PURE__*/_jsx("div", {
109
+ className: "newspack-action-card__image",
110
+ style: backgroundImageStyles(image)
111
+ })
112
+ })
113
+ }), checkbox && !toggleOnChange && /*#__PURE__*/_jsx("div", {
114
+ className: "newspack-action-card__region newspack-action-card__region-left",
115
+ children: /*#__PURE__*/_jsx("span", {
116
+ className: classnames('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked', isPending && 'newspack-checkbox-icon--pending'),
117
+ children: 'checked' === checkbox && /*#__PURE__*/_jsx(Icon, {
118
+ icon: check
119
+ })
120
+ })
121
+ }), /*#__PURE__*/_jsx("div", {
122
+ className: "newspack-action-card__region newspack-action-card__region-center",
123
+ children: /*#__PURE__*/_jsxs(Grid, {
124
+ columns: 1,
125
+ gutter: 8,
126
+ noMargin: true,
127
+ children: [/*#__PURE__*/_jsxs("h2", {
128
+ children: [/*#__PURE__*/_jsxs("span", {
129
+ className: "newspack-action-card__title",
130
+ ...titleProps,
131
+ children: [titleLink && /*#__PURE__*/_jsx("a", {
132
+ href: titleLink,
133
+ children: title
134
+ }), !titleLink && expandable && /*#__PURE__*/_jsx(Button, {
135
+ isLink: true,
136
+ onClick: () => this.setState({
137
+ expanded: !expanded
138
+ }),
139
+ children: title
140
+ }), !titleLink && !expandable && title]
141
+ }), badges?.length && badges.map((badgeText, i) => /*#__PURE__*/_jsx("span", {
142
+ className: "newspack-action-card__badge",
143
+ children: badgeText
144
+ }, `badge-${i}`))]
145
+ }), description && /*#__PURE__*/_jsxs("p", {
146
+ children: [typeof description === 'string' && description, typeof description === 'function' && description()]
147
+ })]
148
+ })
149
+ }), !expandable && (actionText || isDisplayingSecondaryAction || actionContent) && /*#__PURE__*/_jsxs("div", {
150
+ className: "newspack-action-card__region newspack-action-card__region-right",
151
+ children: [actionContent && actionContent, actionText && (handoff ? /*#__PURE__*/_jsx(Handoff, {
152
+ plugin: handoff,
153
+ editLink: editLink,
154
+ compact: true,
155
+ isLink: true,
156
+ children: actionText
157
+ }) : onClick || hasInternalLink ? /*#__PURE__*/_jsx(Button, {
158
+ disabled: disabled,
159
+ isLink: true,
160
+ href: href,
161
+ onClick: onClick,
162
+ className: "newspack-action-card__primary_button",
163
+ children: actionText
164
+ }) : href ? /*#__PURE__*/_jsx(ExternalLink, {
165
+ href: href,
166
+ className: "newspack-action-card__primary_button",
167
+ children: actionText
168
+ }) : /*#__PURE__*/_jsxs("div", {
169
+ className: "newspack-action-card__container",
170
+ children: [actionText, isWaiting && /*#__PURE__*/_jsx(Waiting, {
171
+ isRight: true
172
+ })]
173
+ })), isDisplayingSecondaryAction && /*#__PURE__*/_jsx(Button, {
174
+ isLink: true,
175
+ onClick: onSecondaryActionClick,
176
+ className: "newspack-action-card__secondary_button",
177
+ isDestructive: secondaryDestructive,
178
+ children: secondaryActionText
179
+ })]
180
+ }), expandable && /*#__PURE__*/_jsx(Button, {
181
+ onClick: () => this.setState({
182
+ expanded: !expanded
183
+ }),
184
+ children: /*#__PURE__*/_jsx(Icon, {
185
+ icon: expanded ? chevronUp : chevronDown,
186
+ height: 24,
187
+ width: 24
188
+ })
189
+ })]
190
+ }), notification && /*#__PURE__*/_jsxs("div", {
191
+ className: "newspack-action-card__notification newspack-action-card__region-children",
192
+ children: ['error' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
193
+ noticeText: notification,
194
+ isError: true,
195
+ rawHTML: notificationHTML
196
+ }), 'info' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
197
+ noticeText: notification,
198
+ rawHTML: notificationHTML
199
+ }), 'success' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
200
+ noticeText: notification,
201
+ isSuccess: true,
202
+ rawHTML: notificationHTML
203
+ }), 'warning' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
204
+ noticeText: notification,
205
+ isWarning: true,
206
+ rawHTML: notificationHTML
207
+ })]
208
+ }), children && (expandable && expanded || !expandable) && /*#__PURE__*/_jsx("div", {
209
+ className: "newspack-action-card__region-children",
210
+ children: children
211
+ })]
212
+ });
213
+ }
214
+ }
215
+ ActionCard.defaultProps = {
216
+ toggleChecked: false
217
+ };
218
+ export default ActionCard;