newspack-components 2.2.1 → 3.0.0-alpha.2
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.
- package/babel.config.js +25 -0
- package/copy-styles.js +2 -10
- package/dist/{cjs/accordion → accordion}/index.js +17 -13
- package/dist/{cjs/accordion → accordion}/style.scss +7 -3
- package/dist/{cjs/action-card → action-card}/index.js +39 -43
- package/dist/{esm/action-card → action-card}/style.scss +9 -9
- package/dist/{cjs/autocomplete-tokenfield → autocomplete-tokenfield}/index.js +67 -29
- package/dist/{esm/autocomplete-tokenfield → autocomplete-tokenfield}/style.scss +14 -8
- package/dist/{cjs/autocomplete-with-suggestions → autocomplete-with-suggestions}/index.js +61 -73
- package/dist/{esm/autocomplete-with-suggestions → autocomplete-with-suggestions}/style.scss +9 -17
- package/dist/button/index.js +51 -0
- package/{src/button/index.js → dist/button/index.tsx} +12 -5
- package/dist/{cjs/button → button}/style.scss +1 -1
- package/dist/{cjs/button-card → button-card}/index.js +9 -10
- package/dist/{cjs/button-card → button-card}/style.scss +19 -13
- package/dist/{cjs/card → card}/index.js +4 -5
- package/dist/{esm/card → card}/style.scss +1 -1
- package/dist/{cjs/category-autocomplete → category-autocomplete}/index.js +51 -53
- package/dist/{esm/category-autocomplete → category-autocomplete}/style.scss +2 -2
- package/dist/{cjs/color-picker → color-picker}/index.js +14 -16
- package/dist/{cjs/color-picker → color-picker}/style.scss +3 -3
- package/dist/consts.js +7 -0
- package/dist/{cjs/custom-select-control → custom-select-control}/index.js +4 -5
- package/dist/{cjs/custom-select-control → custom-select-control}/style.scss +11 -10
- package/dist/{cjs/date-range-picker → date-range-picker}/index.js +9 -11
- package/dist/{cjs/date-range-picker → date-range-picker}/style.scss +6 -6
- package/dist/{cjs/footer → footer}/index.js +33 -36
- package/dist/{cjs/footer → footer}/style.scss +1 -1
- package/dist/{cjs/form-token-field → form-token-field}/index.js +6 -7
- package/dist/{esm/form-token-field → form-token-field}/style.scss +1 -1
- package/dist/{cjs/global-notices → global-notices}/index.js +4 -5
- package/dist/grid/index.js +44 -0
- package/dist/grid/index.tsx +34 -0
- package/dist/{cjs/grid → grid}/style.scss +9 -9
- package/dist/{cjs/handoff → handoff}/index.js +73 -71
- package/dist/{cjs/handoff-message → handoff-message}/index.js +5 -3
- package/dist/hooks/index.js +29 -0
- package/{src/hooks/index.js → dist/hooks/index.ts} +1 -1
- package/dist/{cjs/hooks → hooks}/useObjectState.js +2 -3
- package/dist/{cjs/hooks → hooks}/useObjectState.test.js +9 -9
- package/dist/{cjs/hooks → hooks}/useOnClickOutside.js +1 -2
- package/dist/hooks/usePrompt.js +47 -0
- package/{src/hooks/usePrompt.js → dist/hooks/usePrompt.ts} +4 -8
- package/dist/image-upload/index.js +148 -0
- package/dist/{cjs/image-upload → image-upload}/index.test.js +13 -6
- package/dist/{esm/image-upload → image-upload}/style.scss +5 -5
- package/dist/{cjs/index.js → index.js} +1 -1
- package/dist/{cjs/info-button → info-button}/index.js +6 -7
- package/dist/{cjs/modal → modal}/index.js +4 -5
- package/dist/{esm/modal → modal}/style.scss +5 -5
- package/dist/{cjs/newspack-icon → newspack-icon}/index.js +5 -6
- package/dist/{cjs/newspack-icon → newspack-icon}/style.scss +1 -1
- package/dist/{cjs/newspack-logo → newspack-logo}/index.js +5 -6
- package/dist/{cjs/newspack-logo → newspack-logo}/style.scss +1 -1
- package/dist/{cjs/notice → notice}/index.js +12 -10
- package/dist/{cjs/notice → notice}/style.scss +11 -11
- package/dist/patrons-logo/index.js +77 -0
- package/dist/plugin-installer/index.js +297 -0
- package/dist/{cjs/plugin-installer → plugin-installer}/style.scss +1 -1
- package/dist/{cjs/plugin-settings → plugin-settings}/SettingsSection.js +13 -13
- package/dist/plugin-settings/index.js +228 -0
- package/dist/{cjs/plugin-settings → plugin-settings}/style.scss +1 -1
- package/dist/plugin-toggle/README.md +53 -0
- package/dist/plugin-toggle/index.js +222 -0
- package/dist/{esm/plugin-toggle → plugin-toggle}/style.scss +1 -1
- package/dist/{cjs/popover → popover}/index.js +4 -5
- package/dist/{cjs/popover → popover}/style.scss +7 -7
- package/dist/{cjs/position-control → position-control}/index.js +33 -32
- package/dist/{cjs/position-control → position-control}/style.scss +8 -8
- package/dist/{cjs/progress-bar → progress-bar}/index.js +9 -10
- package/dist/{cjs/progress-bar → progress-bar}/index.test.js +16 -16
- package/dist/{cjs/progress-bar → progress-bar}/style.scss +2 -2
- package/dist/proxied-imports/router.js +15 -0
- package/dist/{cjs/radio-control → radio-control}/index.js +4 -5
- package/dist/{cjs/radio-control → radio-control}/style.scss +3 -3
- package/dist/{cjs/section-header → section-header}/index.js +20 -21
- package/dist/{esm/section-header → section-header}/style.scss +5 -1
- package/dist/{cjs/select-control → select-control}/ButtonGroupControl.js +17 -19
- package/dist/{cjs/select-control → select-control}/GroupedSelectControl.js +32 -35
- package/dist/{cjs/select-control → select-control}/index.js +7 -8
- package/dist/{cjs/select-control → select-control}/style.scss +4 -4
- package/dist/settings/MinMaxSetting.js +60 -0
- package/dist/{cjs/settings → settings}/SettingsCard.js +14 -16
- package/dist/settings/SettingsSection.js +33 -0
- package/dist/{cjs/settings → settings}/index.js +3 -4
- package/dist/{cjs/settings → settings}/style.scss +15 -2
- package/dist/sortable-newsletter-list-control/index.js +135 -0
- package/dist/sortable-newsletter-list-control/style.scss +45 -0
- package/dist/{cjs/steps-list → steps-list}/index.js +5 -6
- package/dist/{esm/steps-list → steps-list}/style.scss +2 -2
- package/dist/{cjs/steps-list-item → steps-list-item}/index.js +6 -7
- package/dist/{cjs/steps-list-item → steps-list-item}/style.scss +5 -5
- package/dist/{cjs/style-card → style-card}/index.js +21 -19
- package/dist/{esm/style-card → style-card}/style.scss +4 -4
- package/dist/{esm/style.scss → style.scss} +14 -2
- package/dist/{cjs/tabbed-navigation → tabbed-navigation}/index.js +16 -19
- package/dist/{cjs/tabbed-navigation → tabbed-navigation}/style.scss +4 -4
- package/dist/text-control/index.js +76 -0
- package/dist/text-control/index.tsx +71 -0
- package/dist/utils/index.js +36 -0
- package/dist/{cjs/waiting → waiting}/index.js +4 -5
- package/dist/web-preview/index.js +191 -0
- package/dist/{cjs/web-preview → web-preview}/style.scss +5 -5
- package/dist/with-wizard/index.js +328 -0
- package/dist/{esm/with-wizard → with-wizard}/style.scss +44 -22
- package/dist/{cjs/with-wizard-screen → with-wizard-screen}/index.js +40 -43
- package/dist/{esm/with-wizard-screen → with-wizard-screen}/style.scss +7 -7
- package/dist/{cjs/wizard → wizard}/components/WizardError.js +16 -17
- package/dist/{cjs/wizard → wizard}/index.js +44 -46
- package/dist/{cjs/wizard → wizard}/store/index.js +37 -38
- package/dist/{cjs/wizard → wizard}/store/utils.js +1 -4
- package/package.json +16 -14
- package/shared/scss/_mixins.scss +2 -2
- package/src/accordion/index.js +4 -1
- package/src/accordion/style.scss +7 -3
- package/src/action-card/style.scss +9 -9
- package/src/autocomplete-tokenfield/index.js +48 -15
- package/src/autocomplete-tokenfield/style.scss +14 -8
- package/src/autocomplete-with-suggestions/index.js +59 -62
- package/src/autocomplete-with-suggestions/style.scss +9 -17
- package/src/button/index.tsx +48 -0
- package/src/button/style.scss +1 -1
- package/src/button-card/style.scss +19 -13
- package/src/card/style.scss +1 -1
- package/src/category-autocomplete/style.scss +2 -2
- package/src/color-picker/style.scss +3 -3
- package/src/consts.js +0 -2
- package/src/custom-select-control/style.scss +11 -10
- package/src/date-range-picker/style.scss +6 -6
- package/src/footer/index.js +7 -7
- package/src/footer/style.scss +1 -1
- package/src/form-token-field/style.scss +1 -1
- package/src/grid/index.tsx +34 -0
- package/src/grid/style.scss +9 -9
- package/src/handoff/index.js +7 -6
- package/src/handoff-message/index.js +3 -1
- package/src/hooks/index.ts +15 -0
- package/src/hooks/usePrompt.ts +46 -0
- package/src/image-upload/index.js +5 -5
- package/src/image-upload/index.test.js +6 -1
- package/src/image-upload/style.scss +5 -5
- package/src/modal/style.scss +5 -5
- package/src/newspack-icon/style.scss +1 -1
- package/src/newspack-logo/style.scss +1 -1
- package/src/notice/index.js +1 -1
- package/src/notice/style.scss +11 -11
- package/src/patrons-logo/index.js +4 -1
- package/src/plugin-installer/index.js +7 -7
- package/src/plugin-installer/style.scss +1 -1
- package/src/plugin-settings/index.js +1 -1
- package/src/plugin-settings/style.scss +1 -1
- package/src/plugin-toggle/index.js +13 -12
- package/src/plugin-toggle/style.scss +1 -1
- package/src/popover/style.scss +7 -7
- package/src/position-control/index.js +63 -64
- package/src/position-control/style.scss +8 -8
- package/src/progress-bar/style.scss +2 -2
- package/src/radio-control/style.scss +3 -3
- package/src/section-header/index.js +3 -3
- package/src/section-header/style.scss +5 -1
- package/src/select-control/GroupedSelectControl.js +1 -1
- package/src/select-control/style.scss +4 -4
- package/src/settings/MinMaxSetting.js +8 -6
- package/src/settings/style.scss +15 -2
- package/src/sortable-newsletter-list-control/index.js +137 -0
- package/src/sortable-newsletter-list-control/style.scss +45 -0
- package/src/steps-list/style.scss +2 -2
- package/src/steps-list-item/style.scss +5 -5
- package/src/style-card/index.js +11 -5
- package/src/style-card/style.scss +4 -4
- package/src/style.scss +14 -2
- package/src/tabbed-navigation/style.scss +4 -4
- package/src/text-control/index.tsx +65 -0
- package/src/web-preview/index.js +6 -6
- package/src/web-preview/style.scss +5 -5
- package/src/with-wizard/index.js +4 -4
- package/src/with-wizard/style.scss +44 -22
- package/src/with-wizard-screen/index.js +1 -1
- package/src/with-wizard-screen/style.scss +7 -7
- package/src/wizard/components/WizardError.js +1 -1
- package/src/wizard/index.js +3 -3
- package/src/wizard/store/index.js +9 -2
- package/dist/cjs/action-card/style.scss +0 -483
- package/dist/cjs/autocomplete-tokenfield/style.scss +0 -43
- package/dist/cjs/autocomplete-with-suggestions/style.scss +0 -171
- package/dist/cjs/button/index.js +0 -57
- package/dist/cjs/card/style.scss +0 -168
- package/dist/cjs/category-autocomplete/style.scss +0 -34
- package/dist/cjs/consts.js +0 -12
- package/dist/cjs/form-token-field/style.scss +0 -37
- package/dist/cjs/grid/index.js +0 -54
- package/dist/cjs/hooks/index.js +0 -26
- package/dist/cjs/hooks/usePrompt.js +0 -52
- package/dist/cjs/image-upload/index.js +0 -144
- package/dist/cjs/image-upload/style.scss +0 -103
- package/dist/cjs/modal/style.scss +0 -56
- package/dist/cjs/patrons-logo/index.js +0 -82
- package/dist/cjs/plugin-installer/index.js +0 -299
- package/dist/cjs/plugin-settings/index.js +0 -222
- package/dist/cjs/plugin-toggle/index.js +0 -222
- package/dist/cjs/plugin-toggle/style.scss +0 -20
- package/dist/cjs/proxied-imports/router.js +0 -15
- package/dist/cjs/section-header/style.scss +0 -41
- package/dist/cjs/settings/MinMaxSetting.js +0 -57
- package/dist/cjs/settings/SettingsSection.js +0 -37
- package/dist/cjs/steps-list/style.scss +0 -11
- package/dist/cjs/style-card/style.scss +0 -94
- package/dist/cjs/style.scss +0 -43
- package/dist/cjs/text-control/index.js +0 -71
- package/dist/cjs/utils/index.js +0 -40
- package/dist/cjs/web-preview/index.js +0 -189
- package/dist/cjs/with-wizard/index.js +0 -318
- package/dist/cjs/with-wizard/style.scss +0 -260
- package/dist/cjs/with-wizard-screen/style.scss +0 -160
- package/dist/esm/accordion/index.js +0 -38
- package/dist/esm/accordion/style.scss +0 -27
- package/dist/esm/action-card/index.js +0 -222
- package/dist/esm/autocomplete-tokenfield/index.js +0 -223
- package/dist/esm/autocomplete-with-suggestions/index.js +0 -289
- package/dist/esm/button/index.js +0 -48
- package/dist/esm/button/style.scss +0 -11
- package/dist/esm/button-card/index.js +0 -65
- package/dist/esm/button-card/style.scss +0 -174
- package/dist/esm/card/index.js +0 -43
- package/dist/esm/category-autocomplete/index.js +0 -185
- package/dist/esm/color-picker/index.js +0 -61
- package/dist/esm/color-picker/style.scss +0 -37
- package/dist/esm/consts.js +0 -3
- package/dist/esm/custom-select-control/index.js +0 -37
- package/dist/esm/custom-select-control/style.scss +0 -92
- package/dist/esm/date-range-picker/index.js +0 -32
- package/dist/esm/date-range-picker/style.scss +0 -148
- package/dist/esm/footer/index.js +0 -105
- package/dist/esm/footer/style.scss +0 -82
- package/dist/esm/form-token-field/index.js +0 -50
- package/dist/esm/global-notices/index.js +0 -30
- package/dist/esm/grid/index.js +0 -45
- package/dist/esm/grid/style.scss +0 -166
- package/dist/esm/handoff/index.js +0 -177
- package/dist/esm/handoff-message/index.js +0 -45
- package/dist/esm/hooks/index.js +0 -17
- package/dist/esm/hooks/useObjectState.js +0 -31
- package/dist/esm/hooks/useObjectState.test.js +0 -83
- package/dist/esm/hooks/useOnClickOutside.js +0 -31
- package/dist/esm/hooks/usePrompt.js +0 -43
- package/dist/esm/image-upload/index.js +0 -141
- package/dist/esm/image-upload/index.test.js +0 -28
- package/dist/esm/index.js +0 -47
- package/dist/esm/info-button/index.js +0 -42
- package/dist/esm/info-button/style.scss +0 -18
- package/dist/esm/modal/index.js +0 -39
- package/dist/esm/newspack-icon/index.js +0 -50
- package/dist/esm/newspack-icon/style.scss +0 -26
- package/dist/esm/newspack-logo/index.js +0 -46
- package/dist/esm/newspack-logo/style.scss +0 -30
- package/dist/esm/notice/index.js +0 -67
- package/dist/esm/notice/style.scss +0 -111
- package/dist/esm/patrons-logo/index.js +0 -76
- package/dist/esm/plugin-installer/index.js +0 -295
- package/dist/esm/plugin-installer/style.scss +0 -72
- package/dist/esm/plugin-settings/SettingsSection.js +0 -136
- package/dist/esm/plugin-settings/index.js +0 -217
- package/dist/esm/plugin-settings/style.scss +0 -7
- package/dist/esm/plugin-toggle/index.js +0 -217
- package/dist/esm/popover/index.js +0 -41
- package/dist/esm/popover/style.scss +0 -161
- package/dist/esm/position-control/index.js +0 -109
- package/dist/esm/position-control/style.scss +0 -66
- package/dist/esm/progress-bar/index.js +0 -69
- package/dist/esm/progress-bar/index.test.js +0 -110
- package/dist/esm/progress-bar/style.scss +0 -42
- package/dist/esm/proxied-imports/router.js +0 -8
- package/dist/esm/radio-control/index.js +0 -37
- package/dist/esm/radio-control/style.scss +0 -92
- package/dist/esm/section-header/index.js +0 -68
- package/dist/esm/select-control/ButtonGroupControl.js +0 -54
- package/dist/esm/select-control/GroupedSelectControl.js +0 -84
- package/dist/esm/select-control/index.js +0 -51
- package/dist/esm/select-control/style.scss +0 -108
- package/dist/esm/settings/MinMaxSetting.js +0 -53
- package/dist/esm/settings/SettingsCard.js +0 -39
- package/dist/esm/settings/SettingsSection.js +0 -30
- package/dist/esm/settings/index.js +0 -9
- package/dist/esm/settings/style.scss +0 -106
- package/dist/esm/steps-list/index.js +0 -43
- package/dist/esm/steps-list-item/index.js +0 -48
- package/dist/esm/steps-list-item/style.scss +0 -47
- package/dist/esm/style-card/index.js +0 -76
- package/dist/esm/tabbed-navigation/index.js +0 -56
- package/dist/esm/tabbed-navigation/style.scss +0 -86
- package/dist/esm/text-control/index.js +0 -66
- package/dist/esm/text-control/style.scss +0 -32
- package/dist/esm/utils/index.js +0 -32
- package/dist/esm/waiting/index.js +0 -44
- package/dist/esm/waiting/style.scss +0 -27
- package/dist/esm/web-preview/index.js +0 -184
- package/dist/esm/web-preview/style.scss +0 -155
- package/dist/esm/with-wizard/index.js +0 -313
- package/dist/esm/with-wizard-screen/index.js +0 -116
- package/dist/esm/wizard/components/WizardError.js +0 -69
- package/dist/esm/wizard/index.js +0 -126
- package/dist/esm/wizard/store/index.js +0 -155
- package/dist/esm/wizard/store/utils.js +0 -17
- package/src/grid/index.js +0 -44
- package/src/text-control/index.js +0 -56
- /package/dist/{cjs/info-button → info-button}/style.scss +0 -0
- /package/dist/{cjs/text-control → text-control}/style.scss +0 -0
- /package/dist/{cjs/waiting → waiting}/style.scss +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
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 _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
var _icons = require("@wordpress/icons");
|
|
12
|
+
var _ = require("../");
|
|
13
|
+
require("./style.scss");
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
/**
|
|
17
|
+
* Plugin Installer
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* WordPress dependencies.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Internal dependencies.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const PLUGIN_STATE_NONE = 0;
|
|
29
|
+
const PLUGIN_STATE_ACTIVE = 1;
|
|
30
|
+
const PLUGIN_STATE_INSTALLING = 2;
|
|
31
|
+
const PLUGIN_STATE_ERROR = 3;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* External dependencies.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Plugin installer.
|
|
39
|
+
*/
|
|
40
|
+
class PluginInstaller extends _element.Component {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.state = {
|
|
44
|
+
pluginInfo: {},
|
|
45
|
+
installationInitialized: false
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
componentDidMount = () => {
|
|
49
|
+
const {
|
|
50
|
+
plugins
|
|
51
|
+
} = this.props;
|
|
52
|
+
this.retrievePluginInfo(plugins).then(() => {
|
|
53
|
+
if (this.props.autoInstall) {
|
|
54
|
+
this.installAllPlugins();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
componentDidUpdate = prevProps => {
|
|
59
|
+
const {
|
|
60
|
+
autoInstall,
|
|
61
|
+
plugins
|
|
62
|
+
} = this.props;
|
|
63
|
+
const {
|
|
64
|
+
installationInitialized
|
|
65
|
+
} = this.state;
|
|
66
|
+
if (plugins !== prevProps.plugins) {
|
|
67
|
+
this.retrievePluginInfo(plugins);
|
|
68
|
+
}
|
|
69
|
+
if (autoInstall && !installationInitialized) {
|
|
70
|
+
this.installAllPlugins();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
retrievePluginInfo = plugins => {
|
|
74
|
+
return new Promise(resolve => {
|
|
75
|
+
(0, _apiFetch.default)({
|
|
76
|
+
path: '/newspack/v1/plugins/'
|
|
77
|
+
}).then(response => {
|
|
78
|
+
const pluginInfo = Object.keys(response).reduce((result, slug) => {
|
|
79
|
+
if (plugins.indexOf(slug) === -1) {
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
result[slug] = {
|
|
83
|
+
...response[slug],
|
|
84
|
+
installationStatus: response[slug].Status === 'active' ? PLUGIN_STATE_ACTIVE : PLUGIN_STATE_NONE
|
|
85
|
+
};
|
|
86
|
+
return result;
|
|
87
|
+
}, {});
|
|
88
|
+
this.updatePluginInfo(pluginInfo).then(() => resolve());
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
installAllPlugins = () => {
|
|
93
|
+
const {
|
|
94
|
+
pluginInfo
|
|
95
|
+
} = this.state;
|
|
96
|
+
this.setState({
|
|
97
|
+
installationInitialized: true
|
|
98
|
+
});
|
|
99
|
+
const promises = Object.keys(pluginInfo).filter(slug => 'active' !== pluginInfo[slug].Status).map(slug => () => this.installPlugin(slug));
|
|
100
|
+
promises.reduce((promise, action) => promise.then(result => action().then(Array.prototype.concat.bind(result))), Promise.resolve([]));
|
|
101
|
+
};
|
|
102
|
+
installPlugin = slug => {
|
|
103
|
+
this.setInstallationStatus(slug, PLUGIN_STATE_INSTALLING);
|
|
104
|
+
const params = {
|
|
105
|
+
path: `/newspack/v1/plugins/${slug}/configure/`,
|
|
106
|
+
method: 'post'
|
|
107
|
+
};
|
|
108
|
+
return (0, _apiFetch.default)(params).then(response => {
|
|
109
|
+
const {
|
|
110
|
+
pluginInfo
|
|
111
|
+
} = this.state;
|
|
112
|
+
this.props.onInstalled(slug);
|
|
113
|
+
this.updatePluginInfo({
|
|
114
|
+
...pluginInfo,
|
|
115
|
+
[slug]: {
|
|
116
|
+
...response,
|
|
117
|
+
installationStatus: PLUGIN_STATE_ACTIVE
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}).catch(error => {
|
|
121
|
+
this.setInstallationStatus(slug, PLUGIN_STATE_ERROR, error.message);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
setChecked = (slug, checked) => {
|
|
125
|
+
const {
|
|
126
|
+
pluginInfo
|
|
127
|
+
} = this.state;
|
|
128
|
+
this.updatePluginInfo({
|
|
129
|
+
...pluginInfo,
|
|
130
|
+
[slug]: {
|
|
131
|
+
...pluginInfo[slug],
|
|
132
|
+
checked
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
setInstallationStatus = (slug, installationStatus, notification = null) => {
|
|
137
|
+
const {
|
|
138
|
+
pluginInfo
|
|
139
|
+
} = this.state;
|
|
140
|
+
this.updatePluginInfo({
|
|
141
|
+
...pluginInfo,
|
|
142
|
+
[slug]: {
|
|
143
|
+
...pluginInfo[slug],
|
|
144
|
+
installationStatus,
|
|
145
|
+
notification
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
updatePluginInfo = pluginInfo => {
|
|
150
|
+
return new Promise(resolve => {
|
|
151
|
+
const {
|
|
152
|
+
onStatus
|
|
153
|
+
} = this.props;
|
|
154
|
+
this.setState({
|
|
155
|
+
pluginInfo
|
|
156
|
+
}, () => {
|
|
157
|
+
const complete = Object.values(pluginInfo).every(plugin => {
|
|
158
|
+
return 'active' === plugin.Status;
|
|
159
|
+
});
|
|
160
|
+
onStatus({
|
|
161
|
+
complete,
|
|
162
|
+
pluginInfo
|
|
163
|
+
});
|
|
164
|
+
resolve();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
classForInstallationStatus = status => {
|
|
169
|
+
switch (status) {
|
|
170
|
+
case PLUGIN_STATE_ACTIVE:
|
|
171
|
+
return 'newspack-plugin-installer__status-active';
|
|
172
|
+
case PLUGIN_STATE_INSTALLING:
|
|
173
|
+
return 'newspack-plugin-installer__status-installing';
|
|
174
|
+
case PLUGIN_STATE_ERROR:
|
|
175
|
+
return 'newspack-plugin-installer__status-error';
|
|
176
|
+
default:
|
|
177
|
+
return 'newspack-plugin-installer__status-none';
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Render.
|
|
183
|
+
*/
|
|
184
|
+
render() {
|
|
185
|
+
const {
|
|
186
|
+
autoInstall,
|
|
187
|
+
isSmall,
|
|
188
|
+
withoutFooterButton
|
|
189
|
+
} = this.props;
|
|
190
|
+
const {
|
|
191
|
+
pluginInfo
|
|
192
|
+
} = this.state;
|
|
193
|
+
const {
|
|
194
|
+
is_atomic: isAtomic
|
|
195
|
+
} = window;
|
|
196
|
+
const slugs = Object.keys(pluginInfo);
|
|
197
|
+
|
|
198
|
+
// Store all plugin status info for installer button text value based on current status.
|
|
199
|
+
const currentPluginStatuses = [];
|
|
200
|
+
slugs.forEach(slug => {
|
|
201
|
+
const plugin = pluginInfo[slug];
|
|
202
|
+
currentPluginStatuses.push(plugin.Status);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Make sure plugin status falls in either one of these, to handle button text.
|
|
206
|
+
const pluginInstalled = currentStatus => currentStatus === 'active' || currentStatus === 'inactive';
|
|
207
|
+
const buttonText = currentPluginStatuses.every(pluginInstalled) ? (0, _i18n.__)('Activate', 'newspack-plugin') : (0, _i18n.__)('Install', 'newspack-plugin');
|
|
208
|
+
const needsInstall = slugs.some(slug => {
|
|
209
|
+
const plugin = pluginInfo[slug];
|
|
210
|
+
return plugin.Status !== 'active' && plugin.installationStatus === PLUGIN_STATE_NONE;
|
|
211
|
+
});
|
|
212
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
213
|
+
children: [(!pluginInfo || !Object.keys(pluginInfo).length) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
214
|
+
className: "newspack-plugin-installer_is-waiting",
|
|
215
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Waiting, {
|
|
216
|
+
isLeft: true
|
|
217
|
+
}), (0, _i18n.__)('Retrieving plugin information…', 'newspack-plugin')]
|
|
218
|
+
}), pluginInfo && slugs.length > 0 && slugs.map(slug => {
|
|
219
|
+
const plugin = pluginInfo[slug];
|
|
220
|
+
const {
|
|
221
|
+
Name,
|
|
222
|
+
Description,
|
|
223
|
+
Download,
|
|
224
|
+
Status,
|
|
225
|
+
installationStatus,
|
|
226
|
+
notification
|
|
227
|
+
} = plugin;
|
|
228
|
+
const isWaiting = installationStatus === PLUGIN_STATE_INSTALLING;
|
|
229
|
+
const isButton = !isWaiting && Status !== 'active';
|
|
230
|
+
const installable = Download || pluginInstalled(Status);
|
|
231
|
+
let actionText;
|
|
232
|
+
if (installationStatus === PLUGIN_STATE_INSTALLING) {
|
|
233
|
+
actionText = 'inactive' === Status ? (0, _i18n.__)('Activating…') : (0, _i18n.__)('Installing…');
|
|
234
|
+
} else if (!installable) {
|
|
235
|
+
actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
236
|
+
className: "newspack-plugin-installer__status",
|
|
237
|
+
children: [isAtomic ? (0, _i18n.__)('Contact Newspack support to install', 'newspack-plugin') : (0, _i18n.__)('Plugin must be installed manually', 'newspack-plugin'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
238
|
+
className: "newspack-checkbox-icon"
|
|
239
|
+
})]
|
|
240
|
+
});
|
|
241
|
+
} else if (Status === 'uninstalled') {
|
|
242
|
+
actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
243
|
+
className: "newspack-plugin-installer__status",
|
|
244
|
+
children: [(0, _i18n.__)('Install', 'newspack'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
245
|
+
className: "newspack-checkbox-icon"
|
|
246
|
+
})]
|
|
247
|
+
});
|
|
248
|
+
} else if (Status === 'inactive') {
|
|
249
|
+
actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
250
|
+
className: "newspack-plugin-installer__status",
|
|
251
|
+
children: [(0, _i18n.__)('Activate', 'newspack-plugin'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
252
|
+
className: "newspack-checkbox-icon"
|
|
253
|
+
})]
|
|
254
|
+
});
|
|
255
|
+
} else if (Status === 'active') {
|
|
256
|
+
actionText = /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
257
|
+
className: "newspack-plugin-installer__status",
|
|
258
|
+
children: [(0, _i18n.__)('Installed', 'newspack-plugin'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
259
|
+
className: "newspack-checkbox-icon newspack-checkbox-icon--checked",
|
|
260
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
|
|
261
|
+
icon: _icons.check
|
|
262
|
+
})
|
|
263
|
+
})]
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
const classes = (0, _classnames.default)('newspack-action-card__plugin-installer', this.classForInstallationStatus(installationStatus));
|
|
267
|
+
const onClick = isButton ? () => this.installPlugin(slug) : null;
|
|
268
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.ActionCard, {
|
|
269
|
+
title: Name,
|
|
270
|
+
description: Description,
|
|
271
|
+
disabled: !installable,
|
|
272
|
+
actionText: actionText,
|
|
273
|
+
isSmall: isSmall,
|
|
274
|
+
isWaiting: isWaiting,
|
|
275
|
+
onClick: onClick,
|
|
276
|
+
notification: notification,
|
|
277
|
+
notificationLevel: "error",
|
|
278
|
+
notificationHTML: true,
|
|
279
|
+
className: classes
|
|
280
|
+
}, slug);
|
|
281
|
+
}), !withoutFooterButton && !autoInstall && pluginInfo && slugs.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
282
|
+
className: "newspack-buttons-card",
|
|
283
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
|
|
284
|
+
disabled: !needsInstall,
|
|
285
|
+
isPrimary: true,
|
|
286
|
+
onClick: this.installAllPlugins,
|
|
287
|
+
children: buttonText
|
|
288
|
+
})
|
|
289
|
+
})]
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
PluginInstaller.defaultProps = {
|
|
294
|
+
onStatus: () => {},
|
|
295
|
+
onInstalled: () => {}
|
|
296
|
+
};
|
|
297
|
+
var _default = exports.default = PluginInstaller;
|
|
@@ -10,17 +10,19 @@ var _i18n = require("@wordpress/i18n");
|
|
|
10
10
|
var _components = require("@wordpress/components");
|
|
11
11
|
var _ = require("../");
|
|
12
12
|
require("./style.scss");
|
|
13
|
-
var _jsxRuntime = require("
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
14
|
/**
|
|
15
15
|
* Ads Settings Section.
|
|
16
16
|
*/
|
|
17
|
+
|
|
17
18
|
/**
|
|
18
19
|
* WordPress dependencies
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* Internal dependencies
|
|
23
24
|
*/
|
|
25
|
+
|
|
24
26
|
const isSelectControl = setting => {
|
|
25
27
|
return Array.isArray(setting.options) && setting.options.length;
|
|
26
28
|
};
|
|
@@ -86,8 +88,7 @@ const SettingsSection = props => {
|
|
|
86
88
|
setSaveDisabled(false);
|
|
87
89
|
}
|
|
88
90
|
});
|
|
89
|
-
const createFilter =
|
|
90
|
-
let defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
91
|
+
const createFilter = (name, defaultComponent = null) => {
|
|
91
92
|
return (0, _hooks.applyFilters)(`newspack.settingSection.${sectionKey}.${name}`, defaultComponent, props);
|
|
92
93
|
};
|
|
93
94
|
let columns = 2;
|
|
@@ -96,7 +97,7 @@ const SettingsSection = props => {
|
|
|
96
97
|
} else if (fields.length === 1) {
|
|
97
98
|
columns = 1;
|
|
98
99
|
}
|
|
99
|
-
return (0, _jsxRuntime.jsx)(_.ActionCard, {
|
|
100
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.ActionCard, {
|
|
100
101
|
isMedium: true,
|
|
101
102
|
disabled: disabled,
|
|
102
103
|
title: title,
|
|
@@ -106,25 +107,25 @@ const SettingsSection = props => {
|
|
|
106
107
|
toggleOnChange: active !== null ? value => onUpdate({
|
|
107
108
|
active: value
|
|
108
109
|
}) : null,
|
|
109
|
-
actionContent: (active || null === active) && createFilter('buttons', (0, _jsxRuntime.jsx)(_.Button, {
|
|
110
|
+
actionContent: (active || null === active) && createFilter('buttons', /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
|
|
110
111
|
variant: "primary",
|
|
111
112
|
disabled: disabled || saveDisabled,
|
|
112
113
|
onClick: () => {
|
|
113
114
|
onUpdate();
|
|
114
115
|
setSaveDisabled(true);
|
|
115
116
|
},
|
|
116
|
-
children: __('Save Settings', 'newspack')
|
|
117
|
+
children: (0, _i18n.__)('Save Settings', 'newspack')
|
|
117
118
|
})),
|
|
118
|
-
children: (active || active === null) && (0, _jsxRuntime.jsxs)(_element.Fragment, {
|
|
119
|
-
children: [error?.message && (0, _jsxRuntime.jsx)(_.Notice, {
|
|
119
|
+
children: (active || active === null) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
|
|
120
|
+
children: [error?.message && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
|
|
120
121
|
noticeText: error.message,
|
|
121
122
|
isError: true
|
|
122
|
-
}), createFilter('beforeControls'), (0, _jsxRuntime.jsx)(_.Grid, {
|
|
123
|
+
}), createFilter('beforeControls'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Grid, {
|
|
123
124
|
columns: columns,
|
|
124
125
|
gutter: 32,
|
|
125
126
|
children: fields.map(setting => {
|
|
126
127
|
const Control = getControlComponent(setting); // eslint-disable-line @wordpress/no-unused-vars-before-return, no-unused-vars
|
|
127
|
-
return (0, _hooks.applyFilters)(`newspack.settingsSection.${sectionKey}.control`, (0, _jsxRuntime.jsx)(Control, {
|
|
128
|
+
return (0, _hooks.applyFilters)(`newspack.settingsSection.${sectionKey}.control`, /*#__PURE__*/(0, _jsxRuntime.jsx)(Control, {
|
|
128
129
|
...getControlProps(setting)
|
|
129
130
|
}, setting.key), {
|
|
130
131
|
sectionKey,
|
|
@@ -136,5 +137,4 @@ const SettingsSection = props => {
|
|
|
136
137
|
})
|
|
137
138
|
});
|
|
138
139
|
};
|
|
139
|
-
var _default = SettingsSection;
|
|
140
|
-
exports.default = _default;
|
|
140
|
+
var _default = exports.default = SettingsSection;
|
|
@@ -0,0 +1,228 @@
|
|
|
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 _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
|
+
var _ = require("../");
|
|
13
|
+
var _SettingsSection = _interopRequireDefault(require("./SettingsSection"));
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
/**
|
|
16
|
+
* External dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* WordPress dependencies.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Internal dependencies.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
class PluginSettings extends _element.Component {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.state = {
|
|
31
|
+
inFlight: false,
|
|
32
|
+
settings: {},
|
|
33
|
+
error: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
fetchSettings = () => {
|
|
37
|
+
const {
|
|
38
|
+
afterFetch,
|
|
39
|
+
pluginSlug,
|
|
40
|
+
isWizard
|
|
41
|
+
} = this.props;
|
|
42
|
+
this.setState({
|
|
43
|
+
inFlight: true
|
|
44
|
+
});
|
|
45
|
+
(0, _apiFetch.default)({
|
|
46
|
+
path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`
|
|
47
|
+
}).then(settings => {
|
|
48
|
+
this.setState({
|
|
49
|
+
settings,
|
|
50
|
+
error: null
|
|
51
|
+
});
|
|
52
|
+
if ('function' === typeof afterFetch) {
|
|
53
|
+
afterFetch(settings);
|
|
54
|
+
}
|
|
55
|
+
}).catch(error => {
|
|
56
|
+
this.setState({
|
|
57
|
+
error
|
|
58
|
+
});
|
|
59
|
+
}).finally(() => {
|
|
60
|
+
this.setState({
|
|
61
|
+
inFlight: false
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
componentDidMount() {
|
|
66
|
+
this.fetchSettings();
|
|
67
|
+
}
|
|
68
|
+
getSettingsValues = sectionKey => {
|
|
69
|
+
return this.state.settings[sectionKey]?.reduce((map, setting) => {
|
|
70
|
+
map[setting.key] = setting.value;
|
|
71
|
+
return map;
|
|
72
|
+
}, {}) || {};
|
|
73
|
+
};
|
|
74
|
+
handleSettingChange = sectionKey => (key, value) => {
|
|
75
|
+
const sectionSettings = [...this.state.settings[sectionKey]];
|
|
76
|
+
sectionSettings.forEach(setting => {
|
|
77
|
+
if (setting.key === key) {
|
|
78
|
+
setting.value = value;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.setState({
|
|
82
|
+
settings: {
|
|
83
|
+
...this.state.settings,
|
|
84
|
+
[sectionKey]: sectionSettings
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
handleSectionUpdate = sectionKey => data => {
|
|
89
|
+
const {
|
|
90
|
+
afterUpdate,
|
|
91
|
+
pluginSlug,
|
|
92
|
+
isWizard
|
|
93
|
+
} = this.props;
|
|
94
|
+
this.setState({
|
|
95
|
+
inFlight: true
|
|
96
|
+
});
|
|
97
|
+
(0, _apiFetch.default)({
|
|
98
|
+
path: isWizard ? `/newspack/v1/wizard/${pluginSlug}/settings` : `/${pluginSlug}/v1/settings`,
|
|
99
|
+
method: 'POST',
|
|
100
|
+
data: {
|
|
101
|
+
section: sectionKey,
|
|
102
|
+
settings: data ? data : this.getSettingsValues(sectionKey)
|
|
103
|
+
}
|
|
104
|
+
}).then(settings => {
|
|
105
|
+
this.setState({
|
|
106
|
+
settings: {
|
|
107
|
+
...this.state.settings,
|
|
108
|
+
[sectionKey]: settings[sectionKey]
|
|
109
|
+
},
|
|
110
|
+
error: null
|
|
111
|
+
});
|
|
112
|
+
if ('function' === typeof afterUpdate) {
|
|
113
|
+
afterUpdate(settings);
|
|
114
|
+
}
|
|
115
|
+
}).catch(error => {
|
|
116
|
+
this.setState({
|
|
117
|
+
error
|
|
118
|
+
});
|
|
119
|
+
}).finally(() => {
|
|
120
|
+
this.setState({
|
|
121
|
+
inFlight: false
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get the section setting containing section information.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} sectionKey The section name.
|
|
130
|
+
* @return {Object} The section setting.
|
|
131
|
+
*/
|
|
132
|
+
getSectionInfo = sectionKey => {
|
|
133
|
+
return this.state.settings[sectionKey]?.find(setting => !setting.key || setting.key === 'active');
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get the section title.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} sectionKey The section name.
|
|
140
|
+
* @return {string} The section title.
|
|
141
|
+
*/
|
|
142
|
+
getSectionTitle = sectionKey => {
|
|
143
|
+
return this.getSectionInfo(sectionKey)?.description;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get the section description.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} sectionKey The section name.
|
|
150
|
+
* @return {string} The section description.
|
|
151
|
+
*/
|
|
152
|
+
getSectionDescription = sectionKey => {
|
|
153
|
+
return this.getSectionInfo(sectionKey)?.help;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get whether a section is active.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} sectionKey The section name.
|
|
160
|
+
* @return {?boolean} Whether the section is active or not. Null if the section is not found or does not support activation.
|
|
161
|
+
*/
|
|
162
|
+
isSectionActive = sectionKey => {
|
|
163
|
+
const {
|
|
164
|
+
settings
|
|
165
|
+
} = this.state;
|
|
166
|
+
const activation = settings[sectionKey]?.find(setting => setting.key === 'active');
|
|
167
|
+
if (!activation) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return activation.value;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Get list of section field settings.
|
|
175
|
+
*
|
|
176
|
+
* @param {string} sectionKey The section name.
|
|
177
|
+
* @return {?Array} List of section fields.
|
|
178
|
+
*/
|
|
179
|
+
getSectionFields = sectionKey => {
|
|
180
|
+
return this.state.settings[sectionKey]?.filter(setting => setting.key && setting.key !== 'active');
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Render.
|
|
185
|
+
*/
|
|
186
|
+
render() {
|
|
187
|
+
const {
|
|
188
|
+
title,
|
|
189
|
+
description,
|
|
190
|
+
hasGreyHeader,
|
|
191
|
+
children
|
|
192
|
+
} = this.props;
|
|
193
|
+
const {
|
|
194
|
+
settings,
|
|
195
|
+
inFlight,
|
|
196
|
+
error
|
|
197
|
+
} = this.state;
|
|
198
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
|
|
199
|
+
children: [title && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.SectionHeader, {
|
|
200
|
+
title: title,
|
|
201
|
+
description: description
|
|
202
|
+
}), error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
|
|
203
|
+
isError: true,
|
|
204
|
+
noticeText: error.message
|
|
205
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
206
|
+
className: (0, _classnames.default)('newspack-plugin-settings', {
|
|
207
|
+
'newspack-wizard-section__is-loading': inFlight && !Object.keys(settings).length
|
|
208
|
+
}),
|
|
209
|
+
children: [Object.keys(settings).map(sectionKey => /*#__PURE__*/(0, _jsxRuntime.jsx)(_SettingsSection.default, {
|
|
210
|
+
disabled: inFlight,
|
|
211
|
+
sectionKey: sectionKey,
|
|
212
|
+
title: this.getSectionTitle(sectionKey),
|
|
213
|
+
description: this.getSectionDescription(sectionKey),
|
|
214
|
+
active: this.isSectionActive(sectionKey),
|
|
215
|
+
fields: this.getSectionFields(sectionKey),
|
|
216
|
+
onChange: this.handleSettingChange(sectionKey),
|
|
217
|
+
onUpdate: this.handleSectionUpdate(sectionKey),
|
|
218
|
+
hasGreyHeader: hasGreyHeader
|
|
219
|
+
}, sectionKey)), children]
|
|
220
|
+
})]
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
PluginSettings.defaultProps = {
|
|
225
|
+
title: (0, _i18n.__)('General Settings', 'newspack-plugin')
|
|
226
|
+
};
|
|
227
|
+
PluginSettings.Section = _SettingsSection.default;
|
|
228
|
+
var _default = exports.default = PluginSettings;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# PluginToggle
|
|
2
|
+
|
|
3
|
+
PluginToggle presents ActionCards for one or more plugins.
|
|
4
|
+
|
|
5
|
+
Each ActionCard displays the name and description of the plugin. Clicking the ToggleControl installs/activates or uninstalls the plugin. If a plugin is installed, there will be a Handoff link on the right. Optionally the href and label of this link can be overridden.
|
|
6
|
+
|
|
7
|
+
Each plugin accepts a shouldRefreshAfterUpdate param. If true, the page will be reloaded after the plugin is installed or uninstalled. Updating ensures that the WordPress dashboard accurately represents current state, e.g. that newly installed plugins appear in menus.
|
|
8
|
+
|
|
9
|
+
### Usage
|
|
10
|
+
|
|
11
|
+
ActionCards for WooCommerce and Instant Articles for WP. Both will have Handoff links.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
<PluginToggle
|
|
15
|
+
plugins={ {
|
|
16
|
+
woocommerce: true,
|
|
17
|
+
'fb-instant-articles': true,
|
|
18
|
+
} }
|
|
19
|
+
/>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
ActionCards for WooCommerce and Instant Articles for WP with custom text and URL for links.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
<PluginToggle
|
|
26
|
+
plugins={ {
|
|
27
|
+
woocommerce: {
|
|
28
|
+
actionText: __( 'Use WooCommerce' ),
|
|
29
|
+
href: '/wp-admin/admin.php?page=newspack',
|
|
30
|
+
},
|
|
31
|
+
'fb-instant-articles': {
|
|
32
|
+
actionText: __( 'Configure Instant Articles' ),
|
|
33
|
+
href: '/wp-admin/admin.php?page=newspack',
|
|
34
|
+
},
|
|
35
|
+
} }
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
ActionCards for WooCommerce and Instant Articles for WP. Page will refresh after WooCommerce installation or deinstallation.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
<PluginToggle
|
|
43
|
+
plugins={ {
|
|
44
|
+
woocommerce: {
|
|
45
|
+
shouldRefreshAfterUpdate: true,
|
|
46
|
+
},
|
|
47
|
+
'fb-instant-articles': {
|
|
48
|
+
actionText: __( 'Configure Instant Articles' ),
|
|
49
|
+
href: '/wp-admin/admin.php?page=newspack',
|
|
50
|
+
},
|
|
51
|
+
} }
|
|
52
|
+
/>
|
|
53
|
+
```
|