@startlibs/components 1.1.4 → 1.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/lib/BasicBulletList.mjs +1 -1
  2. package/lib/BasicBulletList.mjs.map +1 -1
  3. package/lib/Button.mjs +3 -3
  4. package/lib/Button.mjs.map +1 -1
  5. package/lib/ContextMenu.mjs +22 -6
  6. package/lib/ContextMenu.mjs.map +1 -1
  7. package/lib/Dialog.mjs +60 -24
  8. package/lib/Dialog.mjs.map +1 -1
  9. package/lib/Icon.mjs +10 -4
  10. package/lib/Icon.mjs.map +1 -1
  11. package/lib/Loading.mjs +26 -3
  12. package/lib/Loading.mjs.map +1 -1
  13. package/lib/PageLoader.mjs +2 -2
  14. package/lib/PageLoader.mjs.map +1 -1
  15. package/lib/PersistentNotifications.mjs +1 -1
  16. package/lib/PersistentNotifications.mjs.map +1 -1
  17. package/lib/SplitColumnsContainer.mjs +77 -6
  18. package/lib/SplitColumnsContainer.mjs.map +1 -1
  19. package/lib/TextButton.mjs +1 -1
  20. package/lib/TextButton.mjs.map +1 -1
  21. package/lib/ToastNotifications.mjs +16 -14
  22. package/lib/ToastNotifications.mjs.map +1 -1
  23. package/lib/alt/dialogs/DialogWithImageHeader.mjs +1 -1
  24. package/lib/alt/dialogs/DialogWithImageHeader.mjs.map +1 -1
  25. package/lib/alt/dialogs/DialogWithSidebar.mjs +7 -3
  26. package/lib/alt/dialogs/DialogWithSidebar.mjs.map +1 -1
  27. package/lib/alt/dialogs/MobileBubbleDialog.mjs +1 -1
  28. package/lib/alt/dialogs/MobileBubbleDialog.mjs.map +1 -1
  29. package/lib/containers/DialogContainer.mjs +29 -10
  30. package/lib/containers/DialogContainer.mjs.map +1 -1
  31. package/lib/index.cjs +286 -93
  32. package/lib/index.cjs.map +1 -1
  33. package/lib/willUseIsSticky.mjs +23 -2
  34. package/lib/willUseIsSticky.mjs.map +1 -1
  35. package/lib-yak/BasicBulletList.mjs +27 -0
  36. package/lib-yak/BasicBulletList.mjs.map +1 -0
  37. package/lib-yak/Button.mjs +374 -0
  38. package/lib-yak/Button.mjs.map +1 -0
  39. package/lib-yak/ContextMenu.mjs +642 -0
  40. package/lib-yak/ContextMenu.mjs.map +1 -0
  41. package/lib-yak/Dialog.mjs +469 -0
  42. package/lib-yak/Dialog.mjs.map +1 -0
  43. package/lib-yak/Draggable.mjs +892 -0
  44. package/lib-yak/Draggable.mjs.map +1 -0
  45. package/lib-yak/ErrorBoundary.mjs +108 -0
  46. package/lib-yak/ErrorBoundary.mjs.map +1 -0
  47. package/lib-yak/FillLastLineResizer.mjs +238 -0
  48. package/lib-yak/FillLastLineResizer.mjs.map +1 -0
  49. package/lib-yak/Flip.mjs +644 -0
  50. package/lib-yak/Flip.mjs.map +1 -0
  51. package/lib-yak/FlipList.mjs +186 -0
  52. package/lib-yak/FlipList.mjs.map +1 -0
  53. package/lib-yak/FormatDate.mjs +25 -0
  54. package/lib-yak/FormatDate.mjs.map +1 -0
  55. package/lib-yak/Icon.mjs +74 -0
  56. package/lib-yak/Icon.mjs.map +1 -0
  57. package/lib-yak/Image.mjs +41 -0
  58. package/lib-yak/Image.mjs.map +1 -0
  59. package/lib-yak/Link.mjs +116 -0
  60. package/lib-yak/Link.mjs.map +1 -0
  61. package/lib-yak/Loading.mjs +54 -0
  62. package/lib-yak/Loading.mjs.map +1 -0
  63. package/lib-yak/LoadingDiv.mjs +82 -0
  64. package/lib-yak/LoadingDiv.mjs.map +1 -0
  65. package/lib-yak/Notifications.mjs +99 -0
  66. package/lib-yak/Notifications.mjs.map +1 -0
  67. package/lib-yak/PageLoader.mjs +61 -0
  68. package/lib-yak/PageLoader.mjs.map +1 -0
  69. package/lib-yak/PersistentNotifications.mjs +209 -0
  70. package/lib-yak/PersistentNotifications.mjs.map +1 -0
  71. package/lib-yak/Popup.mjs +66 -0
  72. package/lib-yak/Popup.mjs.map +1 -0
  73. package/lib-yak/SplitColumnsContainer.mjs +140 -0
  74. package/lib-yak/SplitColumnsContainer.mjs.map +1 -0
  75. package/lib-yak/SwitchDiv.mjs +60 -0
  76. package/lib-yak/SwitchDiv.mjs.map +1 -0
  77. package/lib-yak/TextButton.mjs +61 -0
  78. package/lib-yak/TextButton.mjs.map +1 -0
  79. package/lib-yak/ToastNotifications.mjs +316 -0
  80. package/lib-yak/ToastNotifications.mjs.map +1 -0
  81. package/lib-yak/Tooltip.mjs +176 -0
  82. package/lib-yak/Tooltip.mjs.map +1 -0
  83. package/lib-yak/TransitionDiv.mjs +59 -0
  84. package/lib-yak/TransitionDiv.mjs.map +1 -0
  85. package/lib-yak/WarningDialog.mjs +107 -0
  86. package/lib-yak/WarningDialog.mjs.map +1 -0
  87. package/lib-yak/alt/buttons/OnClickLoadingButton.mjs +36 -0
  88. package/lib-yak/alt/buttons/OnClickLoadingButton.mjs.map +1 -0
  89. package/lib-yak/alt/dialogs/DialogWithImageHeader.mjs +50 -0
  90. package/lib-yak/alt/dialogs/DialogWithImageHeader.mjs.map +1 -0
  91. package/lib-yak/alt/dialogs/DialogWithSidebar.mjs +193 -0
  92. package/lib-yak/alt/dialogs/DialogWithSidebar.mjs.map +1 -0
  93. package/lib-yak/alt/dialogs/MobileBubbleDialog.mjs +82 -0
  94. package/lib-yak/alt/dialogs/MobileBubbleDialog.mjs.map +1 -0
  95. package/lib-yak/containers/DialogContainer.mjs +482 -0
  96. package/lib-yak/containers/DialogContainer.mjs.map +1 -0
  97. package/lib-yak/containers/Reposition.mjs +35 -0
  98. package/lib-yak/containers/Reposition.mjs.map +1 -0
  99. package/lib-yak/containers/usePositioning.mjs +311 -0
  100. package/lib-yak/containers/usePositioning.mjs.map +1 -0
  101. package/lib-yak/index.mjs +37 -0
  102. package/lib-yak/index.mjs.map +1 -0
  103. package/lib-yak/useDialogWithToggle.mjs +18 -0
  104. package/lib-yak/useDialogWithToggle.mjs.map +1 -0
  105. package/lib-yak/willUseIsSticky.mjs +147 -0
  106. package/lib-yak/willUseIsSticky.mjs.map +1 -0
  107. package/package.json +12 -3
  108. package/src/BasicBulletList.jsx +1 -1
  109. package/src/Button.jsx +36 -30
  110. package/src/ContextMenu.jsx +21 -7
  111. package/src/Dialog.jsx +30 -12
  112. package/src/Icon.jsx +5 -4
  113. package/src/Loading.jsx +19 -5
  114. package/src/PageLoader.jsx +3 -3
  115. package/src/PersistentNotifications.jsx +2 -2
  116. package/src/SplitColumnsContainer.jsx +89 -30
  117. package/src/TextButton.jsx +1 -1
  118. package/src/ToastNotifications.jsx +15 -8
  119. package/src/alt/dialogs/DialogWithImageHeader.jsx +2 -2
  120. package/src/alt/dialogs/DialogWithSidebar.jsx +6 -5
  121. package/src/alt/dialogs/MobileBubbleDialog.jsx +1 -1
  122. package/src/containers/DialogContainer.jsx +11 -4
  123. package/src/willUseIsSticky.jsx +22 -2
  124. package/lib/index.js +0 -5444
@@ -0,0 +1,644 @@
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: ${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(${left}px,${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(`
227
+ ${transform}
228
+ ${heightFix}
229
+ ${overflowFix}
230
+ margin-top: ${oldMarginTop}px;
231
+ margin-bottom: ${oldMarginBottom}px;
232
+ width: ${oldSnap.width}px;
233
+ height: ${Math.max(0, oldSnap.height + (smallJumpFix || 0))}px;
234
+ `, `
235
+ ${finalPadding}
236
+ ${oldTransform ? `transform:${oldTransform};` : ''}
237
+ ${overflowFix}
238
+ margin-top:${parseInt(newSnap.marginTop) || 0}px;
239
+ margin-bottom:${parseInt(newSnap.marginBottom) || 0}px;
240
+ width: ${newSnap.width}px;
241
+ height: ${Math.max(0, newSnap.height + (smallJumpFix || 0))}px;
242
+ `)];
243
+ } else {
244
+ return [];
245
+ }
246
+ };
247
+ const getClientRectAnimationForSwitch = function (oldSnap, newSnap) {
248
+ let {
249
+ skipTransform
250
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
251
+ if (hasClientRectChanged(oldSnap, newSnap)) {
252
+ var _node$parentNode, _node$parentNode2;
253
+ const node = newSnap.domNode;
254
+ const {
255
+ offsetLeft,
256
+ offsetTop,
257
+ scrollHeight,
258
+ clientHeight,
259
+ scrollWidth,
260
+ clientWidth
261
+ } = node;
262
+ const scrollTop = ((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.scrollTop) || 0;
263
+ const scrollLeft = ((_node$parentNode2 = node.parentNode) === null || _node$parentNode2 === void 0 ? void 0 : _node$parentNode2.scrollLeft) || 0;
264
+
265
+ // get margin-bottom
266
+ const prevBorder = node.style.border;
267
+ node.style.border = '1px solid transparent';
268
+ const borderHeight = node.clientHeight;
269
+ node.style.border = prevBorder;
270
+
271
+ // get negative margin top
272
+ const prevPadding = newSnap.paddingTop;
273
+ const nonPaddingFixTop = newSnap.clonedNode.getBoundingClientRect().top;
274
+ let topWithPaddingFix = nonPaddingFixTop;
275
+ if (!parseInt(prevPadding)) {
276
+ node.style.paddingTop = '1px';
277
+ topWithPaddingFix = newSnap.clonedNode.getBoundingClientRect().top;
278
+ node.style.paddingTop = '';
279
+ }
280
+ const newSnapNegativeTopMarginDelta = topWithPaddingFix - nonPaddingFixTop;
281
+ const newSnapBottomMarginDelta = clientHeight - borderHeight;
282
+ const left = oldSnap.left - offsetLeft + scrollLeft;
283
+ const top = oldSnap.top - offsetTop + scrollTop - newSnapNegativeTopMarginDelta;
284
+ const deltaHeight = oldSnap.height - newSnap.height;
285
+ let heightFix = '';
286
+ let finalPadding = '';
287
+ if (deltaHeight > 0) {
288
+ const {
289
+ paddingBottom
290
+ } = window.getComputedStyle(node);
291
+ finalPadding = 'padding-bottom:' + paddingBottom + ';';
292
+ heightFix = `padding-bottom: ${sumWithPx(deltaHeight, paddingBottom)};`;
293
+ }
294
+ const overflowFix = scrollHeight > clientHeight || scrollWidth > clientWidth ? `overflow: hidden;` : ``;
295
+ const transform = (left !== 0 || top !== 0) && !skipTransform ? `transform: translate(${left}px,${top}px);` : '';
296
+ const oldTransform = node.style.transform;
297
+ return [oneWayAnimation(`
298
+ ${transform}
299
+ ${heightFix}
300
+ ${overflowFix}
301
+ width: ${oldSnap.width}px;
302
+ height: ${oldSnap.height}px;
303
+ `, `
304
+ ${finalPadding}
305
+ ${oldTransform ? `transform:${oldTransform};` : ''}
306
+ ${overflowFix}
307
+ width: ${newSnap.width}px;
308
+ height: ${newSnap.height - newSnapBottomMarginDelta}px;
309
+ `)];
310
+ } else {
311
+ return [];
312
+ }
313
+ };
314
+ const willPlaySwitch = (oldSnap, newSnap, _ref2) => {
315
+ let {
316
+ switchIn,
317
+ switchOut,
318
+ switchAnimation,
319
+ timing,
320
+ transformHeight = _identity
321
+ } = _ref2;
322
+ const realWrapper = newSnap.domNode;
323
+ const newChildren = [].slice.call(realWrapper.children);
324
+ // realWrapper.style.willChange = 'width,height,margin-top;'
325
+ if (realWrapper.firstChild) {
326
+ realWrapper.insertBefore(oldSnap.clonedNode, realWrapper.firstChild);
327
+ realWrapper.insertBefore(newSnap.clonedNode, realWrapper.firstChild);
328
+ } else {
329
+ realWrapper.append(oldSnap.clonedNode);
330
+ realWrapper.append(newSnap.clonedNode);
331
+ }
332
+ oldSnap.clonedNode.className = oldSnap.clonedNode.className + ' JS-old-snap';
333
+ newSnap.clonedNode.className = newSnap.clonedNode.className + ' JS-new-snap';
334
+ // newSnap.clonedNode.style.willChange = 'width,height,opacity'
335
+ // oldSnap.clonedNode.style.willChange = 'width,height,opacity'
336
+ const realWrapperRect = realWrapper.getBoundingClientRect();
337
+ const resizeToNew = oneWayAnimation(`
338
+ overflow: hidden;
339
+ width: ${oldSnap.width}px;
340
+ height: ${oldSnap.height}px;
341
+ `, `
342
+ overflow: hidden;
343
+ width: ${newSnap.clonedNode.style.width};
344
+ height: ${callIfFunction(transformHeight, newSnap.clonedNode.style.height, realWrapperRect)};
345
+ `);
346
+ childMAp(newChildren, c => {
347
+ if (c.dataset && !c.dataset.noFlip) {
348
+ // Don't capture "0" as prevOpacity — it's always a transient value from
349
+ // a prior uncompleted willPlaySwitch. Otherwise finishSwitchNew restores
350
+ // opacity to "0" permanently, leaving content invisible.
351
+ if (c.style.opacity && c.style.opacity !== '0') {
352
+ c.dataset.prevOpacity = c.style.opacity;
353
+ }
354
+ c.style.opacity = '0';
355
+ }
356
+ });
357
+ childMAp([].slice.call(oldSnap.clonedNode.children), c => {
358
+ if (c.dataset && c.dataset.noFlip) {
359
+ c.style.opacity = '0';
360
+ }
361
+ });
362
+ const resizeOld = oldSnap.width > newSnap.width || oldSnap.height > newSnap.height ? [resizeToNew] : [resizeToNew];
363
+ const resizeNew = oldSnap.width < newSnap.width || oldSnap.height < newSnap.height ? [resizeToNew] : [resizeToNew];
364
+ return () => {
365
+ morph(oldSnap.clonedNode, formatAnimation([].concat(switchOut || switchAnimation, resizeOld), timing), () => oldSnap.clonedNode.remove());
366
+ newSnap.clonedNode.style.opacity = '0';
367
+ continueSwitchCallbacks.set(realWrapper, continueSwitchOnClone(realWrapper));
368
+ morph(newSnap.clonedNode, formatAnimation([formatAnimation(switchIn || switchAnimation, timing, !switchIn)].concat(resizeNew), timing), finishSwitchNew(newSnap.clonedNode, realWrapper));
369
+ };
370
+ };
371
+ const getDelays = (el, animation) => {
372
+ const delayStr = morphTime.get(el) - Date.now() + 'ms';
373
+ return animation.split(',').map(_ => delayStr).join(',');
374
+ };
375
+ class Snapshoter extends React.Component {
376
+ getSnapshotBeforeUpdate(oldProps) {
377
+ if (oldProps.on !== this.props.on) {
378
+ console.log('on', 'UHUL');
379
+ } else if (oldProps.moveOn !== this.props.moveOn) {
380
+ console.log('moveOn', 'UHUL');
381
+ }
382
+ return null;
383
+ }
384
+ render() {
385
+ return null;
386
+ }
387
+ }
388
+ const useFlip = _ref3 => {
389
+ let {
390
+ on,
391
+ moveOn
392
+ } = _ref3;
393
+ useHiddenFill(/*#__PURE__*/React.createElement(Snapshoter, {
394
+ on: on,
395
+ moveOn: moveOn,
396
+ callback: console.log
397
+ }));
398
+ };
399
+ const getAnimationNames = animation => animation.split(',').map(_ => _.replace(/\s*(\S+).*/, '$1'));
400
+ const willUseFlip = () => {
401
+ let controlElement = null;
402
+ let morphEnabled = false;
403
+ const disableMorph = () => {
404
+ controlElement = null;
405
+ morphEnabled = false;
406
+ };
407
+ const [useRegisterEnter, enterChildrenCallback] = willUseSharedCallback(useLayoutEffect);
408
+ const [useRegisterLeave, leaveChildrenCallback] = willUseSharedCallback(useLayoutEffect);
409
+ const [useRegisterMorph, morphChildrenCallback, getSize] = willUseSharedCallback(useLayoutEffect);
410
+ const useEnterAnimation = function (ref) {
411
+ let onEnter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultEnterAnimation;
412
+ let {
413
+ onEnterEnd,
414
+ timing = defaultAnimationMaker,
415
+ enterEffect
416
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
417
+ useLayoutEffect(() => {
418
+ if (!morphEnabled && onEnter && ref.current) {
419
+ const el = ref.current;
420
+ const animation = formatAnimation(onEnter, timing);
421
+ const endEffect = callIfFunction(enterEffect, el);
422
+ morph(el, animation, () => {
423
+ callIfFunction(onEnterEnd);
424
+ callIfFunction(endEffect, el);
425
+ });
426
+ enterChildrenCallback(timing);
427
+ }
428
+ }, [onEnter]);
429
+ };
430
+ const useLeaveAnimation = function (ref) {
431
+ let onLeave = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultEnterAnimation;
432
+ let {
433
+ ref: removeRef,
434
+ leaveEffect,
435
+ timing = defaultAnimationMaker,
436
+ nestedFlip = false,
437
+ events = {},
438
+ reverse = true
439
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
440
+ useLayoutEffect(() => () => {
441
+ if (onLeave && ref.current) {
442
+ const el = ref.current;
443
+ const animation = formatAnimation(onLeave, timing, reverse);
444
+ // on leave animations require a clone, as the real node will be intantaneousy removed by react
445
+ leaveChildrenCallback(timing);
446
+ const isNested = callIfFunction(nestedFlip);
447
+ const clone = isNested ? el : el.cloneNode(true);
448
+ _s.each((callback, type) => clone.addEventListener(type, callback), events);
449
+ const endEffect = callIfFunction(leaveEffect, clone, el);
450
+ if (removeRef) {
451
+ removeRef.current = clone;
452
+ }
453
+ if (!isNested) {
454
+ el.parentNode.insertBefore(clone, el);
455
+ }
456
+ // sometimes the clone may need to trigger events (usual case: onmouseover to reopen the element)
457
+
458
+ // allow clone to be continued by another animation
459
+ controlElement = clone;
460
+ // the animation
461
+ const animate = () => {
462
+ morph(clone, animation, () => {
463
+ clone.remove();
464
+ disableMorph();
465
+ callIfFunction(endEffect, clone, el);
466
+ });
467
+ };
468
+
469
+ // wait for current animation to end and then animate
470
+ if (clone.style.animation) {
471
+ const maxAnimationTime = _max((clone.style.animationDuration.split(",") || ["0.25s"]).map(s => parseFloat(s.trim() || "0.25") * (s.indexOf("m") > 0 ? 1 : 1000)));
472
+ const timeoutRef = {};
473
+ const animationEnd = e => {
474
+ clearTimeout(timeoutRef.current || -1);
475
+ clone.removeEventListener('animationend', animationEnd);
476
+ clone.style.animationDelay = '';
477
+ e === null || e === void 0 || e.stopImmediatePropagation();
478
+ setTimeout(animate, 1);
479
+ };
480
+ timeoutRef.current = setTimeout(animationEnd, maxAnimationTime);
481
+ clone.addEventListener('animationend', animationEnd);
482
+ clone.style.animationDelay = getDelays(el, clone.style.animation);
483
+ } else {
484
+ animate();
485
+ }
486
+ }
487
+ }, [onLeave]);
488
+ };
489
+ const useMorphAnimation = function (ref) {
490
+ let ready = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
491
+ let {
492
+ timing = defaultAnimationMaker
493
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
494
+ useLayoutEffect(() => {
495
+ if (ready && controlElement && ref.current) {
496
+ // const controlElement =getControlElement()
497
+ const el = ref.current;
498
+ const animation = oneWayAnimation(`opacity:${window.getComputedStyle(controlElement).opacity};`, `opacity: 1`);
499
+ const oldSnap = _objectSpread(_objectSpread({}, toPosition(controlElement, undefined, {
500
+ allowFixed: true
501
+ })), {}, {
502
+ clonedNode: cloneWrapper(controlElement)
503
+ });
504
+ const newSnap = _objectSpread(_objectSpread({}, toPosition(el, undefined, {
505
+ allowFixed: true
506
+ })), {}, {
507
+ clonedNode: cloneWrapper(el)
508
+ });
509
+ const rectAnimation = getClientRectAnimation(oldSnap, newSnap);
510
+ morph(newSnap.domNode, formatAnimation(rectAnimation.concat(animation), timing), disableMorph);
511
+ morphChildrenCallback(executeAnimation => executeAnimation(timing));
512
+ if (rectAnimation.length) {
513
+ willPlaySwitch(oldSnap, newSnap, {
514
+ switchAnimation: defaultSwitchAnimation,
515
+ timing
516
+ })();
517
+ }
518
+ controlElement.remove();
519
+ disableMorph();
520
+ }
521
+ return () => {
522
+ morphEnabled = true;
523
+ // continue existing switch animation on the clone
524
+ if (continueSwitchCallbacks.has(ref.current)) {
525
+ continueSwitchCallbacks.get(ref.current)(controlElement);
526
+ }
527
+ };
528
+ }, [ready]);
529
+ };
530
+ const useNestedEnterAnimation = function (ref, onEnter) {
531
+ let {
532
+ timing
533
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
534
+ useRegisterEnter(parentTiming => {
535
+ const el = ref.current;
536
+ const animation = formatAnimation(onEnter, timing || parentTiming);
537
+ morph(el, animation);
538
+ return getAnimationNames(animation);
539
+ });
540
+ };
541
+ const useNestLeaveAnimation = function (ref, onLeave) {
542
+ let {
543
+ timing,
544
+ events
545
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
546
+ useRegisterLeave(parentTiming => {
547
+ const el = ref.current;
548
+ const animation = formatAnimation(onLeave, timing || parentTiming);
549
+ morph(el, animation);
550
+ return getAnimationNames(animation);
551
+ });
552
+ };
553
+ const willUseNestedMorphAnimation = () => {
554
+ const morphId = _uniqueId('JS-');
555
+ return ref => {
556
+ useLayoutEffect(() => {
557
+ var _ref$current;
558
+ if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.dataset) {
559
+ ref.current.dataset.morphId = morphId;
560
+ }
561
+ });
562
+ const executeAnimation = useConstant(timing => {
563
+ const prev = controlElement.querySelector(`[data-morph-id='${morphId}']`);
564
+ const next = ref.current;
565
+ if (next.dataset) {
566
+ next.dataset.noFlip = true;
567
+ }
568
+ next.style.opacity = '1';
569
+ const prevPos = prev.getBoundingClientRect();
570
+ const nextPos = next.getBoundingClientRect();
571
+ const originalTransform = next.style.transform || '';
572
+ const deltaX = Math.round(nextPos.left - prevPos.left);
573
+ const deltaY = Math.round(nextPos.top - prevPos.top);
574
+ const newLeft = deltaX > 0 ? -deltaX : -deltaX;
575
+ const animation = oneWayAnimation(`
576
+ transform: translate(${newLeft}px,${deltaY}px) ${originalTransform};
577
+ `, `
578
+ transform: translate(0,0) ${originalTransform};
579
+ `);
580
+ morph(next, formatAnimation(animation, timing));
581
+ });
582
+ useRegisterMorph(executeAnimation);
583
+ };
584
+ };
585
+ return [[useEnterAnimation, useLeaveAnimation, useMorphAnimation], [useNestedEnterAnimation, useNestLeaveAnimation], willUseNestedMorphAnimation];
586
+ };
587
+ const willUseFlipSwitch = () => {
588
+ let oldSnap = null;
589
+ const getTempWrapper = function (parent) {
590
+ let positionConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
591
+ const tempWrapper = cloneWrapper(parent);
592
+ return _objectSpread(_objectSpread({}, toPosition(parent, undefined, positionConfig)), {}, {
593
+ clonedNode: tempWrapper
594
+ });
595
+ };
596
+ return function (ref, onEnter, onLeave) {
597
+ let {
598
+ timing = defaultAnimationMaker,
599
+ switchAnimation = defaultSwitchAnimation,
600
+ effect
601
+ } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
602
+ useLayoutEffect(() => {
603
+ if (oldSnap && ref.current) {
604
+ const newSnap = getTempWrapper(ref.current, {
605
+ withMargins: true
606
+ });
607
+ let switchToPlay = _identity;
608
+ if (oldSnap.clonedNode) {
609
+ switchToPlay = willPlaySwitch(oldSnap, newSnap, {
610
+ switchIn: callIfFunction(onEnter),
611
+ switchOut: callIfFunction(onLeave),
612
+ switchAnimation: callIfFunction(switchAnimation),
613
+ timing
614
+ });
615
+ }
616
+ const animation = getClientRectAnimationForSwitch(oldSnap, newSnap);
617
+ const endEffect = callIfFunction(effect, oldSnap.clonedNode, newSnap.clonedNode, ref.current);
618
+ switchToPlay();
619
+ morph(newSnap.domNode, formatAnimation(animation, timing), () => callIfFunction(endEffect, oldSnap.clonedNode, newSnap.clonedNode));
620
+ }
621
+ return () => {
622
+ oldSnap = getTempWrapper(ref.current, {
623
+ withMargins: true
624
+ });
625
+ };
626
+ }, []);
627
+ };
628
+ };
629
+ const flipHooks = willUseFlip();
630
+ const useFlipEnter = flipHooks[0][0];
631
+ const useFlipLeave = flipHooks[0][1];
632
+ const useFlipAnimation = function (ref, onEnterOrBoth) {
633
+ let onLeaveOrIgnore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
634
+ let config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
635
+ const onEnter = ifUndefined(onEnterOrBoth && onEnterOrBoth.onEnter, onEnterOrBoth);
636
+ const onLeave = ifUndefined(onEnterOrBoth && onEnterOrBoth.onLeave, onLeaveOrIgnore);
637
+ useFlipEnter(ref, onEnter, config);
638
+ useFlipLeave(ref, onLeave === true ? onEnter : onLeave, _objectSpread(_objectSpread({}, config), {}, {
639
+ reverse: onLeave === true
640
+ }));
641
+ };
642
+
643
+ export { defaultAnimationMaker, formatAnimation, getClientRectAnimation, morph, toPosition, useFlip, useFlipAnimation, useFlipEnter, useFlipLeave, willUseFlip, willUseFlipSwitch };
644
+ //# sourceMappingURL=Flip.mjs.map