newspack-components 4.3.0 → 4.4.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.
- package/CHANGELOG.md +11 -0
- package/DEVELOPMENT.md +868 -0
- package/colors/colors.module.scss +52 -2
- package/copy-styles.js +3 -2
- package/dist/cjs/accordion/index.js +17 -12
- package/dist/cjs/action-card/index.js +176 -139
- package/dist/cjs/autocomplete-tokenfield/index.js +254 -234
- package/dist/cjs/autocomplete-with-latest-posts/index.js +172 -110
- package/dist/cjs/autocomplete-with-suggestions/index.js +229 -126
- package/dist/cjs/badge/index.js +7 -7
- package/dist/cjs/box-contrast/index.js +19 -15
- package/dist/cjs/button/index.js +41 -26
- package/dist/cjs/button-props/button-props.js +5 -5
- package/dist/cjs/button-props/index.js +2 -2
- package/dist/cjs/card/core-card.js +110 -52
- package/dist/cjs/card/index.js +74 -67
- package/dist/cjs/card/style-core.scss +93 -25
- package/dist/cjs/card/style.scss +2 -2
- package/dist/cjs/card-feature/index.js +141 -0
- package/dist/cjs/card-feature/style.scss +75 -0
- package/dist/cjs/card-form/index.js +144 -0
- package/dist/cjs/card-form/style.scss +20 -0
- package/dist/cjs/card-settings-group/index.js +36 -16
- package/dist/cjs/card-sortable-list/index.js +176 -140
- package/dist/cjs/category-autocomplete/index.js +175 -155
- package/dist/cjs/color-picker/index.js +41 -23
- package/dist/cjs/color-picker/index.test.js +82 -0
- package/dist/cjs/color-picker/style.scss +11 -13
- package/dist/cjs/confirm-dialog/index.js +86 -22
- package/dist/cjs/consts.js +1 -1
- package/dist/cjs/custom-select-control/index.js +39 -28
- package/dist/cjs/dataviews/index.js +38 -0
- package/dist/cjs/dataviews/style.scss +9 -0
- package/dist/cjs/divider/index.js +26 -21
- package/dist/cjs/footer/index.js +36 -30
- package/dist/cjs/form-token-field/index.js +51 -40
- package/dist/cjs/global-notices/index.js +5 -5
- package/dist/cjs/grid/index.js +25 -19
- package/dist/cjs/grid/style.scss +6 -1
- package/dist/cjs/handoff/index.js +204 -156
- package/dist/cjs/handoff-message/index.js +12 -7
- package/dist/cjs/hooks/index.js +10 -8
- package/dist/cjs/hooks/use-confirm-dialog.js +79 -0
- package/dist/cjs/hooks/use-unsaved-changes-dialog.js +144 -0
- package/dist/cjs/hooks/useObjectState.js +21 -12
- package/dist/cjs/hooks/useObjectState.test.js +55 -33
- package/dist/cjs/hooks/useOnClickOutside.js +6 -6
- package/dist/cjs/hooks/usePrompt.js +10 -13
- package/dist/cjs/image-upload/index.js +114 -123
- package/dist/cjs/image-upload/index.test.js +11 -13
- package/dist/cjs/image-upload/style.scss +12 -40
- package/dist/cjs/index.js +136 -104
- package/dist/cjs/info-button/index.js +43 -32
- package/dist/cjs/integration-icons/active-campaign.js +22 -0
- package/dist/cjs/integration-icons/constant-contact.js +28 -0
- package/dist/cjs/integration-icons/fundraise-up.js +25 -0
- package/dist/cjs/integration-icons/index.js +48 -0
- package/dist/cjs/integration-icons/mailchimp.js +19 -0
- package/dist/cjs/integration-icons/salesforce.js +17 -0
- package/dist/cjs/integration-icons/wisepops.js +20 -0
- package/dist/cjs/modal/index.js +22 -19
- package/dist/cjs/modal/style.scss +4 -0
- package/dist/cjs/newspack-icon/index.js +45 -38
- package/dist/cjs/notice/index.js +64 -55
- package/dist/cjs/plugin-installer/index.js +259 -253
- package/dist/cjs/plugin-settings/SettingsSection.js +66 -60
- package/dist/cjs/plugin-settings/index.js +217 -200
- package/dist/cjs/plugin-toggle/index.js +192 -199
- package/dist/cjs/popover/index.js +41 -28
- package/dist/cjs/position-control/index.js +24 -23
- package/dist/cjs/progress-bar/index.js +71 -59
- package/dist/cjs/progress-bar/index.test.js +62 -68
- package/dist/cjs/proxied-imports/router.js +3 -3
- package/dist/cjs/radio-control/index.js +40 -27
- package/dist/cjs/section-header/index.js +103 -58
- package/dist/cjs/section-header/style.scss +31 -11
- package/dist/cjs/select-control/ButtonGroupControl.js +26 -21
- package/dist/cjs/select-control/GroupedSelectControl.js +41 -35
- package/dist/cjs/select-control/index.js +52 -40
- package/dist/cjs/settings/MinMaxSetting.js +30 -20
- package/dist/cjs/settings/SettingsCard.js +20 -17
- package/dist/cjs/settings/SettingsSection.js +22 -21
- package/dist/cjs/settings/index.js +5 -5
- package/dist/cjs/sortable-newsletter-list-control/index.js +78 -57
- package/dist/cjs/steps-list/index.js +44 -34
- package/dist/cjs/steps-list-item/index.js +47 -39
- package/dist/cjs/style-card/index.js +70 -63
- package/dist/cjs/tabbed-navigation/index.js +38 -36
- package/dist/cjs/text-control/index.js +27 -25
- package/dist/cjs/utils/color.js +4 -4
- package/dist/cjs/utils/editor-toolbar-back-button.js +61 -0
- package/dist/cjs/utils/index.js +31 -19
- package/dist/cjs/utils/style.scss +8 -0
- package/dist/cjs/waiting/index.js +48 -37
- package/dist/cjs/web-preview/index.js +217 -211
- package/dist/cjs/with-wizard/index.js +362 -364
- package/dist/cjs/with-wizard/style.scss +4 -54
- package/dist/cjs/with-wizard-screen/index.js +54 -58
- package/dist/cjs/with-wizard-screen/style.scss +41 -3
- package/dist/cjs/wizard/components/WizardError.js +20 -18
- package/dist/cjs/wizard/components/WizardSnackbar.js +26 -23
- package/dist/cjs/wizard/index.js +176 -114
- package/dist/cjs/wizard/store/index.js +171 -123
- package/dist/cjs/wizard/store/utils.js +13 -8
- package/dist/esm/accordion/index.js +14 -9
- package/dist/esm/action-card/index.js +168 -123
- package/dist/esm/autocomplete-tokenfield/index.js +248 -222
- package/dist/esm/autocomplete-with-latest-posts/index.js +169 -103
- package/dist/esm/autocomplete-with-suggestions/index.js +226 -119
- package/dist/esm/badge/index.js +5 -5
- package/dist/esm/box-contrast/index.js +15 -11
- package/dist/esm/button/index.js +39 -21
- package/dist/esm/button-props/button-props.js +1 -1
- package/dist/esm/card/core-card.js +109 -47
- package/dist/esm/card/index.js +69 -54
- package/dist/esm/card/style-core.scss +93 -25
- package/dist/esm/card/style.scss +2 -2
- package/dist/esm/card-feature/index.js +131 -0
- package/dist/esm/card-feature/style.scss +75 -0
- package/dist/esm/card-form/index.js +134 -0
- package/dist/esm/card-form/style.scss +20 -0
- package/dist/esm/card-settings-group/index.js +33 -14
- package/dist/esm/card-sortable-list/index.js +170 -126
- package/dist/esm/category-autocomplete/index.js +168 -140
- package/dist/esm/color-picker/index.js +39 -21
- package/dist/esm/color-picker/index.test.js +78 -0
- package/dist/esm/color-picker/style.scss +11 -13
- package/dist/esm/confirm-dialog/index.js +85 -18
- package/dist/esm/consts.js +1 -1
- package/dist/esm/custom-select-control/index.js +34 -15
- package/dist/esm/dataviews/index.js +34 -0
- package/dist/esm/dataviews/style.scss +9 -0
- package/dist/esm/divider/index.js +24 -16
- package/dist/esm/footer/index.js +34 -28
- package/dist/esm/form-token-field/index.js +46 -27
- package/dist/esm/global-notices/index.js +3 -3
- package/dist/esm/grid/index.js +23 -14
- package/dist/esm/grid/style.scss +6 -1
- package/dist/esm/handoff/index.js +199 -143
- package/dist/esm/handoff-message/index.js +10 -6
- package/dist/esm/hooks/index.js +8 -6
- package/dist/esm/hooks/use-confirm-dialog.js +73 -0
- package/dist/esm/hooks/use-unsaved-changes-dialog.js +136 -0
- package/dist/esm/hooks/useObjectState.js +19 -9
- package/dist/esm/hooks/useObjectState.test.js +54 -32
- package/dist/esm/hooks/useOnClickOutside.js +4 -4
- package/dist/esm/hooks/usePrompt.js +9 -11
- package/dist/esm/image-upload/index.js +110 -111
- package/dist/esm/image-upload/index.test.js +11 -13
- package/dist/esm/image-upload/style.scss +12 -40
- package/dist/esm/index.js +7 -1
- package/dist/esm/info-button/index.js +38 -19
- package/dist/esm/integration-icons/active-campaign.js +16 -0
- package/dist/esm/integration-icons/constant-contact.js +22 -0
- package/dist/esm/integration-icons/fundraise-up.js +19 -0
- package/dist/esm/integration-icons/index.js +6 -0
- package/dist/esm/integration-icons/mailchimp.js +13 -0
- package/dist/esm/integration-icons/salesforce.js +11 -0
- package/dist/esm/integration-icons/wisepops.js +14 -0
- package/dist/esm/modal/index.js +20 -13
- package/dist/esm/modal/style.scss +4 -0
- package/dist/esm/newspack-icon/index.js +40 -25
- package/dist/esm/notice/index.js +59 -42
- package/dist/esm/plugin-installer/index.js +255 -243
- package/dist/esm/plugin-settings/SettingsSection.js +61 -50
- package/dist/esm/plugin-settings/index.js +212 -189
- package/dist/esm/plugin-toggle/index.js +187 -190
- package/dist/esm/popover/index.js +35 -16
- package/dist/esm/position-control/index.js +22 -18
- package/dist/esm/progress-bar/index.js +66 -49
- package/dist/esm/progress-bar/index.test.js +61 -67
- package/dist/esm/radio-control/index.js +34 -15
- package/dist/esm/section-header/index.js +102 -57
- package/dist/esm/section-header/style.scss +31 -11
- package/dist/esm/select-control/ButtonGroupControl.js +23 -18
- package/dist/esm/select-control/GroupedSelectControl.js +38 -30
- package/dist/esm/select-control/index.js +47 -27
- package/dist/esm/settings/MinMaxSetting.js +27 -16
- package/dist/esm/settings/SettingsCard.js +18 -13
- package/dist/esm/settings/SettingsSection.js +20 -19
- package/dist/esm/settings/index.js +3 -3
- package/dist/esm/sortable-newsletter-list-control/index.js +74 -53
- package/dist/esm/steps-list/index.js +39 -21
- package/dist/esm/steps-list-item/index.js +42 -26
- package/dist/esm/style-card/index.js +65 -50
- package/dist/esm/tabbed-navigation/index.js +35 -33
- package/dist/esm/text-control/index.js +25 -19
- package/dist/esm/utils/color.js +4 -4
- package/dist/esm/utils/editor-toolbar-back-button.js +53 -0
- package/dist/esm/utils/index.js +29 -16
- package/dist/esm/utils/style.scss +8 -0
- package/dist/esm/waiting/index.js +43 -24
- package/dist/esm/web-preview/index.js +213 -201
- package/dist/esm/with-wizard/index.js +360 -358
- package/dist/esm/with-wizard/style.scss +4 -54
- package/dist/esm/with-wizard-screen/index.js +48 -46
- package/dist/esm/with-wizard-screen/style.scss +41 -3
- package/dist/esm/wizard/components/WizardError.js +18 -16
- package/dist/esm/wizard/components/WizardSnackbar.js +23 -17
- package/dist/esm/wizard/index.js +171 -103
- package/dist/esm/wizard/store/index.js +169 -116
- package/dist/esm/wizard/store/utils.js +13 -6
- package/package.json +30 -16
- package/release.config.js +1 -0
- package/shared/hooks/use-coauthors.js +195 -27
- package/shared/hooks/use-coauthors.test.js +232 -6
- package/shared/scss/_mixins.scss +13 -5
- package/src/accordion/index.js +8 -7
- package/src/action-card/index.js +15 -1
- package/src/badge/index.tsx +3 -1
- package/src/card/core-card.js +95 -18
- package/src/card/index.js +1 -0
- package/src/card/style-core.scss +93 -25
- package/src/card/style.scss +2 -2
- package/src/card-feature/README.md +188 -0
- package/src/card-feature/index.tsx +186 -0
- package/src/card-feature/style.scss +75 -0
- package/src/card-form/README.md +113 -0
- package/src/card-form/index.tsx +128 -0
- package/src/card-form/style.scss +20 -0
- package/src/card-settings-group/index.tsx +28 -3
- package/src/card-sortable-list/index.tsx +27 -4
- package/src/color-picker/index.js +15 -8
- package/src/color-picker/index.test.js +52 -0
- package/src/color-picker/style.scss +11 -13
- package/src/confirm-dialog/README.md +128 -0
- package/src/confirm-dialog/index.tsx +74 -6
- package/src/dataviews/index.tsx +34 -0
- package/src/dataviews/style.scss +9 -0
- package/src/grid/style.scss +6 -1
- package/src/handoff/README.md +93 -0
- package/src/handoff/index.js +46 -8
- package/src/hooks/index.ts +2 -1
- package/src/hooks/use-confirm-dialog.tsx +80 -0
- package/src/hooks/use-unsaved-changes-dialog.tsx +140 -0
- package/src/image-upload/index.js +10 -15
- package/src/image-upload/style.scss +12 -40
- package/src/index.js +7 -1
- package/src/integration-icons/active-campaign.js +14 -0
- package/src/integration-icons/constant-contact.js +22 -0
- package/src/integration-icons/fundraise-up.js +18 -0
- package/src/integration-icons/index.js +6 -0
- package/src/integration-icons/mailchimp.js +10 -0
- package/src/integration-icons/salesforce.js +10 -0
- package/src/integration-icons/wisepops.js +14 -0
- package/src/modal/style.scss +4 -0
- package/src/plugin-installer/index.js +30 -19
- package/src/section-header/index.js +56 -24
- package/src/section-header/style.scss +31 -11
- package/src/select-control/index.js +4 -0
- package/src/utils/editor-toolbar-back-button.tsx +48 -0
- package/src/utils/index.js +6 -0
- package/src/utils/style.scss +8 -0
- package/src/with-wizard/style.scss +4 -54
- package/src/with-wizard-screen/style.scss +41 -3
- package/src/wizard/index.js +90 -53
- package/src/wizard/store/index.js +2 -2
- package/dist/cjs/button-card/index.js +0 -72
- package/dist/cjs/button-card/style.scss +0 -180
- package/dist/esm/button-card/index.js +0 -64
- package/dist/esm/button-card/style.scss +0 -180
- package/src/button-card/index.js +0 -52
- package/src/button-card/style.scss +0 -180
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
3
|
/**
|
|
2
4
|
* WordPress dependencies
|
|
3
5
|
*/
|
|
@@ -10,7 +12,7 @@ import mergeWith from 'lodash/mergeWith';
|
|
|
10
12
|
* @property {Object.<string, any>} [update] The update object with key-value pairs to merge into the state.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
var mergeCustomizer = function mergeCustomizer(objValue, srcValue) {
|
|
14
16
|
if (isArray(objValue)) {
|
|
15
17
|
// If it's an array, replace it (instead of concatenating).
|
|
16
18
|
return srcValue;
|
|
@@ -25,16 +27,24 @@ const mergeCustomizer = (objValue, srcValue) => {
|
|
|
25
27
|
* @param {T} initial Initial state object.
|
|
26
28
|
* @return {[T, (keyOrUpdate: string | Partial<T>) => (value?: any) => void]} The state object and a function to update it.
|
|
27
29
|
*/
|
|
28
|
-
export default (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
export default (function () {
|
|
31
|
+
var initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
|
+
var _useState = useState(initial),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
stateObject = _useState2[0],
|
|
35
|
+
setStateObject = _useState2[1];
|
|
36
|
+
var runUpdate = function runUpdate(update) {
|
|
37
|
+
return setStateObject(function (_stateObject) {
|
|
38
|
+
return mergeWith({}, _stateObject, update, mergeCustomizer);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var updateStateObject = function updateStateObject(keyOrUpdate) {
|
|
32
42
|
if (typeof keyOrUpdate === 'string') {
|
|
33
|
-
return value
|
|
34
|
-
|
|
35
|
-
}
|
|
43
|
+
return function (value) {
|
|
44
|
+
return runUpdate(_defineProperty({}, keyOrUpdate, value));
|
|
45
|
+
};
|
|
36
46
|
}
|
|
37
47
|
runUpdate(keyOrUpdate);
|
|
38
48
|
};
|
|
39
49
|
return [stateObject, updateStateObject];
|
|
40
|
-
};
|
|
50
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
3
4
|
import useObjectState from './useObjectState';
|
|
4
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
-
|
|
6
|
+
var INIT_STATE = {
|
|
6
7
|
name: 'Foo',
|
|
7
8
|
widgets: [1],
|
|
8
9
|
attributes: {
|
|
@@ -10,68 +11,89 @@ const INIT_STATE = {
|
|
|
10
11
|
baz: 1
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var TestComponent = function TestComponent() {
|
|
15
|
+
var _useObjectState = useObjectState(INIT_STATE),
|
|
16
|
+
_useObjectState2 = _slicedToArray(_useObjectState, 2),
|
|
17
|
+
state = _useObjectState2[0],
|
|
18
|
+
updateState = _useObjectState2[1];
|
|
15
19
|
return /*#__PURE__*/_jsxs("div", {
|
|
16
20
|
children: [/*#__PURE__*/_jsx("input", {
|
|
17
21
|
placeholder: "state",
|
|
18
|
-
onChange: ()
|
|
22
|
+
onChange: function onChange() {},
|
|
19
23
|
value: JSON.stringify(state)
|
|
20
24
|
}), /*#__PURE__*/_jsx("button", {
|
|
21
|
-
onClick: ()
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
onClick: function onClick() {
|
|
26
|
+
return updateState({
|
|
27
|
+
widgets: []
|
|
28
|
+
});
|
|
29
|
+
},
|
|
24
30
|
children: "Remove widgets"
|
|
25
31
|
}), /*#__PURE__*/_jsx("button", {
|
|
26
|
-
onClick: ()
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
onClick: function onClick() {
|
|
33
|
+
return updateState({
|
|
34
|
+
widgets: [1]
|
|
35
|
+
});
|
|
36
|
+
},
|
|
29
37
|
children: "Add widget"
|
|
30
38
|
}), /*#__PURE__*/_jsx("button", {
|
|
31
|
-
onClick: ()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
onClick: function onClick() {
|
|
40
|
+
return updateState({
|
|
41
|
+
attributes: {
|
|
42
|
+
bar: 2
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
},
|
|
36
46
|
children: "Nested update"
|
|
37
47
|
}), /*#__PURE__*/_jsx("input", {
|
|
38
48
|
type: "text",
|
|
39
49
|
value: state.name,
|
|
40
|
-
onChange: e
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
onChange: function onChange(e) {
|
|
51
|
+
return updateState({
|
|
52
|
+
name: e.target.value
|
|
53
|
+
});
|
|
54
|
+
},
|
|
43
55
|
placeholder: "name"
|
|
44
56
|
})]
|
|
45
57
|
});
|
|
46
58
|
};
|
|
47
|
-
describe('useObjectState', ()
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
describe('useObjectState', function () {
|
|
60
|
+
var getState = function getState() {
|
|
61
|
+
return JSON.parse(screen.getByPlaceholderText('state').getAttribute('value'));
|
|
62
|
+
};
|
|
63
|
+
beforeEach(function () {
|
|
50
64
|
render(/*#__PURE__*/_jsx(TestComponent, {}));
|
|
51
65
|
});
|
|
52
|
-
it('updates arrays', ()
|
|
66
|
+
it('updates arrays', function () {
|
|
53
67
|
expect(getState()).toStrictEqual(INIT_STATE);
|
|
54
|
-
act(()
|
|
68
|
+
act(function () {
|
|
69
|
+
return screen.getByText('Remove widgets').click();
|
|
70
|
+
});
|
|
55
71
|
expect(getState()).toMatchObject({
|
|
56
72
|
widgets: []
|
|
57
73
|
});
|
|
58
|
-
act(()
|
|
74
|
+
act(function () {
|
|
75
|
+
return screen.getByText('Add widget').click();
|
|
76
|
+
});
|
|
59
77
|
expect(getState()).toMatchObject({
|
|
60
78
|
widgets: [1]
|
|
61
79
|
});
|
|
62
80
|
});
|
|
63
|
-
it('updates a simple value', ()
|
|
64
|
-
act(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
it('updates a simple value', function () {
|
|
82
|
+
act(function () {
|
|
83
|
+
return fireEvent.change(screen.getByPlaceholderText('name'), {
|
|
84
|
+
target: {
|
|
85
|
+
value: 'Ramon'
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
69
89
|
expect(getState()).toMatchObject({
|
|
70
90
|
name: 'Ramon'
|
|
71
91
|
});
|
|
72
92
|
});
|
|
73
|
-
it('updates a nested object', ()
|
|
74
|
-
act(()
|
|
93
|
+
it('updates a nested object', function () {
|
|
94
|
+
act(function () {
|
|
95
|
+
return screen.getByText('Nested update').click();
|
|
96
|
+
});
|
|
75
97
|
expect(getState()).toMatchObject({
|
|
76
98
|
attributes: {
|
|
77
99
|
bar: 2,
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* External dependencies.
|
|
5
5
|
*/
|
|
6
6
|
import { useEffect } from '@wordpress/element';
|
|
7
|
-
|
|
8
|
-
useEffect(()
|
|
9
|
-
|
|
7
|
+
var useOnClickOutside = function useOnClickOutside(ref, handler) {
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
var listener = function listener(event) {
|
|
10
10
|
// Do nothing if clicking ref's element or descendent elements
|
|
11
11
|
if (!ref.current || ref.current.contains(event.target)) {
|
|
12
12
|
return;
|
|
@@ -15,7 +15,7 @@ const useOnClickOutside = (ref, handler) => {
|
|
|
15
15
|
};
|
|
16
16
|
document.addEventListener('mousedown', listener);
|
|
17
17
|
document.addEventListener('touchstart', listener);
|
|
18
|
-
return ()
|
|
18
|
+
return function () {
|
|
19
19
|
document.removeEventListener('mousedown', listener);
|
|
20
20
|
document.removeEventListener('touchstart', listener);
|
|
21
21
|
};
|
|
@@ -9,13 +9,11 @@ import { useEffect, useRef } from '@wordpress/element';
|
|
|
9
9
|
* Internal dependencies.
|
|
10
10
|
*/
|
|
11
11
|
import Router from '../proxied-imports/router';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const self = useRef(null);
|
|
18
|
-
const onWindowOrTabClose = event => {
|
|
12
|
+
var useHistory = Router.useHistory;
|
|
13
|
+
export default (function (when, message) {
|
|
14
|
+
var history = useHistory();
|
|
15
|
+
var self = useRef(null);
|
|
16
|
+
var onWindowOrTabClose = function onWindowOrTabClose(event) {
|
|
19
17
|
if (!when) {
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
@@ -24,17 +22,17 @@ export default (when, message) => {
|
|
|
24
22
|
}
|
|
25
23
|
return message;
|
|
26
24
|
};
|
|
27
|
-
useEffect(()
|
|
25
|
+
useEffect(function () {
|
|
28
26
|
if (when) {
|
|
29
27
|
self.current = history.block(message);
|
|
30
28
|
window.addEventListener('beforeunload', onWindowOrTabClose);
|
|
31
29
|
}
|
|
32
|
-
return ()
|
|
30
|
+
return function () {
|
|
33
31
|
if (self.current) {
|
|
34
32
|
self.current();
|
|
35
33
|
}
|
|
36
34
|
window.removeEventListener('beforeunload', onWindowOrTabClose);
|
|
37
35
|
};
|
|
38
36
|
}, [message, when]);
|
|
39
|
-
return self.current || (
|
|
40
|
-
};
|
|
37
|
+
return self.current || function () {};
|
|
38
|
+
});
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
8
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1
9
|
/**
|
|
2
10
|
* Image Upload
|
|
3
11
|
*/
|
|
@@ -7,11 +15,12 @@
|
|
|
7
15
|
*/
|
|
8
16
|
import { Component } from '@wordpress/element';
|
|
9
17
|
import { __ } from '@wordpress/i18n';
|
|
18
|
+
import { BaseControl } from '@wordpress/components';
|
|
10
19
|
|
|
11
20
|
/**
|
|
12
21
|
* Internal dependencies.
|
|
13
22
|
*/
|
|
14
|
-
import { Button
|
|
23
|
+
import { Button } from '../';
|
|
15
24
|
import './style.scss';
|
|
16
25
|
|
|
17
26
|
/**
|
|
@@ -19,122 +28,112 @@ import './style.scss';
|
|
|
19
28
|
*/
|
|
20
29
|
import classnames from 'classnames';
|
|
21
30
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
|
-
|
|
31
|
+
var ImageUpload = /*#__PURE__*/function (_Component) {
|
|
23
32
|
/**
|
|
24
33
|
* Constructor.
|
|
25
34
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.state.frame.on('select', this.handleImageSelect);
|
|
54
|
-
this.state.frame.open();
|
|
35
|
+
function ImageUpload() {
|
|
36
|
+
var _this;
|
|
37
|
+
_classCallCheck(this, ImageUpload);
|
|
38
|
+
_this = _callSuper(this, ImageUpload, arguments);
|
|
39
|
+
/**
|
|
40
|
+
* Open the WP media modal.
|
|
41
|
+
*/
|
|
42
|
+
_defineProperty(_this, "openModal", function () {
|
|
43
|
+
if (_this.state.frame) {
|
|
44
|
+
_this.state.frame.open();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
_this.setState({
|
|
48
|
+
frame: wp.media({
|
|
49
|
+
title: __('Select or upload image'),
|
|
50
|
+
button: {
|
|
51
|
+
text: __('Select')
|
|
52
|
+
},
|
|
53
|
+
library: {
|
|
54
|
+
type: 'image'
|
|
55
|
+
},
|
|
56
|
+
multiple: false
|
|
57
|
+
})
|
|
58
|
+
}, function () {
|
|
59
|
+
_this.state.frame.on('select', _this.handleImageSelect);
|
|
60
|
+
_this.state.frame.open();
|
|
61
|
+
});
|
|
55
62
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
onChange
|
|
64
|
-
} = this.props;
|
|
65
|
-
const attachment = this.state.frame.state().get('selection').first().toJSON();
|
|
66
|
-
onChange(attachment);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Render.
|
|
71
|
-
*/
|
|
72
|
-
render = () => {
|
|
73
|
-
const {
|
|
74
|
-
buttonLabel,
|
|
75
|
-
className,
|
|
76
|
-
disabled,
|
|
77
|
-
help,
|
|
78
|
-
image,
|
|
79
|
-
info,
|
|
80
|
-
isCovering,
|
|
81
|
-
label,
|
|
82
|
-
onChange,
|
|
83
|
-
style = {}
|
|
84
|
-
} = this.props;
|
|
85
|
-
const classes = classnames('newspack-image-upload__image', {
|
|
86
|
-
'newspack-image-upload__image--has-image': image
|
|
87
|
-
}, {
|
|
88
|
-
'newspack-image-upload__image--covering': isCovering
|
|
63
|
+
/**
|
|
64
|
+
* Update the state when an image is selected from the media modal.
|
|
65
|
+
*/
|
|
66
|
+
_defineProperty(_this, "handleImageSelect", function () {
|
|
67
|
+
var onChange = _this.props.onChange;
|
|
68
|
+
var attachment = _this.state.frame.state().get('selection').first().toJSON();
|
|
69
|
+
onChange(attachment);
|
|
89
70
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Render.
|
|
73
|
+
*/
|
|
74
|
+
_defineProperty(_this, "render", function () {
|
|
75
|
+
var _this$props = _this.props,
|
|
76
|
+
buttonLabel = _this$props.buttonLabel,
|
|
77
|
+
className = _this$props.className,
|
|
78
|
+
disabled = _this$props.disabled,
|
|
79
|
+
help = _this$props.help,
|
|
80
|
+
image = _this$props.image,
|
|
81
|
+
isCovering = _this$props.isCovering,
|
|
82
|
+
label = _this$props.label,
|
|
83
|
+
onChange = _this$props.onChange,
|
|
84
|
+
_this$props$style = _this$props.style,
|
|
85
|
+
style = _this$props$style === void 0 ? {} : _this$props$style;
|
|
86
|
+
var classes = classnames('newspack-image-upload__image', {
|
|
87
|
+
'newspack-image-upload__image--has-image': image
|
|
88
|
+
}, {
|
|
89
|
+
'newspack-image-upload__image--covering': isCovering
|
|
90
|
+
});
|
|
91
|
+
return /*#__PURE__*/_jsxs(BaseControl, {
|
|
92
|
+
__nextHasNoMarginBottom: true,
|
|
93
|
+
className: classnames('newspack-image-upload', className),
|
|
94
|
+
help: help,
|
|
95
|
+
children: [label && /*#__PURE__*/_jsx(BaseControl.VisualLabel, {
|
|
96
96
|
children: label
|
|
97
|
-
}),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
onClick: () => onChange(null),
|
|
122
|
-
isLink: true,
|
|
123
|
-
isDestructive: true,
|
|
124
|
-
children: __('Remove', 'newspack-plugin')
|
|
97
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
98
|
+
className: classes,
|
|
99
|
+
style: style,
|
|
100
|
+
children: image !== null && image !== void 0 && image.url ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
101
|
+
children: [/*#__PURE__*/_jsx("img", {
|
|
102
|
+
"data-testid": "image-upload",
|
|
103
|
+
src: image.url,
|
|
104
|
+
alt: __('Image preview', 'newspack-plugin')
|
|
105
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
106
|
+
className: "newspack-image-upload__controls",
|
|
107
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
108
|
+
disabled: disabled,
|
|
109
|
+
onClick: _this.openModal,
|
|
110
|
+
variant: "tertiary",
|
|
111
|
+
children: __('Replace', 'newspack-plugin')
|
|
112
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
113
|
+
disabled: disabled,
|
|
114
|
+
onClick: function onClick() {
|
|
115
|
+
return onChange(null);
|
|
116
|
+
},
|
|
117
|
+
variant: "tertiary",
|
|
118
|
+
isDestructive: true,
|
|
119
|
+
children: __('Remove', 'newspack-plugin')
|
|
120
|
+
})]
|
|
125
121
|
})]
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
className: "newspack-image-upload__help",
|
|
135
|
-
children: help
|
|
136
|
-
})]
|
|
122
|
+
}) : /*#__PURE__*/_jsx(Button, {
|
|
123
|
+
disabled: disabled,
|
|
124
|
+
onClick: _this.openModal,
|
|
125
|
+
variant: "tertiary",
|
|
126
|
+
children: buttonLabel ? buttonLabel : __('Upload', 'newspack-plugin')
|
|
127
|
+
})
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
137
130
|
});
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
_this.state = {
|
|
132
|
+
frame: false
|
|
133
|
+
};
|
|
134
|
+
return _this;
|
|
135
|
+
}
|
|
136
|
+
_inherits(ImageUpload, _Component);
|
|
137
|
+
return _createClass(ImageUpload);
|
|
138
|
+
}(Component);
|
|
140
139
|
export default ImageUpload;
|
|
@@ -8,24 +8,22 @@ import { render } from '@testing-library/react';
|
|
|
8
8
|
*/
|
|
9
9
|
import ImageUpload from './';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
describe('ImageUpload', ()
|
|
12
|
-
it('should render an add image button', ()
|
|
13
|
-
|
|
14
|
-
getByText
|
|
15
|
-
} = render(/*#__PURE__*/_jsx(ImageUpload, {}));
|
|
11
|
+
describe('ImageUpload', function () {
|
|
12
|
+
it('should render an add image button', function () {
|
|
13
|
+
var _render = render(/*#__PURE__*/_jsx(ImageUpload, {})),
|
|
14
|
+
getByText = _render.getByText;
|
|
16
15
|
expect(getByText('Upload')).toBeInTheDocument();
|
|
17
16
|
});
|
|
18
|
-
it('should render replace and remove buttons if there is an image provided', ()
|
|
19
|
-
|
|
17
|
+
it('should render replace and remove buttons if there is an image provided', function () {
|
|
18
|
+
var image = {
|
|
20
19
|
id: 1234,
|
|
21
20
|
url: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg'
|
|
22
21
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}));
|
|
22
|
+
var _render2 = render(/*#__PURE__*/_jsx(ImageUpload, {
|
|
23
|
+
image: image
|
|
24
|
+
})),
|
|
25
|
+
getByText = _render2.getByText,
|
|
26
|
+
getByTestId = _render2.getByTestId;
|
|
29
27
|
expect(getByText('Remove')).toBeInTheDocument();
|
|
30
28
|
expect(getByText('Replace')).toBeInTheDocument();
|
|
31
29
|
expect(getByTestId('image-upload')).toBeInTheDocument();
|
|
@@ -3,45 +3,29 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
@use "~@wordpress/base-styles/colors" as wp-colors;
|
|
6
|
+
@use "~@wordpress/base-styles/variables" as wp-vars;
|
|
6
7
|
|
|
7
8
|
.newspack-image-upload {
|
|
8
|
-
margin:
|
|
9
|
-
&__header {
|
|
10
|
-
display: flex;
|
|
11
|
-
}
|
|
12
|
-
&__label {
|
|
13
|
-
margin: 0 0 8px;
|
|
14
|
-
}
|
|
9
|
+
margin: wp-vars.$grid-unit-40 0;
|
|
15
10
|
&__image {
|
|
16
11
|
align-items: center;
|
|
12
|
+
background-position: center;
|
|
17
13
|
background-repeat: no-repeat;
|
|
18
14
|
background-size: contain;
|
|
19
|
-
|
|
20
|
-
border:
|
|
21
|
-
border-radius: 2px;
|
|
15
|
+
border: 1px dashed wp-colors.$gray-600;
|
|
16
|
+
border-radius: wp-vars.$radius-small;
|
|
22
17
|
display: flex;
|
|
23
18
|
justify-content: center;
|
|
24
19
|
max-width: 100%;
|
|
25
|
-
min-height:
|
|
20
|
+
min-height: wp-vars.$grid-unit-50;
|
|
26
21
|
position: relative;
|
|
27
22
|
&--covering {
|
|
28
23
|
background-size: cover;
|
|
29
24
|
}
|
|
30
25
|
&:not(&--has-image) {
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
padding: 4px 16px !important;
|
|
35
|
-
|
|
36
|
-
&:active,
|
|
37
|
-
&:focus,
|
|
38
|
-
&:hover {
|
|
39
|
-
background: white !important;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
&:focus {
|
|
43
|
-
outline-offset: -3px !important;
|
|
44
|
-
}
|
|
26
|
+
.components-button {
|
|
27
|
+
justify-content: center;
|
|
28
|
+
width: calc(100% - 2px);
|
|
45
29
|
}
|
|
46
30
|
}
|
|
47
31
|
&--has-image {
|
|
@@ -49,8 +33,8 @@
|
|
|
49
33
|
overflow: hidden;
|
|
50
34
|
&::before,
|
|
51
35
|
&::after {
|
|
52
|
-
border: 1px solid rgba(black, 0.54);
|
|
53
|
-
border-radius:
|
|
36
|
+
border: 1px solid rgba(wp-colors.$black, 0.54);
|
|
37
|
+
border-radius: wp-vars.$radius-small;
|
|
54
38
|
content: "";
|
|
55
39
|
inset: 0;
|
|
56
40
|
position: absolute;
|
|
@@ -66,7 +50,7 @@
|
|
|
66
50
|
position: relative;
|
|
67
51
|
}
|
|
68
52
|
&::after {
|
|
69
|
-
background: rgba(white, 0.
|
|
53
|
+
background: rgba(wp-colors.$white, 0.95);
|
|
70
54
|
border-color: wp-colors.$gray-700;
|
|
71
55
|
}
|
|
72
56
|
&:focus-within,
|
|
@@ -80,20 +64,8 @@
|
|
|
80
64
|
max-height: 100%;
|
|
81
65
|
max-width: 100%;
|
|
82
66
|
}
|
|
83
|
-
.sep {
|
|
84
|
-
background: transparent;
|
|
85
|
-
display: block;
|
|
86
|
-
height: 8px;
|
|
87
|
-
margin: 0;
|
|
88
|
-
width: 100%;
|
|
89
|
-
}
|
|
90
67
|
}
|
|
91
68
|
}
|
|
92
|
-
&__image + &__help {
|
|
93
|
-
color: wp-colors.$gray-700;
|
|
94
|
-
font-size: 12px;
|
|
95
|
-
margin: 1em 0 0;
|
|
96
|
-
}
|
|
97
69
|
&__controls {
|
|
98
70
|
align-items: center;
|
|
99
71
|
display: flex;
|
package/dist/esm/index.js
CHANGED
|
@@ -5,15 +5,17 @@ export { default as AutocompleteWithSuggestions } from './autocomplete-with-sugg
|
|
|
5
5
|
export { default as AutocompleteWithLatestPosts } from './autocomplete-with-latest-posts';
|
|
6
6
|
export { default as Badge } from './badge';
|
|
7
7
|
export { default as Button } from './button';
|
|
8
|
-
export { default as ButtonCard } from './button-card';
|
|
9
8
|
export { default as BoxContrast } from './box-contrast';
|
|
10
9
|
export { default as Card } from './card';
|
|
10
|
+
export { default as CardFeature } from './card-feature';
|
|
11
|
+
export { default as CardForm } from './card-form';
|
|
11
12
|
export { default as CardSettingsGroup } from './card-settings-group';
|
|
12
13
|
export { default as CardSortableList } from './card-sortable-list';
|
|
13
14
|
export { default as CategoryAutocomplete } from './category-autocomplete';
|
|
14
15
|
export { default as ColorPicker } from './color-picker';
|
|
15
16
|
export { default as ConfirmDialog } from './confirm-dialog';
|
|
16
17
|
export { default as CustomSelectControl } from './custom-select-control';
|
|
18
|
+
export { default as DataViews } from './dataviews';
|
|
17
19
|
export { default as Divider } from './divider';
|
|
18
20
|
export { default as FormTokenField } from './form-token-field';
|
|
19
21
|
export { default as Footer } from './footer';
|
|
@@ -47,5 +49,9 @@ export { default as withWizard } from './with-wizard';
|
|
|
47
49
|
export { default as withWizardScreen } from './with-wizard-screen';
|
|
48
50
|
export { default as Router } from './proxied-imports/router';
|
|
49
51
|
export { default as hooks } from './hooks';
|
|
52
|
+
export { default as useConfirmDialog } from './hooks/use-confirm-dialog';
|
|
53
|
+
export { default as useUnsavedChangesDialog } from './hooks/use-unsaved-changes-dialog';
|
|
54
|
+
import * as integrationIcons from './integration-icons';
|
|
55
|
+
export { integrationIcons };
|
|
50
56
|
export { default as utils } from './utils';
|
|
51
57
|
import './style.scss';
|