newspack-components 4.1.0 → 4.3.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/colors/colors.module.scss +1 -1
- package/dist/cjs/action-card/index.js +21 -12
- package/dist/cjs/action-card/style.scss +32 -14
- package/dist/cjs/autocomplete-tokenfield/index.js +2 -2
- package/dist/cjs/autocomplete-with-latest-posts/index.js +289 -0
- package/dist/cjs/autocomplete-with-latest-posts/style.scss +150 -0
- package/dist/cjs/badge/index.js +32 -0
- package/dist/cjs/badge/style.scss +36 -0
- package/dist/cjs/button/index.js +2 -0
- package/dist/cjs/card/core-card.js +141 -0
- package/dist/cjs/card/index.js +33 -0
- package/dist/cjs/card/style-core.scss +227 -0
- package/dist/cjs/card/style.scss +2 -2
- package/dist/cjs/card-settings-group/index.js +49 -0
- package/dist/cjs/card-settings-group/style.scss +33 -0
- package/dist/cjs/card-sortable-list/index.js +390 -0
- package/dist/cjs/card-sortable-list/style.scss +48 -0
- package/dist/cjs/confirm-dialog/index.js +59 -0
- package/dist/cjs/divider/index.js +42 -0
- package/dist/cjs/divider/style.scss +51 -0
- package/dist/cjs/form-token-field/style.scss +0 -5
- package/dist/cjs/grid/index.js +2 -1
- package/dist/cjs/grid/style.scss +63 -9
- package/dist/cjs/index.js +42 -0
- package/dist/cjs/modal/index.js +11 -4
- package/dist/cjs/modal/style.scss +43 -13
- package/dist/cjs/newspack-icon/style.scss +5 -3
- package/dist/cjs/popover/style.scss +1 -1
- package/dist/cjs/section-header/index.js +76 -17
- package/dist/cjs/section-header/style.scss +109 -4
- package/dist/cjs/style.scss +2 -0
- package/dist/cjs/waiting/index.js +3 -1
- package/dist/cjs/waiting/style.scss +4 -0
- package/dist/cjs/web-preview/index.js +98 -39
- package/dist/cjs/web-preview/style.scss +20 -53
- package/dist/cjs/with-wizard/index.js +1 -1
- package/dist/cjs/with-wizard/style.scss +24 -6
- package/dist/cjs/with-wizard-screen/style.scss +39 -10
- package/dist/cjs/wizard/components/WizardSnackbar.js +70 -0
- package/dist/cjs/wizard/components/style.scss +48 -0
- package/dist/cjs/wizard/index.js +97 -16
- package/dist/cjs/wizard/store/index.js +46 -0
- package/dist/esm/action-card/index.js +21 -12
- package/dist/esm/action-card/style.scss +32 -14
- package/dist/esm/autocomplete-tokenfield/index.js +2 -2
- package/dist/esm/autocomplete-with-latest-posts/index.js +281 -0
- package/dist/esm/autocomplete-with-latest-posts/style.scss +150 -0
- package/dist/esm/badge/index.js +24 -0
- package/dist/esm/badge/style.scss +36 -0
- package/dist/esm/button/index.js +2 -0
- package/dist/esm/card/core-card.js +133 -0
- package/dist/esm/card/index.js +33 -0
- package/dist/esm/card/style-core.scss +227 -0
- package/dist/esm/card/style.scss +2 -2
- package/dist/esm/card-settings-group/index.js +42 -0
- package/dist/esm/card-settings-group/style.scss +33 -0
- package/dist/esm/card-sortable-list/index.js +381 -0
- package/dist/esm/card-sortable-list/style.scss +48 -0
- package/dist/esm/confirm-dialog/index.js +49 -0
- package/dist/esm/divider/index.js +34 -0
- package/dist/esm/divider/style.scss +51 -0
- package/dist/esm/form-token-field/style.scss +0 -5
- package/dist/esm/grid/index.js +2 -1
- package/dist/esm/grid/style.scss +63 -9
- package/dist/esm/index.js +6 -0
- package/dist/esm/modal/index.js +11 -4
- package/dist/esm/modal/style.scss +43 -13
- package/dist/esm/newspack-icon/style.scss +5 -3
- package/dist/esm/popover/style.scss +1 -1
- package/dist/esm/section-header/index.js +75 -18
- package/dist/esm/section-header/style.scss +109 -4
- package/dist/esm/style.scss +2 -0
- package/dist/esm/waiting/index.js +3 -1
- package/dist/esm/waiting/style.scss +4 -0
- package/dist/esm/web-preview/index.js +101 -42
- package/dist/esm/web-preview/style.scss +20 -53
- package/dist/esm/with-wizard/index.js +1 -1
- package/dist/esm/with-wizard/style.scss +24 -6
- package/dist/esm/with-wizard-screen/style.scss +39 -10
- package/dist/esm/wizard/components/WizardSnackbar.js +64 -0
- package/dist/esm/wizard/components/style.scss +48 -0
- package/dist/esm/wizard/index.js +101 -20
- package/dist/esm/wizard/store/index.js +46 -0
- package/package.json +5 -6
- package/shared/author-context.js +26 -0
- package/shared/hooks/use-coauthors.js +220 -0
- package/shared/hooks/use-coauthors.test.js +624 -0
- package/shared/hooks/use-custom-byline.js +47 -0
- package/shared/hooks/use-custom-byline.test.js +133 -0
- package/shared/scss/_mixins.scss +46 -0
- package/src/action-card/action-card.d.ts +7 -3
- package/src/action-card/index.js +24 -11
- package/src/action-card/style.scss +32 -14
- package/src/autocomplete-tokenfield/index.js +2 -2
- package/src/autocomplete-with-latest-posts/index.js +290 -0
- package/src/autocomplete-with-latest-posts/style.scss +150 -0
- package/src/badge/index.tsx +24 -0
- package/src/badge/style.scss +36 -0
- package/src/button/index.tsx +3 -2
- package/src/card/core-card.js +147 -0
- package/src/card/index.js +39 -1
- package/src/card/style-core.scss +227 -0
- package/src/card/style.scss +2 -2
- package/src/card-settings-group/README.md +43 -0
- package/src/card-settings-group/index.tsx +53 -0
- package/src/card-settings-group/style.scss +33 -0
- package/src/card-sortable-list/README.md +51 -0
- package/src/card-sortable-list/index.tsx +412 -0
- package/src/card-sortable-list/style.scss +48 -0
- package/src/confirm-dialog/index.tsx +64 -0
- package/src/divider/README.md +25 -0
- package/src/divider/index.js +31 -0
- package/src/divider/style.scss +51 -0
- package/src/form-token-field/style.scss +0 -5
- package/src/grid/index.tsx +2 -1
- package/src/grid/style.scss +63 -9
- package/src/index.js +6 -0
- package/src/modal/index.js +12 -3
- package/src/modal/style.scss +43 -13
- package/src/newspack-icon/style.scss +5 -3
- package/src/popover/style.scss +1 -1
- package/src/section-header/index.js +72 -13
- package/src/section-header/style.scss +109 -4
- package/src/style.scss +2 -0
- package/src/waiting/index.js +2 -1
- package/src/waiting/style.scss +4 -0
- package/src/web-preview/index.js +90 -35
- package/src/web-preview/style.scss +20 -53
- package/src/with-wizard/index.js +1 -1
- package/src/with-wizard/style.scss +24 -6
- package/src/with-wizard-screen/style.scss +39 -10
- package/src/wizard/components/WizardSnackbar.js +58 -0
- package/src/wizard/components/style.scss +48 -0
- package/src/wizard/index.js +108 -14
- package/src/wizard/store/index.js +26 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ = require("../");
|
|
8
|
+
require("./style.scss");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
/**
|
|
11
|
+
* Card - Settings group component.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const CardSettingsGroup = ({
|
|
19
|
+
actionType = 'chevron',
|
|
20
|
+
children,
|
|
21
|
+
icon = null,
|
|
22
|
+
title = '',
|
|
23
|
+
description = '',
|
|
24
|
+
isActive = false,
|
|
25
|
+
onEnable = () => {}
|
|
26
|
+
}) => {
|
|
27
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Card, {
|
|
28
|
+
className: "newspack-card--core--settings-group",
|
|
29
|
+
actionType: actionType,
|
|
30
|
+
isSmall: true,
|
|
31
|
+
__experimentalCoreCard: true,
|
|
32
|
+
__experimentalCoreProps: {
|
|
33
|
+
header: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
34
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
35
|
+
children: title
|
|
36
|
+
}), description && /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
37
|
+
children: description
|
|
38
|
+
})]
|
|
39
|
+
}),
|
|
40
|
+
onHeaderClick: onEnable,
|
|
41
|
+
icon,
|
|
42
|
+
iconBackgroundColor: true,
|
|
43
|
+
isActive,
|
|
44
|
+
title
|
|
45
|
+
},
|
|
46
|
+
children: isActive && children
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var _default = exports.default = CardSettingsGroup;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.newspack-card--core--settings-group {
|
|
2
|
+
.components-card__body {
|
|
3
|
+
> .newspack-notice {
|
|
4
|
+
margin: 16px 0;
|
|
5
|
+
}
|
|
6
|
+
> .components-base-control {
|
|
7
|
+
&:first-child {
|
|
8
|
+
margin-top: 0;
|
|
9
|
+
}
|
|
10
|
+
+ .components-base-control,
|
|
11
|
+
+ .newspack-form-token-field {
|
|
12
|
+
margin-top: 16px;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** ToggleControl switch should appear after the label. */
|
|
17
|
+
> .components-toggle-control {
|
|
18
|
+
.components-h-stack {
|
|
19
|
+
.components-form-toggle {
|
|
20
|
+
order: 2;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
.components-toggle-control__help {
|
|
24
|
+
margin-inline-start: auto;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
.newspack-grid:last-child,
|
|
28
|
+
.components-base-control:last-child,
|
|
29
|
+
p:last-child {
|
|
30
|
+
margin-bottom: 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _ = require("../");
|
|
11
|
+
require("./style.scss");
|
|
12
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
/**
|
|
15
|
+
* Card - Sortable list component.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* WordPress dependencies.
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Internal dependencies
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* External dependencies
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const DROP_ANIMATION_DURATION = 400; // ms — must match $drop-duration in style.scss
|
|
32
|
+
const BUTTON_MOVE_DURATION = 200; // ms — must match $shift-duration in style.scss
|
|
33
|
+
|
|
34
|
+
const CardSortableList = ({
|
|
35
|
+
disabled = false,
|
|
36
|
+
items = [],
|
|
37
|
+
onDragCallback = () => {}
|
|
38
|
+
}) => {
|
|
39
|
+
const [sortedItems, setSortedItems] = (0, _element.useState)(items);
|
|
40
|
+
const [draggingIndex, setDraggingIndex] = (0, _element.useState)(null);
|
|
41
|
+
const [hoverIndex, setHoverIndex] = (0, _element.useState)(null);
|
|
42
|
+
const [droppedIndex, setDroppedIndex] = (0, _element.useState)(null);
|
|
43
|
+
const [measurements, setMeasurements] = (0, _element.useState)(null);
|
|
44
|
+
const listRef = (0, _element.useRef)(null);
|
|
45
|
+
const itemRefs = (0, _element.useRef)([]);
|
|
46
|
+
const dropAnimationTimer = (0, _element.useRef)(null);
|
|
47
|
+
const buttonMoveTimer = (0, _element.useRef)(null);
|
|
48
|
+
const buttonFlipRef = (0, _element.useRef)(null);
|
|
49
|
+
const [buttonMoveId, setButtonMoveId] = (0, _element.useState)(0);
|
|
50
|
+
const documentDragOverRef = (0, _element.useRef)(null);
|
|
51
|
+
|
|
52
|
+
// Keep sortedItems in sync when the items prop changes externally (e.g. after a save).
|
|
53
|
+
(0, _element.useEffect)(() => {
|
|
54
|
+
setSortedItems(items);
|
|
55
|
+
}, [items]);
|
|
56
|
+
|
|
57
|
+
// Clean up any pending animation timer on unmount.
|
|
58
|
+
(0, _element.useEffect)(() => {
|
|
59
|
+
return () => {
|
|
60
|
+
if (dropAnimationTimer.current) {
|
|
61
|
+
clearTimeout(dropAnimationTimer.current);
|
|
62
|
+
}
|
|
63
|
+
if (buttonMoveTimer.current) {
|
|
64
|
+
clearTimeout(buttonMoveTimer.current);
|
|
65
|
+
}
|
|
66
|
+
if (documentDragOverRef.current) {
|
|
67
|
+
document.removeEventListener('dragover', documentDragOverRef.current);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Handle a chevron-button move. Records item positions before the reorder so
|
|
74
|
+
* the FLIP animation can play after React commits the new DOM order.
|
|
75
|
+
*/
|
|
76
|
+
const handleButtonMove = (fromIndex, toIndex) => {
|
|
77
|
+
if (toIndex < 0 || toIndex >= sortedItems.length) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const fromEl = itemRefs.current[fromIndex];
|
|
81
|
+
const toEl = itemRefs.current[toIndex];
|
|
82
|
+
if (!fromEl || !toEl) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const stride = Math.abs(toEl.getBoundingClientRect().top - fromEl.getBoundingClientRect().top);
|
|
86
|
+
const direction = toIndex > fromIndex ? 1 : -1;
|
|
87
|
+
buttonFlipRef.current = {
|
|
88
|
+
fromIndex,
|
|
89
|
+
toIndex,
|
|
90
|
+
stride,
|
|
91
|
+
direction
|
|
92
|
+
};
|
|
93
|
+
const reordered = [...sortedItems];
|
|
94
|
+
const [moved] = reordered.splice(fromIndex, 1);
|
|
95
|
+
reordered.splice(toIndex, 0, moved);
|
|
96
|
+
setSortedItems(reordered);
|
|
97
|
+
setButtonMoveId(id => id + 1);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* FLIP Invert+Play step: runs synchronously after React commits the reordered
|
|
102
|
+
* DOM. Animate each swapped item from its previous position to its new one
|
|
103
|
+
* using inline CSS transitions (no CSS classes, to avoid creating a new
|
|
104
|
+
* containing block that would break position:fixed on the Draggable clone).
|
|
105
|
+
*/
|
|
106
|
+
(0, _element.useLayoutEffect)(() => {
|
|
107
|
+
const flipData = buttonFlipRef.current;
|
|
108
|
+
if (!flipData) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
buttonFlipRef.current = null;
|
|
112
|
+
const {
|
|
113
|
+
fromIndex,
|
|
114
|
+
toIndex,
|
|
115
|
+
stride,
|
|
116
|
+
direction
|
|
117
|
+
} = flipData;
|
|
118
|
+
const startAnimation = (el, startY) => {
|
|
119
|
+
if (!el) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// Snap to the starting position with no transition.
|
|
123
|
+
el.style.transition = 'none';
|
|
124
|
+
el.style.transform = `translateY(${startY}px)`;
|
|
125
|
+
// Force a reflow so the browser registers the starting position
|
|
126
|
+
// before we switch to the animated transition.
|
|
127
|
+
el.getBoundingClientRect();
|
|
128
|
+
// Animate from startY back to 0 (its new natural position).
|
|
129
|
+
el.style.transition = `transform ${BUTTON_MOVE_DURATION}ms ease-out`;
|
|
130
|
+
el.style.transform = '';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Moved item is now at toIndex: animate it in from its old position.
|
|
134
|
+
startAnimation(itemRefs.current[toIndex], -direction * stride);
|
|
135
|
+
// Displaced item is now at fromIndex: animate it in from its old position.
|
|
136
|
+
startAnimation(itemRefs.current[fromIndex], direction * stride);
|
|
137
|
+
if (buttonMoveTimer.current) {
|
|
138
|
+
clearTimeout(buttonMoveTimer.current);
|
|
139
|
+
}
|
|
140
|
+
buttonMoveTimer.current = setTimeout(() => {
|
|
141
|
+
// Clear inline animation styles before calling the external callback so
|
|
142
|
+
// the subsequent React re-render doesn't fight a live animation.
|
|
143
|
+
[fromIndex, toIndex].forEach(i => {
|
|
144
|
+
const el = itemRefs.current[i];
|
|
145
|
+
if (el) {
|
|
146
|
+
el.style.transition = '';
|
|
147
|
+
el.style.transform = '';
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Move focus to the matching chevron button on the card at toIndex.
|
|
152
|
+
// Focus before onDragCallback so a parent rerender can't steal focus.
|
|
153
|
+
const targetEl = itemRefs.current[toIndex];
|
|
154
|
+
if (targetEl) {
|
|
155
|
+
const moveButtons = targetEl.querySelectorAll('.newspack-card--core__header__draggable-controls__move-buttons button');
|
|
156
|
+
// direction > 0 = moved down → prefer the down button (index 1).
|
|
157
|
+
// direction < 0 = moved up → prefer the up button (index 0).
|
|
158
|
+
const preferred = direction > 0 ? moveButtons[1] : moveButtons[0];
|
|
159
|
+
const fallback = direction > 0 ? moveButtons[0] : moveButtons[1];
|
|
160
|
+
if (preferred && !preferred.disabled) {
|
|
161
|
+
preferred.focus();
|
|
162
|
+
} else if (fallback && !fallback.disabled) {
|
|
163
|
+
fallback.focus();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
onDragCallback(fromIndex, toIndex);
|
|
167
|
+
buttonMoveTimer.current = null;
|
|
168
|
+
}, BUTTON_MOVE_DURATION);
|
|
169
|
+
}, [buttonMoveId]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
170
|
+
|
|
171
|
+
const handleDragStart = index => {
|
|
172
|
+
// Cancel any in-progress button-move animation so no item wrapper keeps
|
|
173
|
+
// an inline transform. A transformed ancestor breaks position:fixed on
|
|
174
|
+
// the Draggable clone (CSS spec: fixed positioning is relative to the
|
|
175
|
+
// nearest ancestor with a transform/filter/perspective).
|
|
176
|
+
if (buttonMoveTimer.current) {
|
|
177
|
+
clearTimeout(buttonMoveTimer.current);
|
|
178
|
+
buttonMoveTimer.current = null;
|
|
179
|
+
itemRefs.current.forEach(el => {
|
|
180
|
+
if (el) {
|
|
181
|
+
el.style.transition = '';
|
|
182
|
+
el.style.transform = '';
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const listEl = listRef.current;
|
|
187
|
+
if (listEl) {
|
|
188
|
+
var _rects$index$height;
|
|
189
|
+
const itemEls = itemRefs.current;
|
|
190
|
+
const rects = itemEls.map(el => el?.getBoundingClientRect());
|
|
191
|
+
|
|
192
|
+
// Stride = item height + gap to next item (difference between consecutive tops).
|
|
193
|
+
const itemStrides = rects.map((rect, i) => {
|
|
194
|
+
if (!rect) {
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
const nextRect = rects[i + 1];
|
|
198
|
+
return nextRect ? nextRect.top - rect.top : rect.height;
|
|
199
|
+
});
|
|
200
|
+
setMeasurements({
|
|
201
|
+
lockedHeight: listEl.getBoundingClientRect().height,
|
|
202
|
+
sourceHeight: (_rects$index$height = rects[index]?.height) !== null && _rects$index$height !== void 0 ? _rects$index$height : 0,
|
|
203
|
+
itemStrides,
|
|
204
|
+
itemTops: rects.map(rect => {
|
|
205
|
+
var _rect$top;
|
|
206
|
+
return (_rect$top = rect?.top) !== null && _rect$top !== void 0 ? _rect$top : 0;
|
|
207
|
+
})
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// Make the entire document a valid drop target so the browser skips
|
|
211
|
+
// its snap-back animation when the cursor is released outside the list.
|
|
212
|
+
const preventSnapback = e => e.preventDefault();
|
|
213
|
+
document.addEventListener('dragover', preventSnapback);
|
|
214
|
+
documentDragOverRef.current = preventSnapback;
|
|
215
|
+
setDraggingIndex(index);
|
|
216
|
+
setDroppedIndex(null);
|
|
217
|
+
};
|
|
218
|
+
const clearDragState = () => {
|
|
219
|
+
if (documentDragOverRef.current) {
|
|
220
|
+
document.removeEventListener('dragover', documentDragOverRef.current);
|
|
221
|
+
documentDragOverRef.current = null;
|
|
222
|
+
}
|
|
223
|
+
setDraggingIndex(null);
|
|
224
|
+
setHoverIndex(null);
|
|
225
|
+
setMeasurements(null);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Determine the drop target index from cursor coordinates and the item
|
|
230
|
+
* top positions snapshotted at drag start. Mirrors the midpoint logic
|
|
231
|
+
* previously used in getDropIndex but works without a live event target.
|
|
232
|
+
*/
|
|
233
|
+
const getDropIndexFromCursor = (clientY, m, sourceIndex) => {
|
|
234
|
+
const {
|
|
235
|
+
itemTops,
|
|
236
|
+
itemStrides,
|
|
237
|
+
sourceHeight
|
|
238
|
+
} = m;
|
|
239
|
+
for (let i = 0; i < itemTops.length; i++) {
|
|
240
|
+
const movingDown = sourceIndex > i;
|
|
241
|
+
const midpoint = itemTops[i] + (movingDown ? itemStrides[i] : itemStrides[i] - sourceHeight);
|
|
242
|
+
if (clientY < midpoint) {
|
|
243
|
+
return i;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return itemTops.length; // below all items
|
|
247
|
+
};
|
|
248
|
+
const handleDragEnd = event => {
|
|
249
|
+
// Take a local copy of measurements before clearDragState nulls it.
|
|
250
|
+
const m = measurements;
|
|
251
|
+
const sourceIndex = draggingIndex;
|
|
252
|
+
clearDragState();
|
|
253
|
+
if (m === null || sourceIndex === null) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const dropIndex = getDropIndexFromCursor(event.clientY, m, sourceIndex);
|
|
257
|
+
|
|
258
|
+
// Compute the destination index in the post-removal array.
|
|
259
|
+
// After splicing out the dragged item, indices above it shift down by one.
|
|
260
|
+
const insertIndex = dropIndex > sourceIndex ? dropIndex - 1 : dropIndex;
|
|
261
|
+
if (insertIndex === sourceIndex) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const reordered = [...sortedItems];
|
|
265
|
+
const [moved] = reordered.splice(sourceIndex, 1);
|
|
266
|
+
reordered.splice(insertIndex, 0, moved);
|
|
267
|
+
|
|
268
|
+
// First render: show items in their new order with no animation.
|
|
269
|
+
// The dragging CSS classes are already cleared by clearDragState() above,
|
|
270
|
+
// so no transitions will fire on this paint.
|
|
271
|
+
setSortedItems(reordered);
|
|
272
|
+
|
|
273
|
+
// Next frame: trigger the drop animation on the newly-positioned item,
|
|
274
|
+
// then call onDragCallback after the animation completes.
|
|
275
|
+
requestAnimationFrame(() => {
|
|
276
|
+
setDroppedIndex(insertIndex);
|
|
277
|
+
dropAnimationTimer.current = setTimeout(() => {
|
|
278
|
+
setDroppedIndex(null);
|
|
279
|
+
onDragCallback(sourceIndex, insertIndex);
|
|
280
|
+
}, DROP_ANIMATION_DURATION);
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
const handleDragOver = (event, index) => {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
if (!measurements) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
289
|
+
const midpoint = rect.top + rect.height / 2;
|
|
290
|
+
setHoverIndex(event.clientY < midpoint ? index : index + 1);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Compute the translateY for a non-source item at `index` given the current
|
|
295
|
+
* draggingIndex and hoverIndex, so that items visually shift to show the gap
|
|
296
|
+
* while the container's layout height stays fixed.
|
|
297
|
+
*
|
|
298
|
+
* The source item has been visually hidden but still occupies its layout slot.
|
|
299
|
+
* Items between the source and the hover position need to slide by the source
|
|
300
|
+
* item's stride (height + gap) to either fill the vacated source slot or make
|
|
301
|
+
* room for the incoming gap at the hover position.
|
|
302
|
+
*/
|
|
303
|
+
const getTranslateY = index => {
|
|
304
|
+
var _itemStrides$dragging;
|
|
305
|
+
if (draggingIndex === null || hoverIndex === null || !measurements) {
|
|
306
|
+
return 0;
|
|
307
|
+
}
|
|
308
|
+
if (index === draggingIndex) {
|
|
309
|
+
return 0;
|
|
310
|
+
}
|
|
311
|
+
const {
|
|
312
|
+
itemStrides,
|
|
313
|
+
sourceHeight
|
|
314
|
+
} = measurements;
|
|
315
|
+
const sourceStride = (_itemStrides$dragging = itemStrides[draggingIndex]) !== null && _itemStrides$dragging !== void 0 ? _itemStrides$dragging : sourceHeight;
|
|
316
|
+
if (hoverIndex > draggingIndex) {
|
|
317
|
+
// Dragging downward: items strictly between source and hover position slide up.
|
|
318
|
+
if (index > draggingIndex && index < hoverIndex) {
|
|
319
|
+
return -sourceStride;
|
|
320
|
+
}
|
|
321
|
+
} else if (index >= hoverIndex && index < draggingIndex) {
|
|
322
|
+
// Dragging upward: items between hover position and source slide down.
|
|
323
|
+
return sourceStride;
|
|
324
|
+
}
|
|
325
|
+
return 0;
|
|
326
|
+
};
|
|
327
|
+
const isDragging = draggingIndex !== null;
|
|
328
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalVStack, {
|
|
329
|
+
ref: listRef,
|
|
330
|
+
className: (0, _classnames.default)('newspack-card--core--sortable-list', disabled && 'newspack-card--core--sortable-list__is-disabled', isDragging && 'newspack-card--core--sortable-list__is-dragging'),
|
|
331
|
+
style: measurements ? {
|
|
332
|
+
height: measurements.lockedHeight
|
|
333
|
+
} : undefined,
|
|
334
|
+
spacing: 4,
|
|
335
|
+
children: sortedItems.map((item, index) => {
|
|
336
|
+
const translateY = getTranslateY(index);
|
|
337
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Disabled, {
|
|
338
|
+
isDisabled: disabled,
|
|
339
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
340
|
+
ref: el => {
|
|
341
|
+
itemRefs.current[index] = el;
|
|
342
|
+
},
|
|
343
|
+
className: (0, _classnames.default)('newspack-card--core--sortable-list__item', {
|
|
344
|
+
'is-source': draggingIndex === index,
|
|
345
|
+
'is-dropped': droppedIndex === index
|
|
346
|
+
}),
|
|
347
|
+
style: translateY ? {
|
|
348
|
+
transform: `translateY(${translateY}px)`
|
|
349
|
+
} : {
|
|
350
|
+
transition: !isDragging ? 'none' : undefined
|
|
351
|
+
},
|
|
352
|
+
id: `draggable-card-${index}`,
|
|
353
|
+
onDragOver: e => handleDragOver(e, index),
|
|
354
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Draggable, {
|
|
355
|
+
transferData: {},
|
|
356
|
+
cloneClassname: "newspack-card--core--sortable-list__item__clone",
|
|
357
|
+
elementId: `draggable-card-${index}`,
|
|
358
|
+
onDragStart: () => handleDragStart(index),
|
|
359
|
+
onDragEnd: handleDragEnd,
|
|
360
|
+
appendToOwnerDocument: true,
|
|
361
|
+
children: ({
|
|
362
|
+
onDraggableStart,
|
|
363
|
+
onDraggableEnd
|
|
364
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Card, {
|
|
365
|
+
isSmall: true,
|
|
366
|
+
draggable: true,
|
|
367
|
+
onDragStart: onDraggableStart,
|
|
368
|
+
onDragEnd: onDraggableEnd,
|
|
369
|
+
__experimentalCoreCard: true,
|
|
370
|
+
__experimentalCoreProps: {
|
|
371
|
+
header: /*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
|
|
372
|
+
children: [item.title, /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Badge, {
|
|
373
|
+
level: item.badgeLevel,
|
|
374
|
+
text: item.badgeText
|
|
375
|
+
})]
|
|
376
|
+
}),
|
|
377
|
+
isDraggable: true,
|
|
378
|
+
isFirstTarget: index === 0,
|
|
379
|
+
isLastTarget: index === sortedItems.length - 1,
|
|
380
|
+
dragIndex: index,
|
|
381
|
+
onDragCallback: handleButtonMove
|
|
382
|
+
}
|
|
383
|
+
})
|
|
384
|
+
})
|
|
385
|
+
})
|
|
386
|
+
}, item.id);
|
|
387
|
+
})
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
var _default = exports.default = CardSortableList;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
$collapse-duration: 200ms;
|
|
2
|
+
$shift-duration: 150ms;
|
|
3
|
+
$drop-duration: 400ms; /* must match DROP_ANIMATION_DURATION in index.tsx */
|
|
4
|
+
|
|
5
|
+
.newspack-card--core--sortable-list {
|
|
6
|
+
&__item {
|
|
7
|
+
cursor: grab;
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Animate items sliding to fill/make space around the dragged item.
|
|
11
|
+
*/
|
|
12
|
+
transition: transform $shift-duration ease;
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Collapse the source item's content — the wrapper stays in layout as the
|
|
16
|
+
* anchor point, and the container height is locked via inline style in JS.
|
|
17
|
+
*/
|
|
18
|
+
&.is-source {
|
|
19
|
+
cursor: grabbing;
|
|
20
|
+
opacity: 0;
|
|
21
|
+
transition: opacity $collapse-duration ease;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Drop landing animation: brief fade-in and scale on the newly placed item.
|
|
26
|
+
*/
|
|
27
|
+
&.is-dropped {
|
|
28
|
+
animation: newspack-sortable-drop $drop-duration ease forwards;
|
|
29
|
+
opacity: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@keyframes newspack-sortable-drop {
|
|
36
|
+
0% {
|
|
37
|
+
opacity: 0;
|
|
38
|
+
transform: scale(0.98);
|
|
39
|
+
}
|
|
40
|
+
60% {
|
|
41
|
+
opacity: 1;
|
|
42
|
+
transform: scale(1.01);
|
|
43
|
+
}
|
|
44
|
+
100% {
|
|
45
|
+
opacity: 1;
|
|
46
|
+
transform: scale(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
var _components = require("@wordpress/components");
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
/**
|
|
13
|
+
* Modal
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* External dependencies.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* See both https://wordpress.github.io/gutenberg/?path=/docs/components-confirmdialog--docs and
|
|
28
|
+
* https://wordpress.github.io/gutenberg/?path=/docs/components-modal--docs for all supported props.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const sizeClassMap = {
|
|
32
|
+
small: 'newspack-modal--size-small',
|
|
33
|
+
medium: 'newspack-modal--size-medium',
|
|
34
|
+
large: 'newspack-modal--size-large',
|
|
35
|
+
'x-large': 'newspack-modal--size-x-large',
|
|
36
|
+
full: 'newspack-modal--size-full'
|
|
37
|
+
};
|
|
38
|
+
function ConfirmDialog({
|
|
39
|
+
className,
|
|
40
|
+
size = 'small',
|
|
41
|
+
hideTitle,
|
|
42
|
+
isDestructive,
|
|
43
|
+
onConfirm,
|
|
44
|
+
onCancel,
|
|
45
|
+
...otherProps
|
|
46
|
+
}, ref) {
|
|
47
|
+
const classes = (0, _classnames.default)('newspack-modal', sizeClassMap[size], hideTitle && 'newspack-modal--hide-title',
|
|
48
|
+
// Note: also hides the X close button.
|
|
49
|
+
isDestructive && 'newspack-modal--destructive', className);
|
|
50
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalConfirmDialog, {
|
|
51
|
+
className: classes,
|
|
52
|
+
...otherProps,
|
|
53
|
+
ref: ref,
|
|
54
|
+
onConfirm: onConfirm,
|
|
55
|
+
onCancel: onCancel,
|
|
56
|
+
__experimentalHideHeader: false
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
var _default = exports.default = (0, _element.forwardRef)(ConfirmDialog);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
require("./style.scss");
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
/**
|
|
12
|
+
* Divider
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* External dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const Divider = ({
|
|
24
|
+
alignment = 'none',
|
|
25
|
+
className = undefined,
|
|
26
|
+
marginBottom = 64,
|
|
27
|
+
marginTop = 64,
|
|
28
|
+
variant = 'default',
|
|
29
|
+
...otherProps
|
|
30
|
+
}) => {
|
|
31
|
+
const classes = (0, _classnames.default)('newspack-divider', className, alignment && `newspack-divider--alignment-${alignment}`, variant && `newspack-divider--variant-${variant}`);
|
|
32
|
+
const style = {
|
|
33
|
+
'--divider-margin-bottom': typeof marginBottom === 'number' ? `${marginBottom}px` : marginBottom,
|
|
34
|
+
'--divider-margin-top': typeof marginTop === 'number' ? `${marginTop}px` : marginTop
|
|
35
|
+
};
|
|
36
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("hr", {
|
|
37
|
+
className: classes,
|
|
38
|
+
style: style,
|
|
39
|
+
...otherProps
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var _default = exports.default = Divider;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Divider
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@use "~@wordpress/base-styles/colors" as wp-colors;
|
|
6
|
+
|
|
7
|
+
.newspack-divider {
|
|
8
|
+
background: transparent;
|
|
9
|
+
border: 0;
|
|
10
|
+
display: block;
|
|
11
|
+
height: 1px;
|
|
12
|
+
margin-bottom: min(32px, var(--divider-margin-bottom, 64px));
|
|
13
|
+
margin-left: 0;
|
|
14
|
+
margin-right: 0;
|
|
15
|
+
margin-top: min(32px, var(--divider-margin-top, 64px));
|
|
16
|
+
padding: 0;
|
|
17
|
+
|
|
18
|
+
@media screen and (min-width: 783px) {
|
|
19
|
+
margin-bottom: var(--divider-margin-bottom, 64px);
|
|
20
|
+
margin-top: var(--divider-margin-top, 64px);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Alignment
|
|
24
|
+
|
|
25
|
+
&--alignment-full-width {
|
|
26
|
+
margin-left: calc(-50vw + 50%);
|
|
27
|
+
width: 100vw;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&--alignment-none {
|
|
31
|
+
width: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Variant
|
|
35
|
+
|
|
36
|
+
&--variant-default {
|
|
37
|
+
background-color: wp-colors.$gray-300;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&--variant-primary {
|
|
41
|
+
background-color: var(--wp-admin-theme-color);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&--variant-secondary {
|
|
45
|
+
background-color: wp-colors.$gray-900;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&--variant-tertiary {
|
|
49
|
+
background-color: wp-colors.$gray-100;
|
|
50
|
+
}
|
|
51
|
+
}
|