@startlibs/components 1.0.3 → 1.1.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/lib/BasicBulletList.mjs +9 -0
- package/lib/BasicBulletList.mjs.map +1 -0
- package/lib/Button.mjs +95 -0
- package/lib/Button.mjs.map +1 -0
- package/lib/ContextMenu.mjs +452 -0
- package/lib/ContextMenu.mjs.map +1 -0
- package/lib/Dialog.mjs +232 -0
- package/lib/Dialog.mjs.map +1 -0
- package/lib/Draggable.mjs +880 -0
- package/lib/Draggable.mjs.map +1 -0
- package/lib/ErrorBoundary.mjs +108 -0
- package/lib/ErrorBoundary.mjs.map +1 -0
- package/lib/FillLastLineResizer.mjs +238 -0
- package/lib/FillLastLineResizer.mjs.map +1 -0
- package/lib/Flip.mjs +604 -0
- package/lib/Flip.mjs.map +1 -0
- package/lib/FlipList.mjs +186 -0
- package/lib/FlipList.mjs.map +1 -0
- package/lib/FormatDate.mjs +25 -0
- package/lib/FormatDate.mjs.map +1 -0
- package/lib/Icon.mjs +50 -0
- package/lib/Icon.mjs.map +1 -0
- package/lib/Image.mjs +41 -0
- package/lib/Image.mjs.map +1 -0
- package/lib/Link.mjs +116 -0
- package/lib/Link.mjs.map +1 -0
- package/lib/Loading.mjs +10 -0
- package/lib/Loading.mjs.map +1 -0
- package/lib/LoadingDiv.mjs +83 -0
- package/lib/LoadingDiv.mjs.map +1 -0
- package/lib/Notifications.mjs +63 -0
- package/lib/Notifications.mjs.map +1 -0
- package/lib/PageLoader.mjs +42 -0
- package/lib/PageLoader.mjs.map +1 -0
- package/lib/PersistentNotifications.mjs +130 -0
- package/lib/PersistentNotifications.mjs.map +1 -0
- package/lib/Popup.mjs +49 -0
- package/lib/Popup.mjs.map +1 -0
- package/lib/SplitColumnsContainer.mjs +43 -0
- package/lib/SplitColumnsContainer.mjs.map +1 -0
- package/lib/SwitchDiv.mjs +61 -0
- package/lib/SwitchDiv.mjs.map +1 -0
- package/lib/TextButton.mjs +41 -0
- package/lib/TextButton.mjs.map +1 -0
- package/lib/ToastNotifications.mjs +215 -0
- package/lib/ToastNotifications.mjs.map +1 -0
- package/lib/Tooltip.mjs +160 -0
- package/lib/Tooltip.mjs.map +1 -0
- package/lib/TransitionDiv.mjs +56 -0
- package/lib/TransitionDiv.mjs.map +1 -0
- package/lib/WarningDialog.mjs +84 -0
- package/lib/WarningDialog.mjs.map +1 -0
- package/lib/alt/buttons/OnClickLoadingButton.mjs +36 -0
- package/lib/alt/buttons/OnClickLoadingButton.mjs.map +1 -0
- package/lib/alt/dialogs/DialogWithImageHeader.mjs +14 -0
- package/lib/alt/dialogs/DialogWithImageHeader.mjs.map +1 -0
- package/lib/alt/dialogs/DialogWithSidebar.mjs +106 -0
- package/lib/alt/dialogs/DialogWithSidebar.mjs.map +1 -0
- package/lib/alt/dialogs/MobileBubbleDialog.mjs +49 -0
- package/lib/alt/dialogs/MobileBubbleDialog.mjs.map +1 -0
- package/lib/containers/DialogContainer.mjs +413 -0
- package/lib/containers/DialogContainer.mjs.map +1 -0
- package/lib/containers/Reposition.mjs +35 -0
- package/lib/containers/Reposition.mjs.map +1 -0
- package/lib/containers/usePositioning.mjs +294 -0
- package/lib/containers/usePositioning.mjs.map +1 -0
- package/lib/index.cjs +5000 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.mjs +37 -0
- package/lib/index.mjs.map +1 -0
- package/lib/useDialogWithToggle.mjs +18 -0
- package/lib/useDialogWithToggle.mjs.map +1 -0
- package/lib/willUseIsSticky.mjs +123 -0
- package/lib/willUseIsSticky.mjs.map +1 -0
- package/package.json +44 -29
- package/src/BasicBulletList.jsx +21 -0
- package/src/Button.jsx +288 -0
- package/src/ContextMenu.jsx +621 -0
- package/src/Dialog.jsx +413 -0
- package/src/Draggable.jsx +801 -0
- package/src/ErrorBoundary.jsx +75 -0
- package/src/FillLastLineResizer.jsx +226 -0
- package/src/Flip.jsx +560 -0
- package/src/FlipList.jsx +136 -0
- package/src/FormatDate.jsx +9 -0
- package/src/Icon.jsx +49 -0
- package/src/Image.jsx +23 -0
- package/src/Link.jsx +68 -0
- package/src/Loading.jsx +29 -0
- package/src/LoadingDiv.jsx +75 -0
- package/src/Notifications.jsx +89 -0
- package/src/PageLoader.jsx +48 -0
- package/src/PersistentNotifications.jsx +182 -0
- package/src/Popup.jsx +49 -0
- package/src/SplitColumnsContainer.jsx +63 -0
- package/src/SwitchDiv.jsx +30 -0
- package/src/TextButton.jsx +34 -0
- package/src/ToastNotifications.jsx +298 -0
- package/src/Tooltip.jsx +158 -0
- package/src/TransitionDiv.jsx +34 -0
- package/src/WarningDialog.jsx +70 -0
- package/src/alt/buttons/OnClickLoadingButton.jsx +16 -0
- package/src/alt/dialogs/DialogWithImageHeader.jsx +42 -0
- package/src/alt/dialogs/DialogWithSidebar.jsx +135 -0
- package/src/alt/dialogs/MobileBubbleDialog.jsx +56 -0
- package/src/containers/DialogContainer.jsx +423 -0
- package/src/containers/Reposition.jsx +24 -0
- package/src/containers/usePositioning.jsx +305 -0
- package/src/index.js +35 -0
- package/src/useDialogWithToggle.jsx +12 -0
- package/src/willUseIsSticky.jsx +113 -0
- package/.babelrc +0 -27
- package/lib/index.js +0 -5196
- package/rollup.config.js +0 -52
package/lib/Flip.mjs
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _uniqueId from 'lodash/fp/uniqueId';
|
|
3
|
+
import _max from 'lodash/fp/max';
|
|
4
|
+
import _identity from 'lodash/fp/identity';
|
|
5
|
+
import React, { useLayoutEffect } from 'react';
|
|
6
|
+
import { animationTiming, oneWayAnimation, ifUndefined, callIfFunction, _s } from '@startlibs/utils';
|
|
7
|
+
import { useHiddenFill, willUseSharedCallback, useConstant } from '@startlibs/core';
|
|
8
|
+
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
const getMargins = domNode => {
|
|
12
|
+
const {
|
|
13
|
+
marginTop,
|
|
14
|
+
marginLeft,
|
|
15
|
+
marginBottom,
|
|
16
|
+
marginRight,
|
|
17
|
+
paddingTop
|
|
18
|
+
} = window.getComputedStyle(domNode);
|
|
19
|
+
return {
|
|
20
|
+
marginTop,
|
|
21
|
+
marginLeft,
|
|
22
|
+
marginBottom,
|
|
23
|
+
marginRight,
|
|
24
|
+
paddingTop
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const getParentProperties = parentNode => {
|
|
28
|
+
if (!parentNode) return {};
|
|
29
|
+
const {
|
|
30
|
+
marginTop,
|
|
31
|
+
marginLeft,
|
|
32
|
+
marginBottom,
|
|
33
|
+
marginRight,
|
|
34
|
+
paddingBottom,
|
|
35
|
+
paddingTop
|
|
36
|
+
} = window.getComputedStyle(parentNode);
|
|
37
|
+
return {
|
|
38
|
+
parentStyle: {
|
|
39
|
+
marginTop,
|
|
40
|
+
marginLeft,
|
|
41
|
+
marginBottom,
|
|
42
|
+
marginRight,
|
|
43
|
+
paddingBottom,
|
|
44
|
+
paddingTop
|
|
45
|
+
},
|
|
46
|
+
parentNode
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const toPosition = function (domNode) {
|
|
50
|
+
let parentRect = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : domNode.offsetParent ? domNode.offsetParent.getBoundingClientRect() : {
|
|
51
|
+
top: 0,
|
|
52
|
+
left: 0
|
|
53
|
+
};
|
|
54
|
+
let {
|
|
55
|
+
allowFixed,
|
|
56
|
+
finalPosition,
|
|
57
|
+
withMargins
|
|
58
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
59
|
+
if (!allowFixed && domNode.style.position === 'fixed' || domNode.style.display === 'none') return;
|
|
60
|
+
const {
|
|
61
|
+
left,
|
|
62
|
+
top,
|
|
63
|
+
height,
|
|
64
|
+
width
|
|
65
|
+
} = domNode.getBoundingClientRect();
|
|
66
|
+
const margins = withMargins ? getMargins(domNode) : {};
|
|
67
|
+
|
|
68
|
+
// const {offsetLeft, offsetTop} = domNode
|
|
69
|
+
return _objectSpread(_objectSpread({
|
|
70
|
+
domNode,
|
|
71
|
+
nextSibling: domNode.nextSibling,
|
|
72
|
+
top: finalPosition ? domNode.offsetTop : top - parentRect.top,
|
|
73
|
+
left: finalPosition ? domNode.offsetLeft : left - parentRect.left,
|
|
74
|
+
height,
|
|
75
|
+
width
|
|
76
|
+
}, getParentProperties(domNode.parentNode)), margins);
|
|
77
|
+
};
|
|
78
|
+
const sumWithPx = function () {
|
|
79
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
80
|
+
args[_key] = arguments[_key];
|
|
81
|
+
}
|
|
82
|
+
return args.map(parseFloat).reduce((a, b) => a + b, 0) + 'px';
|
|
83
|
+
};
|
|
84
|
+
const childMAp = (childs, fn) => {
|
|
85
|
+
for (var c of childs) {
|
|
86
|
+
fn(c);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const defaultAnimationMaker = animationTiming('0.25s ease-out');
|
|
90
|
+
const defaultEnterAnimation = oneWayAnimation('opacity: 0;', 'opacity: 1;');
|
|
91
|
+
const defaultSwitchAnimation = oneWayAnimation("opacity: 1;", "opacity: 0;", "opacity: 0;");
|
|
92
|
+
const SHORT_ANIMATIONS = {
|
|
93
|
+
fadeIn: defaultEnterAnimation
|
|
94
|
+
};
|
|
95
|
+
const applyDefault = k => SHORT_ANIMATIONS[k] || k;
|
|
96
|
+
const formatAnimation = (animationName /* array or string or fn with array or string*/, animationTimer /* string or fn */, reverse) => {
|
|
97
|
+
const animationMaker = typeof animationTimer === 'string' ? k => k + ' ' + animationTimer : animationTimer;
|
|
98
|
+
const animationNameExecuted = typeof animationName === 'function' ? animationName() : animationName;
|
|
99
|
+
const keyframes = [].concat(typeof animationNameExecuted === 'string' ? animationNameExecuted.split(',') : animationNameExecuted);
|
|
100
|
+
const applyReverse = k => reverse ? k + ' reverse' : k;
|
|
101
|
+
return keyframes.map(k => applyReverse(k.trim().indexOf(' ') < 0 ? animationMaker(k) : applyDefault(k))).join(', ');
|
|
102
|
+
};
|
|
103
|
+
const cloneWrapper = element => {
|
|
104
|
+
const cloned = element.cloneNode(true);
|
|
105
|
+
const tempWrapper = document.createElement('div');
|
|
106
|
+
[].slice.call(cloned.childNodes).forEach(c => tempWrapper.append(c));
|
|
107
|
+
const {
|
|
108
|
+
display,
|
|
109
|
+
width,
|
|
110
|
+
height,
|
|
111
|
+
padding,
|
|
112
|
+
borderLeftWidth,
|
|
113
|
+
borderRightWidth,
|
|
114
|
+
borderBottomWidth,
|
|
115
|
+
borderTopWidth
|
|
116
|
+
} = window.getComputedStyle(element);
|
|
117
|
+
Object.assign(tempWrapper.style, {
|
|
118
|
+
display,
|
|
119
|
+
width: sumWithPx(width, '-' + borderLeftWidth, '-' + borderRightWidth),
|
|
120
|
+
height: sumWithPx(height, '-' + borderBottomWidth, '-' + borderTopWidth),
|
|
121
|
+
padding,
|
|
122
|
+
position: 'absolute',
|
|
123
|
+
top: 0,
|
|
124
|
+
left: 0
|
|
125
|
+
});
|
|
126
|
+
return tempWrapper;
|
|
127
|
+
};
|
|
128
|
+
const morphingEndEvents = new Map();
|
|
129
|
+
const morphTime = new Map();
|
|
130
|
+
const continueSwitchCallbacks = new Map();
|
|
131
|
+
const continueSwitchOnClone = oldWrapper => newWrapper => {
|
|
132
|
+
const prevOldClone = oldWrapper.querySelector('.JS-old-snap');
|
|
133
|
+
const prevNewClone = oldWrapper.querySelector('.JS-new-snap');
|
|
134
|
+
const oldClone = newWrapper.querySelector('.JS-old-snap');
|
|
135
|
+
const newClone = newWrapper.querySelector('.JS-new-snap');
|
|
136
|
+
oldClone.style.animationDelay = getDelays(prevOldClone, oldClone.style.animation);
|
|
137
|
+
newClone.style.animationDelay = getDelays(prevNewClone, newClone.style.animation);
|
|
138
|
+
morphTime.set(oldClone, morphTime.get(prevOldClone));
|
|
139
|
+
morphTime.set(newClone, morphTime.get(prevNewClone));
|
|
140
|
+
oldClone.addEventListener('animationend', oldClone.remove);
|
|
141
|
+
newClone.addEventListener('animationend', finishSwitchNew(newClone, newWrapper));
|
|
142
|
+
continueSwitchCallbacks.delete(oldWrapper);
|
|
143
|
+
continueSwitchCallbacks.set(newWrapper, continueSwitchOnClone(newWrapper));
|
|
144
|
+
};
|
|
145
|
+
const finishSwitchNew = (clone, wrapper) => () => {
|
|
146
|
+
clone.remove();
|
|
147
|
+
const newChildren = [].slice.call(wrapper.children);
|
|
148
|
+
childMAp(newChildren, c => {
|
|
149
|
+
if (c.dataset) {
|
|
150
|
+
// Guard against stale "0" from a prior uncompleted cycle: always restore
|
|
151
|
+
// to empty when prev is "0" since "0" is never a legitimate captured value.
|
|
152
|
+
const prev = c.dataset.prevOpacity;
|
|
153
|
+
c.style.opacity = prev && prev !== '0' ? prev : '';
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
// wrapper.style.willChange = ''
|
|
157
|
+
continueSwitchCallbacks.delete(wrapper);
|
|
158
|
+
};
|
|
159
|
+
const supportsEvent = "onanimationend" in HTMLElement.prototype;
|
|
160
|
+
const morph = (node, animation, callback) => {
|
|
161
|
+
if (!animation) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const [cachedAnimation, cachedCallback] = morphingEndEvents.get(node) || [];
|
|
165
|
+
const oldAnimation = cachedAnimation || node.style.animation;
|
|
166
|
+
morphTime.set(node, Date.now());
|
|
167
|
+
const didNotStartPromise = Promise.race([new Promise(res => node.addEventListener('animationstart', res)), new Promise((res, rej) => setTimeout(rej, supportsEvent ? 1000 : 200))]);
|
|
168
|
+
node.style.animation = animation;
|
|
169
|
+
if (!cachedCallback) {
|
|
170
|
+
const end = _ref => {
|
|
171
|
+
let {
|
|
172
|
+
target
|
|
173
|
+
} = _ref;
|
|
174
|
+
if (target !== node) return;
|
|
175
|
+
morphTime.delete(node);
|
|
176
|
+
morphingEndEvents.delete(node);
|
|
177
|
+
node.removeEventListener('animationend', end);
|
|
178
|
+
callback && callback();
|
|
179
|
+
node.style.animation = oldAnimation;
|
|
180
|
+
};
|
|
181
|
+
didNotStartPromise.catch(() => end({
|
|
182
|
+
target: node
|
|
183
|
+
}));
|
|
184
|
+
node.addEventListener('animationend', end);
|
|
185
|
+
morphingEndEvents.set(node, [oldAnimation, end]);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const hasClientRectChanged = (oldSnap, newSnap) => !['top', 'left', 'height', 'width'].every(_ => oldSnap[_] === newSnap[_]);
|
|
189
|
+
const getClientRectAnimation = function (oldSnap, newSnap) {
|
|
190
|
+
let {
|
|
191
|
+
skipTransform,
|
|
192
|
+
smallJumpFix
|
|
193
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
194
|
+
if (oldSnap && newSnap && hasClientRectChanged(oldSnap, newSnap)) {
|
|
195
|
+
var _oldSnap$parentStyle, _newSnap$parentStyle, _oldSnap$parentStyle2, _newSnap$parentStyle2;
|
|
196
|
+
const node = newSnap.domNode;
|
|
197
|
+
const {
|
|
198
|
+
offsetLeft,
|
|
199
|
+
offsetTop,
|
|
200
|
+
scrollHeight,
|
|
201
|
+
clientHeight,
|
|
202
|
+
scrollWidth,
|
|
203
|
+
clientWidth
|
|
204
|
+
} = node;
|
|
205
|
+
const scrollTop = node.parentNode && node.parentNode.scrollTop || 0;
|
|
206
|
+
const scrollLeft = node.parentNode && node.parentNode.scrollLeft || 0;
|
|
207
|
+
const left = oldSnap.left - offsetLeft + scrollLeft;
|
|
208
|
+
const top = oldSnap.top - offsetTop + scrollTop;
|
|
209
|
+
const deltaHeight = oldSnap.height - newSnap.height;
|
|
210
|
+
let heightFix = '';
|
|
211
|
+
let finalPadding = '';
|
|
212
|
+
if (deltaHeight > 0) {
|
|
213
|
+
const {
|
|
214
|
+
paddingBottom
|
|
215
|
+
} = window.getComputedStyle(node);
|
|
216
|
+
finalPadding = 'padding-bottom:' + paddingBottom + ';';
|
|
217
|
+
heightFix = "padding-bottom: ".concat(sumWithPx(deltaHeight, paddingBottom) + (smallJumpFix || 0), ";");
|
|
218
|
+
}
|
|
219
|
+
const overflowFix = scrollHeight > clientHeight || scrollWidth > clientWidth ? "overflow: hidden;" : "";
|
|
220
|
+
const transform = (left !== 0 || top !== 0) && !skipTransform ? "transform: translate(".concat(left, "px,").concat(top, "px);") : '';
|
|
221
|
+
const parentPaddingTopDelta = (parseInt((_oldSnap$parentStyle = oldSnap.parentStyle) === null || _oldSnap$parentStyle === void 0 ? void 0 : _oldSnap$parentStyle.paddingTop) || 0) - (parseInt((_newSnap$parentStyle = newSnap.parentStyle) === null || _newSnap$parentStyle === void 0 ? void 0 : _newSnap$parentStyle.paddingTop) || 0);
|
|
222
|
+
const parentPaddingBottomDelta = (parseInt((_oldSnap$parentStyle2 = oldSnap.parentStyle) === null || _oldSnap$parentStyle2 === void 0 ? void 0 : _oldSnap$parentStyle2.paddingBottom) || 0) - (parseInt((_newSnap$parentStyle2 = newSnap.parentStyle) === null || _newSnap$parentStyle2 === void 0 ? void 0 : _newSnap$parentStyle2.paddingBottom) || 0);
|
|
223
|
+
const oldMarginTop = (parseInt(oldSnap.marginTop) || 0) + parentPaddingTopDelta;
|
|
224
|
+
const oldMarginBottom = (parseInt(oldSnap.marginBottom) || 0) + parentPaddingBottomDelta;
|
|
225
|
+
const oldTransform = node.style.transform;
|
|
226
|
+
return [oneWayAnimation("\n ".concat(transform, "\n ").concat(heightFix, "\n ").concat(overflowFix, "\n margin-top: ").concat(oldMarginTop, "px;\n margin-bottom: ").concat(oldMarginBottom, "px;\n width: ").concat(oldSnap.width, "px;\n height: ").concat(Math.max(0, oldSnap.height + (smallJumpFix || 0)), "px;\n "), "\n ".concat(finalPadding, "\n ").concat(oldTransform ? "transform:".concat(oldTransform, ";") : '', "\n ").concat(overflowFix, "\n margin-top:").concat(parseInt(newSnap.marginTop) || 0, "px;\n margin-bottom:").concat(parseInt(newSnap.marginBottom) || 0, "px;\n width: ").concat(newSnap.width, "px;\n height: ").concat(Math.max(0, newSnap.height + (smallJumpFix || 0)), "px;\n "))];
|
|
227
|
+
} else {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const getClientRectAnimationForSwitch = function (oldSnap, newSnap) {
|
|
232
|
+
let {
|
|
233
|
+
skipTransform
|
|
234
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
235
|
+
if (hasClientRectChanged(oldSnap, newSnap)) {
|
|
236
|
+
var _node$parentNode, _node$parentNode2;
|
|
237
|
+
const node = newSnap.domNode;
|
|
238
|
+
const {
|
|
239
|
+
offsetLeft,
|
|
240
|
+
offsetTop,
|
|
241
|
+
scrollHeight,
|
|
242
|
+
clientHeight,
|
|
243
|
+
scrollWidth,
|
|
244
|
+
clientWidth
|
|
245
|
+
} = node;
|
|
246
|
+
const scrollTop = ((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.scrollTop) || 0;
|
|
247
|
+
const scrollLeft = ((_node$parentNode2 = node.parentNode) === null || _node$parentNode2 === void 0 ? void 0 : _node$parentNode2.scrollLeft) || 0;
|
|
248
|
+
|
|
249
|
+
// get margin-bottom
|
|
250
|
+
const prevBorder = node.style.border;
|
|
251
|
+
node.style.border = '1px solid transparent';
|
|
252
|
+
const borderHeight = node.clientHeight;
|
|
253
|
+
node.style.border = prevBorder;
|
|
254
|
+
|
|
255
|
+
// get negative margin top
|
|
256
|
+
const prevPadding = newSnap.paddingTop;
|
|
257
|
+
const nonPaddingFixTop = newSnap.clonedNode.getBoundingClientRect().top;
|
|
258
|
+
let topWithPaddingFix = nonPaddingFixTop;
|
|
259
|
+
if (!parseInt(prevPadding)) {
|
|
260
|
+
node.style.paddingTop = '1px';
|
|
261
|
+
topWithPaddingFix = newSnap.clonedNode.getBoundingClientRect().top;
|
|
262
|
+
node.style.paddingTop = '';
|
|
263
|
+
}
|
|
264
|
+
const newSnapNegativeTopMarginDelta = topWithPaddingFix - nonPaddingFixTop;
|
|
265
|
+
const newSnapBottomMarginDelta = clientHeight - borderHeight;
|
|
266
|
+
const left = oldSnap.left - offsetLeft + scrollLeft;
|
|
267
|
+
const top = oldSnap.top - offsetTop + scrollTop - newSnapNegativeTopMarginDelta;
|
|
268
|
+
const deltaHeight = oldSnap.height - newSnap.height;
|
|
269
|
+
let heightFix = '';
|
|
270
|
+
let finalPadding = '';
|
|
271
|
+
if (deltaHeight > 0) {
|
|
272
|
+
const {
|
|
273
|
+
paddingBottom
|
|
274
|
+
} = window.getComputedStyle(node);
|
|
275
|
+
finalPadding = 'padding-bottom:' + paddingBottom + ';';
|
|
276
|
+
heightFix = "padding-bottom: ".concat(sumWithPx(deltaHeight, paddingBottom), ";");
|
|
277
|
+
}
|
|
278
|
+
const overflowFix = scrollHeight > clientHeight || scrollWidth > clientWidth ? "overflow: hidden;" : "";
|
|
279
|
+
const transform = (left !== 0 || top !== 0) && !skipTransform ? "transform: translate(".concat(left, "px,").concat(top, "px);") : '';
|
|
280
|
+
const oldTransform = node.style.transform;
|
|
281
|
+
return [oneWayAnimation("\n ".concat(transform, "\n ").concat(heightFix, "\n ").concat(overflowFix, "\n width: ").concat(oldSnap.width, "px;\n height: ").concat(oldSnap.height, "px;\n "), "\n ".concat(finalPadding, "\n ").concat(oldTransform ? "transform:".concat(oldTransform, ";") : '', "\n ").concat(overflowFix, "\n width: ").concat(newSnap.width, "px;\n height: ").concat(newSnap.height - newSnapBottomMarginDelta, "px;\n "))];
|
|
282
|
+
} else {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const willPlaySwitch = (oldSnap, newSnap, _ref2) => {
|
|
287
|
+
let {
|
|
288
|
+
switchIn,
|
|
289
|
+
switchOut,
|
|
290
|
+
switchAnimation,
|
|
291
|
+
timing,
|
|
292
|
+
transformHeight = _identity
|
|
293
|
+
} = _ref2;
|
|
294
|
+
const realWrapper = newSnap.domNode;
|
|
295
|
+
const newChildren = [].slice.call(realWrapper.children);
|
|
296
|
+
// realWrapper.style.willChange = 'width,height,margin-top;'
|
|
297
|
+
if (realWrapper.firstChild) {
|
|
298
|
+
realWrapper.insertBefore(oldSnap.clonedNode, realWrapper.firstChild);
|
|
299
|
+
realWrapper.insertBefore(newSnap.clonedNode, realWrapper.firstChild);
|
|
300
|
+
} else {
|
|
301
|
+
realWrapper.append(oldSnap.clonedNode);
|
|
302
|
+
realWrapper.append(newSnap.clonedNode);
|
|
303
|
+
}
|
|
304
|
+
oldSnap.clonedNode.className = oldSnap.clonedNode.className + ' JS-old-snap';
|
|
305
|
+
newSnap.clonedNode.className = newSnap.clonedNode.className + ' JS-new-snap';
|
|
306
|
+
// newSnap.clonedNode.style.willChange = 'width,height,opacity'
|
|
307
|
+
// oldSnap.clonedNode.style.willChange = 'width,height,opacity'
|
|
308
|
+
const realWrapperRect = realWrapper.getBoundingClientRect();
|
|
309
|
+
const resizeToNew = oneWayAnimation("\n overflow: hidden;\n width: ".concat(oldSnap.width, "px;\n height: ").concat(oldSnap.height, "px;\n "), "\n overflow: hidden;\n width: ".concat(newSnap.clonedNode.style.width, ";\n height: ").concat(callIfFunction(transformHeight, newSnap.clonedNode.style.height, realWrapperRect), ";\n "));
|
|
310
|
+
childMAp(newChildren, c => {
|
|
311
|
+
if (c.dataset && !c.dataset.noFlip) {
|
|
312
|
+
// Don't capture "0" as prevOpacity — it's always a transient value from
|
|
313
|
+
// a prior uncompleted willPlaySwitch. Otherwise finishSwitchNew restores
|
|
314
|
+
// opacity to "0" permanently, leaving content invisible.
|
|
315
|
+
if (c.style.opacity && c.style.opacity !== '0') {
|
|
316
|
+
c.dataset.prevOpacity = c.style.opacity;
|
|
317
|
+
}
|
|
318
|
+
c.style.opacity = '0';
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
childMAp([].slice.call(oldSnap.clonedNode.children), c => {
|
|
322
|
+
if (c.dataset && c.dataset.noFlip) {
|
|
323
|
+
c.style.opacity = '0';
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
const resizeOld = oldSnap.width > newSnap.width || oldSnap.height > newSnap.height ? [resizeToNew] : [resizeToNew];
|
|
327
|
+
const resizeNew = oldSnap.width < newSnap.width || oldSnap.height < newSnap.height ? [resizeToNew] : [resizeToNew];
|
|
328
|
+
return () => {
|
|
329
|
+
morph(oldSnap.clonedNode, formatAnimation([].concat(switchOut || switchAnimation, resizeOld), timing), () => oldSnap.clonedNode.remove());
|
|
330
|
+
newSnap.clonedNode.style.opacity = '0';
|
|
331
|
+
continueSwitchCallbacks.set(realWrapper, continueSwitchOnClone(realWrapper));
|
|
332
|
+
morph(newSnap.clonedNode, formatAnimation([formatAnimation(switchIn || switchAnimation, timing, !switchIn)].concat(resizeNew), timing), finishSwitchNew(newSnap.clonedNode, realWrapper));
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
const getDelays = (el, animation) => {
|
|
336
|
+
const delayStr = morphTime.get(el) - Date.now() + 'ms';
|
|
337
|
+
return animation.split(',').map(_ => delayStr).join(',');
|
|
338
|
+
};
|
|
339
|
+
class Snapshoter extends React.Component {
|
|
340
|
+
getSnapshotBeforeUpdate(oldProps) {
|
|
341
|
+
if (oldProps.on !== this.props.on) {
|
|
342
|
+
console.log('on', 'UHUL');
|
|
343
|
+
} else if (oldProps.moveOn !== this.props.moveOn) {
|
|
344
|
+
console.log('moveOn', 'UHUL');
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
render() {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const useFlip = _ref3 => {
|
|
353
|
+
let {
|
|
354
|
+
on,
|
|
355
|
+
moveOn
|
|
356
|
+
} = _ref3;
|
|
357
|
+
useHiddenFill(/*#__PURE__*/React.createElement(Snapshoter, {
|
|
358
|
+
on: on,
|
|
359
|
+
moveOn: moveOn,
|
|
360
|
+
callback: console.log
|
|
361
|
+
}));
|
|
362
|
+
};
|
|
363
|
+
const getAnimationNames = animation => animation.split(',').map(_ => _.replace(/\s*(\S+).*/, '$1'));
|
|
364
|
+
const willUseFlip = () => {
|
|
365
|
+
let controlElement = null;
|
|
366
|
+
let morphEnabled = false;
|
|
367
|
+
const disableMorph = () => {
|
|
368
|
+
controlElement = null;
|
|
369
|
+
morphEnabled = false;
|
|
370
|
+
};
|
|
371
|
+
const [useRegisterEnter, enterChildrenCallback] = willUseSharedCallback(useLayoutEffect);
|
|
372
|
+
const [useRegisterLeave, leaveChildrenCallback] = willUseSharedCallback(useLayoutEffect);
|
|
373
|
+
const [useRegisterMorph, morphChildrenCallback, getSize] = willUseSharedCallback(useLayoutEffect);
|
|
374
|
+
const useEnterAnimation = function (ref) {
|
|
375
|
+
let onEnter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultEnterAnimation;
|
|
376
|
+
let {
|
|
377
|
+
onEnterEnd,
|
|
378
|
+
timing = defaultAnimationMaker,
|
|
379
|
+
enterEffect
|
|
380
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
381
|
+
useLayoutEffect(() => {
|
|
382
|
+
if (!morphEnabled && onEnter && ref.current) {
|
|
383
|
+
const el = ref.current;
|
|
384
|
+
const animation = formatAnimation(onEnter, timing);
|
|
385
|
+
const endEffect = callIfFunction(enterEffect, el);
|
|
386
|
+
morph(el, animation, () => {
|
|
387
|
+
callIfFunction(onEnterEnd);
|
|
388
|
+
callIfFunction(endEffect, el);
|
|
389
|
+
});
|
|
390
|
+
enterChildrenCallback(timing);
|
|
391
|
+
}
|
|
392
|
+
}, [onEnter]);
|
|
393
|
+
};
|
|
394
|
+
const useLeaveAnimation = function (ref) {
|
|
395
|
+
let onLeave = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultEnterAnimation;
|
|
396
|
+
let {
|
|
397
|
+
ref: removeRef,
|
|
398
|
+
leaveEffect,
|
|
399
|
+
timing = defaultAnimationMaker,
|
|
400
|
+
nestedFlip = false,
|
|
401
|
+
events = {},
|
|
402
|
+
reverse = true
|
|
403
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
404
|
+
useLayoutEffect(() => () => {
|
|
405
|
+
if (onLeave && ref.current) {
|
|
406
|
+
const el = ref.current;
|
|
407
|
+
const animation = formatAnimation(onLeave, timing, reverse);
|
|
408
|
+
// on leave animations require a clone, as the real node will be intantaneousy removed by react
|
|
409
|
+
leaveChildrenCallback(timing);
|
|
410
|
+
const isNested = callIfFunction(nestedFlip);
|
|
411
|
+
const clone = isNested ? el : el.cloneNode(true);
|
|
412
|
+
_s.each((callback, type) => clone.addEventListener(type, callback), events);
|
|
413
|
+
const endEffect = callIfFunction(leaveEffect, clone, el);
|
|
414
|
+
if (removeRef) {
|
|
415
|
+
removeRef.current = clone;
|
|
416
|
+
}
|
|
417
|
+
if (!isNested) {
|
|
418
|
+
el.parentNode.insertBefore(clone, el);
|
|
419
|
+
}
|
|
420
|
+
// sometimes the clone may need to trigger events (usual case: onmouseover to reopen the element)
|
|
421
|
+
|
|
422
|
+
// allow clone to be continued by another animation
|
|
423
|
+
controlElement = clone;
|
|
424
|
+
// the animation
|
|
425
|
+
const animate = () => {
|
|
426
|
+
morph(clone, animation, () => {
|
|
427
|
+
clone.remove();
|
|
428
|
+
disableMorph();
|
|
429
|
+
callIfFunction(endEffect, clone, el);
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// wait for current animation to end and then animate
|
|
434
|
+
if (clone.style.animation) {
|
|
435
|
+
const maxAnimationTime = _max((clone.style.animationDuration.split(",") || ["0.25s"]).map(s => parseFloat(s.trim() || "0.25") * (s.indexOf("m") > 0 ? 1 : 1000)));
|
|
436
|
+
const timeoutRef = {};
|
|
437
|
+
const animationEnd = e => {
|
|
438
|
+
clearTimeout(timeoutRef.current || -1);
|
|
439
|
+
clone.removeEventListener('animationend', animationEnd);
|
|
440
|
+
clone.style.animationDelay = '';
|
|
441
|
+
e === null || e === void 0 || e.stopImmediatePropagation();
|
|
442
|
+
setTimeout(animate, 1);
|
|
443
|
+
};
|
|
444
|
+
timeoutRef.current = setTimeout(animationEnd, maxAnimationTime);
|
|
445
|
+
clone.addEventListener('animationend', animationEnd);
|
|
446
|
+
clone.style.animationDelay = getDelays(el, clone.style.animation);
|
|
447
|
+
} else {
|
|
448
|
+
animate();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}, [onLeave]);
|
|
452
|
+
};
|
|
453
|
+
const useMorphAnimation = function (ref) {
|
|
454
|
+
let ready = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
455
|
+
let {
|
|
456
|
+
timing = defaultAnimationMaker
|
|
457
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
458
|
+
useLayoutEffect(() => {
|
|
459
|
+
if (ready && controlElement && ref.current) {
|
|
460
|
+
// const controlElement =getControlElement()
|
|
461
|
+
const el = ref.current;
|
|
462
|
+
const animation = oneWayAnimation("opacity:".concat(window.getComputedStyle(controlElement).opacity, ";"), "opacity: 1");
|
|
463
|
+
const oldSnap = _objectSpread(_objectSpread({}, toPosition(controlElement, undefined, {
|
|
464
|
+
allowFixed: true
|
|
465
|
+
})), {}, {
|
|
466
|
+
clonedNode: cloneWrapper(controlElement)
|
|
467
|
+
});
|
|
468
|
+
const newSnap = _objectSpread(_objectSpread({}, toPosition(el, undefined, {
|
|
469
|
+
allowFixed: true
|
|
470
|
+
})), {}, {
|
|
471
|
+
clonedNode: cloneWrapper(el)
|
|
472
|
+
});
|
|
473
|
+
const rectAnimation = getClientRectAnimation(oldSnap, newSnap);
|
|
474
|
+
morph(newSnap.domNode, formatAnimation(rectAnimation.concat(animation), timing), disableMorph);
|
|
475
|
+
morphChildrenCallback(executeAnimation => executeAnimation(timing));
|
|
476
|
+
if (rectAnimation.length) {
|
|
477
|
+
willPlaySwitch(oldSnap, newSnap, {
|
|
478
|
+
switchAnimation: defaultSwitchAnimation,
|
|
479
|
+
timing
|
|
480
|
+
})();
|
|
481
|
+
}
|
|
482
|
+
controlElement.remove();
|
|
483
|
+
disableMorph();
|
|
484
|
+
}
|
|
485
|
+
return () => {
|
|
486
|
+
morphEnabled = true;
|
|
487
|
+
// continue existing switch animation on the clone
|
|
488
|
+
if (continueSwitchCallbacks.has(ref.current)) {
|
|
489
|
+
continueSwitchCallbacks.get(ref.current)(controlElement);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
}, [ready]);
|
|
493
|
+
};
|
|
494
|
+
const useNestedEnterAnimation = function (ref, onEnter) {
|
|
495
|
+
let {
|
|
496
|
+
timing
|
|
497
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
498
|
+
useRegisterEnter(parentTiming => {
|
|
499
|
+
const el = ref.current;
|
|
500
|
+
const animation = formatAnimation(onEnter, timing || parentTiming);
|
|
501
|
+
morph(el, animation);
|
|
502
|
+
return getAnimationNames(animation);
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
const useNestLeaveAnimation = function (ref, onLeave) {
|
|
506
|
+
let {
|
|
507
|
+
timing,
|
|
508
|
+
events
|
|
509
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
510
|
+
useRegisterLeave(parentTiming => {
|
|
511
|
+
const el = ref.current;
|
|
512
|
+
const animation = formatAnimation(onLeave, timing || parentTiming);
|
|
513
|
+
morph(el, animation);
|
|
514
|
+
return getAnimationNames(animation);
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
const willUseNestedMorphAnimation = () => {
|
|
518
|
+
const morphId = _uniqueId('JS-');
|
|
519
|
+
return ref => {
|
|
520
|
+
useLayoutEffect(() => {
|
|
521
|
+
var _ref$current;
|
|
522
|
+
if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.dataset) {
|
|
523
|
+
ref.current.dataset.morphId = morphId;
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
const executeAnimation = useConstant(timing => {
|
|
527
|
+
const prev = controlElement.querySelector("[data-morph-id='".concat(morphId, "']"));
|
|
528
|
+
const next = ref.current;
|
|
529
|
+
if (next.dataset) {
|
|
530
|
+
next.dataset.noFlip = true;
|
|
531
|
+
}
|
|
532
|
+
next.style.opacity = '1';
|
|
533
|
+
const prevPos = prev.getBoundingClientRect();
|
|
534
|
+
const nextPos = next.getBoundingClientRect();
|
|
535
|
+
const originalTransform = next.style.transform || '';
|
|
536
|
+
const deltaX = Math.round(nextPos.left - prevPos.left);
|
|
537
|
+
const deltaY = Math.round(nextPos.top - prevPos.top);
|
|
538
|
+
const newLeft = deltaX > 0 ? -deltaX : -deltaX;
|
|
539
|
+
const animation = oneWayAnimation("\n transform: translate(".concat(newLeft, "px,").concat(deltaY, "px) ").concat(originalTransform, ";\n "), "\n transform: translate(0,0) ".concat(originalTransform, ";\n "));
|
|
540
|
+
morph(next, formatAnimation(animation, timing));
|
|
541
|
+
});
|
|
542
|
+
useRegisterMorph(executeAnimation);
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
return [[useEnterAnimation, useLeaveAnimation, useMorphAnimation], [useNestedEnterAnimation, useNestLeaveAnimation], willUseNestedMorphAnimation];
|
|
546
|
+
};
|
|
547
|
+
const willUseFlipSwitch = () => {
|
|
548
|
+
let oldSnap = null;
|
|
549
|
+
const getTempWrapper = function (parent) {
|
|
550
|
+
let positionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
551
|
+
const tempWrapper = cloneWrapper(parent);
|
|
552
|
+
return _objectSpread(_objectSpread({}, toPosition(parent, undefined, positionConfig)), {}, {
|
|
553
|
+
clonedNode: tempWrapper
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
return function (ref, onEnter, onLeave) {
|
|
557
|
+
let {
|
|
558
|
+
timing = defaultAnimationMaker,
|
|
559
|
+
switchAnimation = defaultSwitchAnimation,
|
|
560
|
+
effect
|
|
561
|
+
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
562
|
+
useLayoutEffect(() => {
|
|
563
|
+
if (oldSnap && ref.current) {
|
|
564
|
+
const newSnap = getTempWrapper(ref.current, {
|
|
565
|
+
withMargins: true
|
|
566
|
+
});
|
|
567
|
+
let switchToPlay = _identity;
|
|
568
|
+
if (oldSnap.clonedNode) {
|
|
569
|
+
switchToPlay = willPlaySwitch(oldSnap, newSnap, {
|
|
570
|
+
switchIn: callIfFunction(onEnter),
|
|
571
|
+
switchOut: callIfFunction(onLeave),
|
|
572
|
+
switchAnimation: callIfFunction(switchAnimation),
|
|
573
|
+
timing
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
const animation = getClientRectAnimationForSwitch(oldSnap, newSnap);
|
|
577
|
+
const endEffect = callIfFunction(effect, oldSnap.clonedNode, newSnap.clonedNode, ref.current);
|
|
578
|
+
switchToPlay();
|
|
579
|
+
morph(newSnap.domNode, formatAnimation(animation, timing), () => callIfFunction(endEffect, oldSnap.clonedNode, newSnap.clonedNode));
|
|
580
|
+
}
|
|
581
|
+
return () => {
|
|
582
|
+
oldSnap = getTempWrapper(ref.current, {
|
|
583
|
+
withMargins: true
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
}, []);
|
|
587
|
+
};
|
|
588
|
+
};
|
|
589
|
+
const flipHooks = willUseFlip();
|
|
590
|
+
const useFlipEnter = flipHooks[0][0];
|
|
591
|
+
const useFlipLeave = flipHooks[0][1];
|
|
592
|
+
const useFlipAnimation = function (ref, onEnterOrBoth) {
|
|
593
|
+
let onLeaveOrIgnore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
594
|
+
let config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
595
|
+
const onEnter = ifUndefined(onEnterOrBoth && onEnterOrBoth.onEnter, onEnterOrBoth);
|
|
596
|
+
const onLeave = ifUndefined(onEnterOrBoth && onEnterOrBoth.onLeave, onLeaveOrIgnore);
|
|
597
|
+
useFlipEnter(ref, onEnter, config);
|
|
598
|
+
useFlipLeave(ref, onLeave === true ? onEnter : onLeave, _objectSpread(_objectSpread({}, config), {}, {
|
|
599
|
+
reverse: onLeave === true
|
|
600
|
+
}));
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
export { defaultAnimationMaker, formatAnimation, getClientRectAnimation, morph, toPosition, useFlip, useFlipAnimation, useFlipEnter, useFlipLeave, willUseFlip, willUseFlipSwitch };
|
|
604
|
+
//# sourceMappingURL=Flip.mjs.map
|