newspack-components 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/DEVELOPMENT.md +1 -1
- package/dist/cjs/accordion/index.js +43 -26
- package/dist/cjs/accordion/index.test.js +80 -0
- package/dist/cjs/accordion/style.scss +25 -21
- package/dist/cjs/action-card/style.scss +0 -22
- package/dist/cjs/breadcrumbs/index.js +80 -0
- package/dist/cjs/breadcrumbs/index.test.js +109 -0
- package/dist/cjs/breadcrumbs/style.scss +41 -0
- package/dist/cjs/card/core-card.js +8 -4
- package/dist/cjs/card/index.js +1 -1
- package/dist/cjs/card/style-core.scss +14 -0
- package/dist/cjs/card/style.scss +0 -9
- package/dist/cjs/card-feature/index.js +25 -13
- package/dist/cjs/card-settings-group/index.js +3 -0
- package/dist/cjs/confirm-dialog/index.js +34 -8
- package/dist/cjs/confirm-dialog/index.test.js +173 -0
- package/dist/cjs/divider/style.scss +4 -2
- package/dist/cjs/grid/style.scss +5 -0
- package/dist/cjs/handoff/index.js +8 -5
- package/dist/cjs/index.js +34 -1
- package/dist/cjs/integration-icon/index.js +40 -0
- package/dist/cjs/integration-icon/style.scss +42 -0
- package/dist/cjs/integration-icons/index.js +21 -2
- package/dist/cjs/modal/style.scss +4 -0
- package/dist/cjs/page/index.js +121 -0
- package/dist/cjs/page/index.test.js +69 -0
- package/dist/cjs/page/style.scss +86 -0
- package/dist/cjs/route-match.js +59 -0
- package/dist/cjs/route-match.test.js +77 -0
- package/dist/cjs/section-header/index.js +8 -1
- package/dist/cjs/section-header/style.scss +11 -11
- package/dist/cjs/select-control/GroupedSelectControl.js +1 -1
- package/dist/cjs/select-control/style.scss +4 -0
- package/dist/cjs/style.scss +1 -4
- package/dist/cjs/tabbed-navigation/index.js +188 -40
- package/dist/cjs/tabbed-navigation/index.test.js +299 -0
- package/dist/cjs/tabbed-navigation/style.scss +77 -57
- package/dist/cjs/with-wizard/index.js +34 -45
- package/dist/cjs/with-wizard-screen/index.js +82 -41
- package/dist/cjs/with-wizard-screen/index.test.js +50 -0
- package/dist/cjs/with-wizard-screen/style.scss +15 -118
- package/dist/cjs/wizard/breadcrumbs-select.js +70 -0
- package/dist/cjs/wizard/breadcrumbs-select.test.js +200 -0
- package/dist/cjs/wizard/components/WizardError.js +8 -4
- package/dist/cjs/wizard/index.js +162 -141
- package/dist/esm/accordion/index.js +42 -26
- package/dist/esm/accordion/index.test.js +79 -0
- package/dist/esm/accordion/style.scss +25 -21
- package/dist/esm/action-card/style.scss +0 -22
- package/dist/esm/breadcrumbs/index.js +75 -0
- package/dist/esm/breadcrumbs/index.test.js +105 -0
- package/dist/esm/breadcrumbs/style.scss +41 -0
- package/dist/esm/card/core-card.js +8 -4
- package/dist/esm/card/index.js +1 -1
- package/dist/esm/card/style-core.scss +14 -0
- package/dist/esm/card/style.scss +0 -9
- package/dist/esm/card-feature/index.js +25 -13
- package/dist/esm/card-settings-group/index.js +3 -0
- package/dist/esm/confirm-dialog/index.js +34 -8
- package/dist/esm/confirm-dialog/index.test.js +173 -0
- package/dist/esm/divider/style.scss +4 -2
- package/dist/esm/grid/style.scss +5 -0
- package/dist/esm/handoff/index.js +7 -5
- package/dist/esm/index.js +5 -1
- package/dist/esm/integration-icon/index.js +34 -0
- package/dist/esm/integration-icon/style.scss +42 -0
- package/dist/esm/integration-icons/index.js +22 -1
- package/dist/esm/modal/style.scss +4 -0
- package/dist/esm/page/index.js +113 -0
- package/dist/esm/page/index.test.js +65 -0
- package/dist/esm/page/style.scss +86 -0
- package/dist/esm/route-match.js +51 -0
- package/dist/esm/route-match.test.js +74 -0
- package/dist/esm/section-header/index.js +8 -1
- package/dist/esm/section-header/style.scss +11 -11
- package/dist/esm/select-control/GroupedSelectControl.js +1 -1
- package/dist/esm/select-control/style.scss +4 -0
- package/dist/esm/style.scss +1 -4
- package/dist/esm/tabbed-navigation/index.js +192 -38
- package/dist/esm/tabbed-navigation/index.test.js +296 -0
- package/dist/esm/tabbed-navigation/style.scss +77 -57
- package/dist/esm/with-wizard/index.js +33 -45
- package/dist/esm/with-wizard-screen/index.js +78 -41
- package/dist/esm/with-wizard-screen/index.test.js +46 -0
- package/dist/esm/with-wizard-screen/style.scss +15 -118
- package/dist/esm/wizard/breadcrumbs-select.js +63 -0
- package/dist/esm/wizard/breadcrumbs-select.test.js +197 -0
- package/dist/esm/wizard/components/WizardError.js +7 -5
- package/dist/esm/wizard/index.js +165 -144
- package/package.json +10 -2
- package/src/accordion/index.js +27 -15
- package/src/accordion/index.test.js +62 -0
- package/src/accordion/style.scss +25 -21
- package/src/action-card/style.scss +0 -22
- package/src/breadcrumbs/index.js +63 -0
- package/src/breadcrumbs/index.test.js +59 -0
- package/src/breadcrumbs/style.scss +41 -0
- package/src/card/core-card.js +11 -6
- package/src/card/index.js +0 -1
- package/src/card/style-core.scss +14 -0
- package/src/card/style.scss +0 -9
- package/src/card-feature/README.md +3 -3
- package/src/card-feature/index.tsx +37 -21
- package/src/card-settings-group/index.tsx +4 -0
- package/src/card-sortable-list/index.tsx +1 -1
- package/src/confirm-dialog/index.test.js +142 -0
- package/src/confirm-dialog/index.tsx +34 -7
- package/src/divider/style.scss +4 -2
- package/src/grid/style.scss +5 -0
- package/src/handoff/index.js +4 -3
- package/src/index.js +5 -1
- package/src/integration-icon/index.tsx +35 -0
- package/src/integration-icon/style.scss +42 -0
- package/src/integration-icons/index.js +23 -0
- package/src/modal/style.scss +4 -0
- package/src/page/index.js +89 -0
- package/src/page/index.test.js +43 -0
- package/src/page/style.scss +86 -0
- package/src/route-match.js +47 -0
- package/src/route-match.test.js +50 -0
- package/src/section-header/index.js +7 -3
- package/src/section-header/style.scss +11 -11
- package/src/select-control/GroupedSelectControl.js +1 -1
- package/src/select-control/style.scss +4 -0
- package/src/style.scss +1 -4
- package/src/tabbed-navigation/index.js +181 -34
- package/src/tabbed-navigation/index.test.js +228 -0
- package/src/tabbed-navigation/style.scss +77 -57
- package/src/with-wizard/index.js +18 -39
- package/src/with-wizard-screen/index.js +70 -35
- package/src/with-wizard-screen/index.test.js +36 -0
- package/src/with-wizard-screen/style.scss +15 -118
- package/src/wizard/breadcrumbs-select.js +51 -0
- package/src/wizard/breadcrumbs-select.test.js +124 -0
- package/src/wizard/components/WizardError.js +4 -3
- package/src/wizard/index.js +160 -146
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.appendSectionName = exports.activeBreadcrumbs = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _routeMatch = require("../route-match");
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Select the active section's explicit breadcrumb trail by current route. Falls
|
|
16
|
+
* back to the first section, then to an empty trail.
|
|
17
|
+
*
|
|
18
|
+
* @param {Array} sections Wizard sections (`{ path, breadcrumbs, exact?, activeTabPaths? }`).
|
|
19
|
+
* @param {string} pathname Current router pathname.
|
|
20
|
+
* @return {Array} Breadcrumb items `{ label, url? }`.
|
|
21
|
+
*/
|
|
22
|
+
var activeBreadcrumbs = exports.activeBreadcrumbs = function activeBreadcrumbs() {
|
|
23
|
+
var sections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
24
|
+
var pathname = arguments.length > 1 ? arguments[1] : undefined;
|
|
25
|
+
if (!(sections !== null && sections !== void 0 && sections.length)) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
var match = sections.find(function (section) {
|
|
29
|
+
return (0, _routeMatch.matchesRoute)(section, pathname);
|
|
30
|
+
}) || sections[0];
|
|
31
|
+
return match.breadcrumbs || [];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Append a section's render-time current-page breadcrumb(s) to a trail.
|
|
36
|
+
*
|
|
37
|
+
* A section can supply a leaf via `headerData.sectionName` — either a single
|
|
38
|
+
* label (e.g. an integration name, or Add/Edit) or an ordered array of
|
|
39
|
+
* `{ label, url? }` crumbs when the leaf needs its own linked ancestors. Each
|
|
40
|
+
* crumb is appended in turn.
|
|
41
|
+
*
|
|
42
|
+
* Convention: a route authors its current-page leaf in exactly ONE place —
|
|
43
|
+
* the static `breadcrumbs` array for a constant label, or `sectionName` for a
|
|
44
|
+
* render-time label (e.g. Add/Edit) whose static trail then holds ancestors
|
|
45
|
+
* only. Never both. The trailing-label skip below is a defensive guard against
|
|
46
|
+
* a route accidentally doing both; it is not a supported pattern to rely on.
|
|
47
|
+
*
|
|
48
|
+
* @param {Array} breadcrumbItems Base trail `{ label, url? }[]`.
|
|
49
|
+
* @param {string|Array|undefined} sectionName A label, an array of crumbs, or falsy.
|
|
50
|
+
* @return {Array} A new trail with the section crumb(s) appended (deduped).
|
|
51
|
+
*/
|
|
52
|
+
var appendSectionName = exports.appendSectionName = function appendSectionName() {
|
|
53
|
+
var breadcrumbItems = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
54
|
+
var sectionName = arguments.length > 1 ? arguments[1] : undefined;
|
|
55
|
+
if (!sectionName) {
|
|
56
|
+
return breadcrumbItems;
|
|
57
|
+
}
|
|
58
|
+
var extraCrumbs = (Array.isArray(sectionName) ? sectionName : [{
|
|
59
|
+
label: sectionName
|
|
60
|
+
}]).filter(function (crumb) {
|
|
61
|
+
return crumb === null || crumb === void 0 ? void 0 : crumb.label;
|
|
62
|
+
});
|
|
63
|
+
return extraCrumbs.reduce(function (trail, crumb) {
|
|
64
|
+
var _trail;
|
|
65
|
+
if (((_trail = trail[trail.length - 1]) === null || _trail === void 0 ? void 0 : _trail.label) === crumb.label) {
|
|
66
|
+
return trail;
|
|
67
|
+
}
|
|
68
|
+
return [].concat((0, _toConsumableArray2["default"])(trail), [crumb]);
|
|
69
|
+
}, breadcrumbItems);
|
|
70
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _breadcrumbsSelect = require("./breadcrumbs-select");
|
|
4
|
+
/**
|
|
5
|
+
* Internal dependencies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
var SECTIONS = [{
|
|
9
|
+
path: '/',
|
|
10
|
+
breadcrumbs: [{
|
|
11
|
+
label: 'Audience Management'
|
|
12
|
+
}, {
|
|
13
|
+
label: 'Configuration'
|
|
14
|
+
}]
|
|
15
|
+
}, {
|
|
16
|
+
path: '/donations',
|
|
17
|
+
breadcrumbs: [{
|
|
18
|
+
label: 'Audience Management'
|
|
19
|
+
}, {
|
|
20
|
+
label: 'Donations'
|
|
21
|
+
}]
|
|
22
|
+
}];
|
|
23
|
+
describe('activeBreadcrumbs', function () {
|
|
24
|
+
it('returns the matching section breadcrumbs by exact path', function () {
|
|
25
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(SECTIONS, '/donations')).toEqual([{
|
|
26
|
+
label: 'Audience Management'
|
|
27
|
+
}, {
|
|
28
|
+
label: 'Donations'
|
|
29
|
+
}]);
|
|
30
|
+
});
|
|
31
|
+
it('falls back to the first section when no path matches', function () {
|
|
32
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(SECTIONS, '/nope')).toEqual(SECTIONS[0].breadcrumbs);
|
|
33
|
+
});
|
|
34
|
+
it('returns [] when sections is empty', function () {
|
|
35
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)([], '/x')).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
it('returns [] when sections is null or undefined', function () {
|
|
38
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(null, '/x')).toEqual([]);
|
|
39
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(undefined, '/x')).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
it('matches a non-exact section by path prefix', function () {
|
|
42
|
+
var sections = [{
|
|
43
|
+
path: '/',
|
|
44
|
+
breadcrumbs: [{
|
|
45
|
+
label: 'Root'
|
|
46
|
+
}]
|
|
47
|
+
}, {
|
|
48
|
+
path: '/access',
|
|
49
|
+
exact: false,
|
|
50
|
+
breadcrumbs: [{
|
|
51
|
+
label: 'Root'
|
|
52
|
+
}, {
|
|
53
|
+
label: 'Access control'
|
|
54
|
+
}]
|
|
55
|
+
}];
|
|
56
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(sections, '/access/institutions')).toEqual([{
|
|
57
|
+
label: 'Root'
|
|
58
|
+
}, {
|
|
59
|
+
label: 'Access control'
|
|
60
|
+
}]);
|
|
61
|
+
});
|
|
62
|
+
it('matches a parameterized route to its own breadcrumbs', function () {
|
|
63
|
+
var sections = [{
|
|
64
|
+
path: '/content-gates',
|
|
65
|
+
breadcrumbs: [{
|
|
66
|
+
label: 'Access control'
|
|
67
|
+
}]
|
|
68
|
+
}, {
|
|
69
|
+
path: '/institutions/:id',
|
|
70
|
+
exact: true,
|
|
71
|
+
breadcrumbs: [{
|
|
72
|
+
label: 'Access control'
|
|
73
|
+
}, {
|
|
74
|
+
label: 'Edit institution'
|
|
75
|
+
}]
|
|
76
|
+
}];
|
|
77
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(sections, '/institutions/123')).toEqual([{
|
|
78
|
+
label: 'Access control'
|
|
79
|
+
}, {
|
|
80
|
+
label: 'Edit institution'
|
|
81
|
+
}]);
|
|
82
|
+
});
|
|
83
|
+
it('matches via activeTabPaths wildcard', function () {
|
|
84
|
+
var sections = [{
|
|
85
|
+
path: '/',
|
|
86
|
+
breadcrumbs: [{
|
|
87
|
+
label: 'Root'
|
|
88
|
+
}]
|
|
89
|
+
}, {
|
|
90
|
+
path: '/segments',
|
|
91
|
+
activeTabPaths: ['/segments/*'],
|
|
92
|
+
breadcrumbs: [{
|
|
93
|
+
label: 'Root'
|
|
94
|
+
}, {
|
|
95
|
+
label: 'Segments'
|
|
96
|
+
}]
|
|
97
|
+
}];
|
|
98
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(sections, '/segments/123')).toEqual([{
|
|
99
|
+
label: 'Root'
|
|
100
|
+
}, {
|
|
101
|
+
label: 'Segments'
|
|
102
|
+
}]);
|
|
103
|
+
});
|
|
104
|
+
it('prefers an exact path match over the first section', function () {
|
|
105
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)(SECTIONS, '/')).toEqual(SECTIONS[0].breadcrumbs);
|
|
106
|
+
});
|
|
107
|
+
it('returns [] when the matched section has no breadcrumbs', function () {
|
|
108
|
+
expect((0, _breadcrumbsSelect.activeBreadcrumbs)([{
|
|
109
|
+
path: '/'
|
|
110
|
+
}], '/')).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('appendSectionName', function () {
|
|
114
|
+
var base = [{
|
|
115
|
+
label: 'Access Control'
|
|
116
|
+
}];
|
|
117
|
+
it('returns the base trail unchanged when sectionName is falsy', function () {
|
|
118
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(base, undefined)).toBe(base);
|
|
119
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(base, '')).toBe(base);
|
|
120
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(base, null)).toBe(base);
|
|
121
|
+
});
|
|
122
|
+
it('appends a string sectionName as a leaf crumb', function () {
|
|
123
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(base, 'Content Gifting')).toEqual([{
|
|
124
|
+
label: 'Access Control'
|
|
125
|
+
}, {
|
|
126
|
+
label: 'Content Gifting'
|
|
127
|
+
}]);
|
|
128
|
+
});
|
|
129
|
+
it('appends an array of crumbs in order', function () {
|
|
130
|
+
var sectionName = [{
|
|
131
|
+
label: 'Mailchimp',
|
|
132
|
+
url: '/mailchimp'
|
|
133
|
+
}, {
|
|
134
|
+
label: 'Logs'
|
|
135
|
+
}];
|
|
136
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(base, sectionName)).toEqual([{
|
|
137
|
+
label: 'Access Control'
|
|
138
|
+
}, {
|
|
139
|
+
label: 'Mailchimp',
|
|
140
|
+
url: '/mailchimp'
|
|
141
|
+
}, {
|
|
142
|
+
label: 'Logs'
|
|
143
|
+
}]);
|
|
144
|
+
});
|
|
145
|
+
it('dedupes a string leaf that repeats the current trailing label', function () {
|
|
146
|
+
var trail = [{
|
|
147
|
+
label: 'Access Control'
|
|
148
|
+
}, {
|
|
149
|
+
label: 'Metered Countdown'
|
|
150
|
+
}];
|
|
151
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(trail, 'Metered Countdown')).toEqual(trail);
|
|
152
|
+
});
|
|
153
|
+
it('dedupes an array leaf that repeats the current trailing label', function () {
|
|
154
|
+
var trail = [{
|
|
155
|
+
label: 'Access Control'
|
|
156
|
+
}, {
|
|
157
|
+
label: 'Metered Countdown'
|
|
158
|
+
}];
|
|
159
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(trail, [{
|
|
160
|
+
label: 'Metered Countdown'
|
|
161
|
+
}])).toEqual(trail);
|
|
162
|
+
});
|
|
163
|
+
it('skips crumbs without a label', function () {
|
|
164
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(base, [{
|
|
165
|
+
url: '/no-label'
|
|
166
|
+
}, {
|
|
167
|
+
label: 'Edit'
|
|
168
|
+
}])).toEqual([{
|
|
169
|
+
label: 'Access Control'
|
|
170
|
+
}, {
|
|
171
|
+
label: 'Edit'
|
|
172
|
+
}]);
|
|
173
|
+
});
|
|
174
|
+
it('only dedupes against the immediate predecessor, not earlier crumbs', function () {
|
|
175
|
+
var trail = [{
|
|
176
|
+
label: 'Access Control'
|
|
177
|
+
}, {
|
|
178
|
+
label: 'Institutions'
|
|
179
|
+
}];
|
|
180
|
+
// 'Access Control' repeats an earlier (non-adjacent) crumb, so it is kept.
|
|
181
|
+
expect((0, _breadcrumbsSelect.appendSectionName)(trail, [{
|
|
182
|
+
label: 'Access Control'
|
|
183
|
+
}])).toEqual([{
|
|
184
|
+
label: 'Access Control'
|
|
185
|
+
}, {
|
|
186
|
+
label: 'Institutions'
|
|
187
|
+
}, {
|
|
188
|
+
label: 'Access Control'
|
|
189
|
+
}]);
|
|
190
|
+
});
|
|
191
|
+
it('does not mutate the input trail', function () {
|
|
192
|
+
var trail = [{
|
|
193
|
+
label: 'Access Control'
|
|
194
|
+
}];
|
|
195
|
+
(0, _breadcrumbsSelect.appendSectionName)(trail, 'Content Gifting');
|
|
196
|
+
expect(trail).toEqual([{
|
|
197
|
+
label: 'Access Control'
|
|
198
|
+
}]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _i18n = require("@wordpress/i18n");
|
|
8
8
|
var _data = require("@wordpress/data");
|
|
9
|
+
var _components = require("@wordpress/components");
|
|
9
10
|
var _ = require("../..");
|
|
10
11
|
var _store = require("../store");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -13,6 +14,8 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
13
14
|
* WordPress dependencies.
|
|
14
15
|
*/
|
|
15
16
|
|
|
17
|
+
// eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* Internal dependencies.
|
|
18
21
|
*/
|
|
@@ -53,10 +56,11 @@ var WizardError = function WizardError() {
|
|
|
53
56
|
noticeText: message,
|
|
54
57
|
isError: true,
|
|
55
58
|
rawHTML: true
|
|
56
|
-
}), fallbackURL && /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
}), fallbackURL && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHStack, {
|
|
60
|
+
justify: "flex-end",
|
|
61
|
+
spacing: 4,
|
|
62
|
+
wrap: true,
|
|
63
|
+
className: "newspack-modal__footer",
|
|
60
64
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
|
|
61
65
|
isPrimary: true,
|
|
62
66
|
href: fallbackURL,
|
package/dist/cjs/wizard/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var _element = require("@wordpress/element");
|
|
|
14
14
|
var _i18n = require("@wordpress/i18n");
|
|
15
15
|
var _icons = require("@wordpress/icons");
|
|
16
16
|
var _ = require("../");
|
|
17
|
+
var _breadcrumbsSelect = require("./breadcrumbs-select");
|
|
17
18
|
var _router = _interopRequireDefault(require("../proxied-imports/router"));
|
|
18
19
|
var _store = _interopRequireWildcard(require("./store"));
|
|
19
20
|
var _WizardSnackbar = _interopRequireDefault(require("./components/WizardSnackbar"));
|
|
@@ -66,6 +67,49 @@ var ResetHeaderData = function ResetHeaderData() {
|
|
|
66
67
|
return null;
|
|
67
68
|
};
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Wizard header + content region. Rendered inside the wizard's HashRouter so it
|
|
72
|
+
* can read the current route and derive the active-tab breadcrumb.
|
|
73
|
+
*/
|
|
74
|
+
var WizardHeaderRegion = function WizardHeaderRegion(_ref) {
|
|
75
|
+
var hideHeader = _ref.hideHeader,
|
|
76
|
+
headerText = _ref.headerText,
|
|
77
|
+
sections = _ref.sections,
|
|
78
|
+
sectionName = _ref.sectionName,
|
|
79
|
+
subTitle = _ref.subTitle,
|
|
80
|
+
actions = _ref.actions,
|
|
81
|
+
tabbedNavigation = _ref.tabbedNavigation,
|
|
82
|
+
children = _ref.children;
|
|
83
|
+
var _useLocation = useLocation(),
|
|
84
|
+
pathname = _useLocation.pathname;
|
|
85
|
+
if (hideHeader) {
|
|
86
|
+
// Without the Page shell the tabs still own the content: it renders
|
|
87
|
+
// inside the active tab's panel.
|
|
88
|
+
if ((0, _element.isValidElement)(tabbedNavigation)) {
|
|
89
|
+
return (0, _element.cloneElement)(tabbedNavigation, {
|
|
90
|
+
content: children
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return children;
|
|
94
|
+
}
|
|
95
|
+
var breadcrumbItems = (0, _breadcrumbsSelect.activeBreadcrumbs)(sections, pathname);
|
|
96
|
+
if (!breadcrumbItems.length && headerText) {
|
|
97
|
+
breadcrumbItems = [{
|
|
98
|
+
label: headerText
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
// Append any render-time leaf crumb(s) the section supplied via
|
|
102
|
+
// headerData.sectionName (deduped against the current trailing label).
|
|
103
|
+
breadcrumbItems = (0, _breadcrumbsSelect.appendSectionName)(breadcrumbItems, sectionName);
|
|
104
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Page, {
|
|
105
|
+
breadcrumbItems: breadcrumbItems,
|
|
106
|
+
subTitle: subTitle,
|
|
107
|
+
actions: actions,
|
|
108
|
+
tabbedNavigation: tabbedNavigation,
|
|
109
|
+
children: children
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
69
113
|
/**
|
|
70
114
|
* @typedef {Object} WizardProps
|
|
71
115
|
* @property {string} headerText The header text.
|
|
@@ -87,23 +131,23 @@ var ResetHeaderData = function ResetHeaderData() {
|
|
|
87
131
|
* @param {WizardProps} props
|
|
88
132
|
* @return {JSX.Element} Wizard component
|
|
89
133
|
*/
|
|
90
|
-
var Wizard = function Wizard(
|
|
91
|
-
var
|
|
92
|
-
sections =
|
|
93
|
-
headerText =
|
|
94
|
-
apiSlug =
|
|
95
|
-
|
|
96
|
-
sharedProps =
|
|
97
|
-
subHeaderText =
|
|
98
|
-
hasSimpleFooter =
|
|
99
|
-
className =
|
|
100
|
-
renderAboveSections =
|
|
101
|
-
|
|
102
|
-
requiredPlugins =
|
|
103
|
-
|
|
104
|
-
isInitialFetchTriggered =
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
var Wizard = function Wizard(_ref2, ref) {
|
|
135
|
+
var _ref2$sections = _ref2.sections,
|
|
136
|
+
sections = _ref2$sections === void 0 ? [] : _ref2$sections,
|
|
137
|
+
headerText = _ref2.headerText,
|
|
138
|
+
apiSlug = _ref2.apiSlug,
|
|
139
|
+
_ref2$sharedProps = _ref2.sharedProps,
|
|
140
|
+
sharedProps = _ref2$sharedProps === void 0 ? {} : _ref2$sharedProps,
|
|
141
|
+
subHeaderText = _ref2.subHeaderText,
|
|
142
|
+
hasSimpleFooter = _ref2.hasSimpleFooter,
|
|
143
|
+
className = _ref2.className,
|
|
144
|
+
renderAboveSections = _ref2.renderAboveSections,
|
|
145
|
+
_ref2$requiredPlugins = _ref2.requiredPlugins,
|
|
146
|
+
requiredPlugins = _ref2$requiredPlugins === void 0 ? [] : _ref2$requiredPlugins,
|
|
147
|
+
_ref2$isInitialFetchT = _ref2.isInitialFetchTriggered,
|
|
148
|
+
isInitialFetchTriggered = _ref2$isInitialFetchT === void 0 ? true : _ref2$isInitialFetchT,
|
|
149
|
+
_ref2$hideHeader = _ref2.hideHeader,
|
|
150
|
+
hideHeader = _ref2$hideHeader === void 0 ? false : _ref2$hideHeader;
|
|
107
151
|
var isLoading = (0, _data.useSelect)(function (select) {
|
|
108
152
|
return select(_store.WIZARD_STORE_NAMESPACE).isLoading();
|
|
109
153
|
});
|
|
@@ -151,8 +195,8 @@ var Wizard = function Wizard(_ref, ref) {
|
|
|
151
195
|
render: function render() {
|
|
152
196
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.PluginInstaller, {
|
|
153
197
|
plugins: requiredPlugins,
|
|
154
|
-
onStatus: function onStatus(
|
|
155
|
-
var complete =
|
|
198
|
+
onStatus: function onStatus(_ref3) {
|
|
199
|
+
var complete = _ref3.complete;
|
|
156
200
|
return setPluginRequirementsSatisfied(complete);
|
|
157
201
|
}
|
|
158
202
|
});
|
|
@@ -163,137 +207,114 @@ var Wizard = function Wizard(_ref, ref) {
|
|
|
163
207
|
// When plugins are required but not yet satisfied, `displayedSections` is replaced with
|
|
164
208
|
// the PluginInstaller. Use it for routing so the installer actually mounts and runs.
|
|
165
209
|
var routedSections = pluginRequirementsSatisfied ? sections : displayedSections;
|
|
166
|
-
var
|
|
210
|
+
var tabbedNavigation = displayedSections.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.TabbedNavigation, {
|
|
211
|
+
items: displayedSections,
|
|
212
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_WizardError["default"], {})
|
|
213
|
+
});
|
|
214
|
+
var content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
215
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.HandoffMessage, {}), sections.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(ResetHeaderData, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
216
|
+
className: "newspack-wizard__main",
|
|
217
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Switch, {
|
|
218
|
+
children: [routedSections.map(function (section, index) {
|
|
219
|
+
var _section$exact;
|
|
220
|
+
var SectionComponent = section.render;
|
|
221
|
+
var sectionProps = section.props || {};
|
|
222
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Route, {
|
|
223
|
+
exact: (_section$exact = section.exact) !== null && _section$exact !== void 0 ? _section$exact : false,
|
|
224
|
+
path: section.path,
|
|
225
|
+
render: function render(routerProps) {
|
|
226
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
227
|
+
className: (0, _classnames["default"])('newspack-wizard__content', className, {
|
|
228
|
+
'newspack-wizard__content--full-width': section.fullWidth
|
|
229
|
+
}),
|
|
230
|
+
children: ['function' === typeof renderAboveSections ? renderAboveSections() : null, (sectionTitle || section.title) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.SectionHeader, {
|
|
231
|
+
className: "newspack-wizard__section-header",
|
|
232
|
+
backNav: backNav || section.backNav,
|
|
233
|
+
title: sectionTitle || section.title,
|
|
234
|
+
description: sectionDescription || section.description,
|
|
235
|
+
badges: badges || section.badges,
|
|
236
|
+
menu: sectionMenu || section.menu,
|
|
237
|
+
primaryAction: sectionPrimaryAction || section.primaryAction,
|
|
238
|
+
secondaryAction: sectionSecondaryAction || section.secondaryAction,
|
|
239
|
+
heading: 2,
|
|
240
|
+
noMargin: true
|
|
241
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(SectionComponent, _objectSpread(_objectSpread(_objectSpread({}, routerProps), sectionProps), sharedProps))]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}, index);
|
|
245
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Redirect, {
|
|
246
|
+
to: displayedSections[0].path
|
|
247
|
+
})]
|
|
248
|
+
})
|
|
249
|
+
})]
|
|
250
|
+
});
|
|
251
|
+
var headerActions = (actions === null || actions === void 0 ? void 0 : actions.length) > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
252
|
+
children: [mainActions.map(function (action, index) {
|
|
253
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
|
|
254
|
+
className: "newspack-wizard__actions__main",
|
|
255
|
+
href: action.href,
|
|
256
|
+
icon: resolveIcon(action.icon),
|
|
257
|
+
variant: action.type,
|
|
258
|
+
onClick: action.action,
|
|
259
|
+
disabled: action.disabled || false,
|
|
260
|
+
isDestructive: action.destructive || false,
|
|
261
|
+
children: action.label
|
|
262
|
+
}, index);
|
|
263
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
264
|
+
className: (moreActions === null || moreActions === void 0 ? void 0 : moreActions.length) === 0 ? 'newspack-wizard__actions__more--primary-only' : '',
|
|
265
|
+
icon: _icons.moreVertical,
|
|
266
|
+
label: (0, _i18n.__)('More', 'newspack-plugin'),
|
|
267
|
+
popoverProps: {
|
|
268
|
+
className: 'newspack-wizard__actions__more'
|
|
269
|
+
},
|
|
270
|
+
children: function children() {
|
|
271
|
+
return (
|
|
272
|
+
// Split actions into groups whenever an action opts in via `separator: true`.
|
|
273
|
+
// Consecutive MenuGroups render the WordPress-standard divider between them.
|
|
274
|
+
actions.reduce(function (groups, action) {
|
|
275
|
+
if (action.separator || groups.length === 0) {
|
|
276
|
+
groups.push([]);
|
|
277
|
+
}
|
|
278
|
+
groups[groups.length - 1].push(action);
|
|
279
|
+
return groups;
|
|
280
|
+
}, []).map(function (group, groupIndex) {
|
|
281
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuGroup, {
|
|
282
|
+
children: group.map(function (action, index) {
|
|
283
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
|
|
284
|
+
className: action.type === 'primary' || action.type === 'secondary' ? 'newspack-wizard__actions__more__main' : 'newspack-wizard__actions__more__more',
|
|
285
|
+
icon: action.icon,
|
|
286
|
+
href: action.href,
|
|
287
|
+
onClick: action.action,
|
|
288
|
+
disabled: action.disabled || false,
|
|
289
|
+
isDestructive: action.destructive || false,
|
|
290
|
+
children: action.label
|
|
291
|
+
}, index);
|
|
292
|
+
})
|
|
293
|
+
}, groupIndex);
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
})]
|
|
298
|
+
}) : undefined;
|
|
167
299
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
168
300
|
ref: ref,
|
|
169
301
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
170
302
|
className: (0, _classnames["default"])(isLoading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded', {
|
|
171
|
-
'newspack-wizard__is-loading-quiet': isQuietLoading
|
|
172
|
-
'newspack-wizard__fixed-header': fixedHeader
|
|
303
|
+
'newspack-wizard__is-loading-quiet': isQuietLoading
|
|
173
304
|
}),
|
|
174
305
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(HashRouter, {
|
|
175
306
|
hashType: "slash",
|
|
176
307
|
children: [newspack_aux_data.is_debug_mode && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
|
|
177
308
|
debugMode: true
|
|
178
|
-
}), /*#__PURE__*/(0, _jsxRuntime.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
label: (0, _i18n.__)('Return to Dashboard', 'newspack-plugin'),
|
|
188
|
-
showTooltip: true,
|
|
189
|
-
icon: _icons.category,
|
|
190
|
-
iconSize: 36,
|
|
191
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewspackIcon, {
|
|
192
|
-
size: 36
|
|
193
|
-
})
|
|
194
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_.NewspackIcon, {
|
|
195
|
-
size: 36
|
|
196
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
197
|
-
children: [headerText && /*#__PURE__*/(0, _jsxRuntime.jsxs)("h2", {
|
|
198
|
-
className: "newspack-wizard__header__title",
|
|
199
|
-
children: [headerText, sectionName && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
200
|
-
className: "newspack-wizard__header__section",
|
|
201
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
202
|
-
className: "newspack-wizard__header__section__separator",
|
|
203
|
-
children: " / "
|
|
204
|
-
}), " ", sectionName]
|
|
205
|
-
})]
|
|
206
|
-
}), subHeaderText && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
207
|
-
children: subHeaderText
|
|
208
|
-
})]
|
|
209
|
-
})]
|
|
210
|
-
})
|
|
211
|
-
}), (actions === null || actions === void 0 ? void 0 : actions.length) > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
212
|
-
className: "newspack-wizard__header__actions",
|
|
213
|
-
children: [mainActions.map(function (action, index) {
|
|
214
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
|
|
215
|
-
className: "newspack-wizard__header__actions__main",
|
|
216
|
-
href: action.href,
|
|
217
|
-
icon: resolveIcon(action.icon),
|
|
218
|
-
variant: action.type,
|
|
219
|
-
onClick: action.action,
|
|
220
|
-
disabled: action.disabled || false,
|
|
221
|
-
isDestructive: action.destructive || false,
|
|
222
|
-
children: action.label
|
|
223
|
-
}, index);
|
|
224
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
225
|
-
className: (moreActions === null || moreActions === void 0 ? void 0 : moreActions.length) === 0 ? 'newspack-wizard__header__actions__more--primary-only' : '',
|
|
226
|
-
icon: _icons.moreVertical,
|
|
227
|
-
label: (0, _i18n.__)('More', 'newspack-plugin'),
|
|
228
|
-
popoverProps: {
|
|
229
|
-
className: 'newspack-wizard__header__actions__more'
|
|
230
|
-
},
|
|
231
|
-
children: function children() {
|
|
232
|
-
return (
|
|
233
|
-
// Split actions into groups whenever an action opts in via `separator: true`.
|
|
234
|
-
// Consecutive MenuGroups render the WordPress-standard divider between them.
|
|
235
|
-
actions.reduce(function (groups, action) {
|
|
236
|
-
if (action.separator || groups.length === 0) {
|
|
237
|
-
groups.push([]);
|
|
238
|
-
}
|
|
239
|
-
groups[groups.length - 1].push(action);
|
|
240
|
-
return groups;
|
|
241
|
-
}, []).map(function (group, groupIndex) {
|
|
242
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuGroup, {
|
|
243
|
-
children: group.map(function (action, index) {
|
|
244
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
|
|
245
|
-
className: action.type === 'primary' || action.type === 'secondary' ? 'newspack-wizard__header__actions__more__main' : 'newspack-wizard__header__actions__more__more',
|
|
246
|
-
icon: action.icon,
|
|
247
|
-
href: action.href,
|
|
248
|
-
onClick: action.action,
|
|
249
|
-
disabled: action.disabled || false,
|
|
250
|
-
isDestructive: action.destructive || false,
|
|
251
|
-
children: action.label
|
|
252
|
-
}, index);
|
|
253
|
-
})
|
|
254
|
-
}, groupIndex);
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
})]
|
|
259
|
-
})]
|
|
260
|
-
}), displayedSections.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.TabbedNavigation, {
|
|
261
|
-
items: displayedSections,
|
|
262
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_WizardError["default"], {})
|
|
263
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.HandoffMessage, {}), sections.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(ResetHeaderData, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
264
|
-
className: "newspack-wizard__main",
|
|
265
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Switch, {
|
|
266
|
-
children: [routedSections.map(function (section, index) {
|
|
267
|
-
var _section$exact;
|
|
268
|
-
var SectionComponent = section.render;
|
|
269
|
-
var sectionProps = section.props || {};
|
|
270
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Route, {
|
|
271
|
-
exact: (_section$exact = section.exact) !== null && _section$exact !== void 0 ? _section$exact : false,
|
|
272
|
-
path: section.path,
|
|
273
|
-
render: function render(routerProps) {
|
|
274
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
275
|
-
className: (0, _classnames["default"])('newspack-wizard__content', className, {
|
|
276
|
-
'newspack-wizard__content--full-width': section.fullWidth
|
|
277
|
-
}),
|
|
278
|
-
children: ['function' === typeof renderAboveSections ? renderAboveSections() : null, (sectionTitle || section.title) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.SectionHeader, {
|
|
279
|
-
className: "newspack-wizard__section-header",
|
|
280
|
-
backNav: backNav || section.backNav,
|
|
281
|
-
title: sectionTitle || section.title,
|
|
282
|
-
description: sectionDescription || section.description,
|
|
283
|
-
badges: badges || section.badges,
|
|
284
|
-
menu: sectionMenu || section.menu,
|
|
285
|
-
primaryAction: sectionPrimaryAction || section.primaryAction,
|
|
286
|
-
secondaryAction: sectionSecondaryAction || section.secondaryAction,
|
|
287
|
-
heading: 1,
|
|
288
|
-
noMargin: true
|
|
289
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(SectionComponent, _objectSpread(_objectSpread(_objectSpread({}, routerProps), sectionProps), sharedProps))]
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}, index);
|
|
293
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Redirect, {
|
|
294
|
-
to: displayedSections[0].path
|
|
295
|
-
})]
|
|
296
|
-
})
|
|
309
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(WizardHeaderRegion, {
|
|
310
|
+
hideHeader: hideHeader,
|
|
311
|
+
headerText: headerText,
|
|
312
|
+
sections: routedSections,
|
|
313
|
+
sectionName: sectionName,
|
|
314
|
+
subTitle: subHeaderText,
|
|
315
|
+
actions: headerActions,
|
|
316
|
+
tabbedNavigation: tabbedNavigation,
|
|
317
|
+
children: content
|
|
297
318
|
})]
|
|
298
319
|
}), (notices === null || notices === void 0 ? void 0 : notices.length) > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
299
320
|
className: "newspack-wizard__snackbar-list",
|