react-tooltip 5.26.2 → 5.26.4-beta.1148.rc.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.
@@ -0,0 +1,77 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const util = require('util')
3
+ const exec = util.promisify(require('child_process').exec)
4
+ const package = require('./package.json')
5
+
6
+ const args = require('minimist')(process.argv.slice(2))
7
+
8
+ const issueNumber = args['issue']
9
+
10
+ console.log(issueNumber)
11
+
12
+ const runCommand = async (command) => {
13
+ return new Promise((resolve) => {
14
+ exec(command, (error, stdout, stderr) => {
15
+ resolve({ error, stdout, stderr })
16
+ })
17
+ })
18
+ }
19
+
20
+ const AutoBetaRelease = async () => {
21
+ // get all the versions of the package from npm
22
+ const { stdout } = await runCommand(`npm view . versions --json`)
23
+
24
+ // show npm published versions of this package
25
+ console.log(stdout)
26
+
27
+ // check if there is a beta release with the same issue number on published versions
28
+ const arrayOfBetaReleases = JSON.parse(stdout).filter((version) =>
29
+ version.includes(`${package.version}-beta.${issueNumber}`),
30
+ )
31
+
32
+ let fullLastBetaRelease = null
33
+
34
+ // if yes, get the latest beta release. Output: 1.0.0-beta.1.rc.0
35
+ if (arrayOfBetaReleases.length) {
36
+ fullLastBetaRelease = arrayOfBetaReleases[arrayOfBetaReleases.length - 1]
37
+ }
38
+
39
+ console.log('Last Beta Release: ', fullLastBetaRelease)
40
+
41
+ let nextBetaReleaseVersion = 0
42
+
43
+ if (fullLastBetaRelease) {
44
+ const lastBetaReleaseRCVersionArray = fullLastBetaRelease.match(/rc.+[0-9]+/g)
45
+
46
+ const lastBetaReleaseRCVersion =
47
+ lastBetaReleaseRCVersionArray && lastBetaReleaseRCVersionArray.length
48
+ ? lastBetaReleaseRCVersionArray[0]
49
+ : null
50
+
51
+ const lastBetaReleaseVersion = lastBetaReleaseRCVersion
52
+ ? lastBetaReleaseRCVersion.split('.')[1]
53
+ : 0
54
+
55
+ nextBetaReleaseVersion = parseInt(lastBetaReleaseVersion, 10) + 1
56
+ }
57
+
58
+ // next beta release version. Output: 1.0.0-beta.1.rc.1
59
+ const nextBetaReleaseVesionFull = `${package.version}-beta.${issueNumber}.rc.${nextBetaReleaseVersion}`
60
+
61
+ // update the beta version on package.json
62
+ const { error } = await runCommand(
63
+ `npm version ${nextBetaReleaseVesionFull} --no-git-tag-version`,
64
+ )
65
+
66
+ if (error) {
67
+ console.error(error)
68
+ return
69
+ }
70
+
71
+ // the beta version is already updated on package.json on the next line
72
+ console.log('Next Beta version: ', `${nextBetaReleaseVesionFull}`)
73
+
74
+ await runCommand(`echo "NEW_VERSION=${nextBetaReleaseVesionFull}" >> $GITHUB_ENV`)
75
+ }
76
+
77
+ AutoBetaRelease()
@@ -105,6 +105,96 @@ function removeStyle({ type = 'base', id = REACT_TOOLTIP_BASE_STYLES_ID, } = {})
105
105
  injected[type] = false;
106
106
  }
107
107
 
108
+ const computeTooltipPosition = async ({ elementReference = null, tooltipReference = null, tooltipArrowReference = null, place = 'top', offset: offsetValue = 10, strategy = 'absolute', middlewares = [
109
+ dom.offset(Number(offsetValue)),
110
+ dom.flip({
111
+ fallbackAxisSideDirection: 'start',
112
+ }),
113
+ dom.shift({ padding: 5 }),
114
+ ], border, }) => {
115
+ if (!elementReference) {
116
+ // elementReference can be null or undefined and we will not compute the position
117
+ // eslint-disable-next-line no-console
118
+ // console.error('The reference element for tooltip was not defined: ', elementReference)
119
+ return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
120
+ }
121
+ if (tooltipReference === null) {
122
+ return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
123
+ }
124
+ const middleware = middlewares;
125
+ if (tooltipArrowReference) {
126
+ middleware.push(dom.arrow({ element: tooltipArrowReference, padding: 5 }));
127
+ return dom.computePosition(elementReference, tooltipReference, {
128
+ placement: place,
129
+ strategy,
130
+ middleware,
131
+ }).then(({ x, y, placement, middlewareData }) => {
132
+ var _a, _b;
133
+ const styles = { left: `${x}px`, top: `${y}px`, border };
134
+ /* c8 ignore start */
135
+ const { x: arrowX, y: arrowY } = (_a = middlewareData.arrow) !== null && _a !== void 0 ? _a : { x: 0, y: 0 };
136
+ const staticSide = (_b = {
137
+ top: 'bottom',
138
+ right: 'left',
139
+ bottom: 'top',
140
+ left: 'right',
141
+ }[placement.split('-')[0]]) !== null && _b !== void 0 ? _b : 'bottom';
142
+ /* c8 ignore end */
143
+ const borderSide = border && {
144
+ borderBottom: border,
145
+ borderRight: border,
146
+ };
147
+ let borderWidth = 0;
148
+ if (border) {
149
+ const match = `${border}`.match(/(\d+)px/);
150
+ if (match === null || match === void 0 ? void 0 : match[1]) {
151
+ borderWidth = Number(match[1]);
152
+ }
153
+ else {
154
+ /**
155
+ * this means `border` was set without `width`,
156
+ * or non-px value (such as `medium`, `thick`, ...)
157
+ */
158
+ borderWidth = 1;
159
+ }
160
+ }
161
+ /* c8 ignore start */
162
+ const arrowStyle = {
163
+ left: arrowX != null ? `${arrowX}px` : '',
164
+ top: arrowY != null ? `${arrowY}px` : '',
165
+ right: '',
166
+ bottom: '',
167
+ ...borderSide,
168
+ [staticSide]: `-${4 + borderWidth}px`,
169
+ };
170
+ /* c8 ignore end */
171
+ return { tooltipStyles: styles, tooltipArrowStyles: arrowStyle, place: placement };
172
+ });
173
+ }
174
+ return dom.computePosition(elementReference, tooltipReference, {
175
+ placement: 'bottom',
176
+ strategy,
177
+ middleware,
178
+ }).then(({ x, y, placement }) => {
179
+ const styles = { left: `${x}px`, top: `${y}px` };
180
+ return { tooltipStyles: styles, tooltipArrowStyles: {}, place: placement };
181
+ });
182
+ };
183
+
184
+ const cssSupports = (property, value) => {
185
+ const hasCssSupports = 'CSS' in window && 'supports' in window.CSS;
186
+ return hasCssSupports ? window.CSS.supports(property, value) : true;
187
+ };
188
+
189
+ const cssTimeToMs = (time) => {
190
+ const match = time.match(/^([\d.]+)(ms|s)$/);
191
+ if (!match) {
192
+ return 0;
193
+ }
194
+ const [, amount, unit] = match;
195
+ return Number(amount) * (unit === 'ms' ? 1 : 1000);
196
+ };
197
+
108
198
  /* eslint-disable @typescript-eslint/no-explicit-any */
109
199
  /**
110
200
  * This function debounce the received function
@@ -123,7 +213,7 @@ const debounce = (func, wait, immediate) => {
123
213
  };
124
214
  if (immediate && !timeout) {
125
215
  /**
126
- * there's not need to clear the timeout
216
+ * there's no need to clear the timeout
127
217
  * since we expect it to resolve and set `timeout = null`
128
218
  */
129
219
  func.apply(this, args);
@@ -137,15 +227,70 @@ const debounce = (func, wait, immediate) => {
137
227
  }
138
228
  };
139
229
  debounced.cancel = () => {
230
+ /* c8 ignore start */
140
231
  if (!timeout) {
141
232
  return;
142
233
  }
234
+ /* c8 ignore end */
143
235
  clearTimeout(timeout);
144
236
  timeout = null;
145
237
  };
146
238
  return debounced;
147
239
  };
148
240
 
241
+ const isObject = (object) => {
242
+ return object !== null && !Array.isArray(object) && typeof object === 'object';
243
+ };
244
+ const deepEqual = (object1, object2) => {
245
+ if (object1 === object2) {
246
+ return true;
247
+ }
248
+ if (Array.isArray(object1) && Array.isArray(object2)) {
249
+ if (object1.length !== object2.length) {
250
+ return false;
251
+ }
252
+ return object1.every((val, index) => deepEqual(val, object2[index]));
253
+ }
254
+ if (Array.isArray(object1) !== Array.isArray(object2)) {
255
+ return false;
256
+ }
257
+ if (!isObject(object1) || !isObject(object2)) {
258
+ return object1 === object2;
259
+ }
260
+ const keys1 = Object.keys(object1);
261
+ const keys2 = Object.keys(object2);
262
+ if (keys1.length !== keys2.length) {
263
+ return false;
264
+ }
265
+ return keys1.every((key) => deepEqual(object1[key], object2[key]));
266
+ };
267
+
268
+ const isScrollable = (node) => {
269
+ if (!(node instanceof HTMLElement || node instanceof SVGElement)) {
270
+ return false;
271
+ }
272
+ const style = getComputedStyle(node);
273
+ return ['overflow', 'overflow-x', 'overflow-y'].some((propertyName) => {
274
+ const value = style.getPropertyValue(propertyName);
275
+ return value === 'auto' || value === 'scroll';
276
+ });
277
+ };
278
+ const getScrollParent = (node) => {
279
+ if (!node) {
280
+ return null;
281
+ }
282
+ let currentParent = node.parentElement;
283
+ while (currentParent) {
284
+ if (isScrollable(currentParent)) {
285
+ return currentParent;
286
+ }
287
+ currentParent = currentParent.parentElement;
288
+ }
289
+ return document.scrollingElement || document.documentElement;
290
+ };
291
+
292
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
293
+
149
294
  const DEFAULT_TOOLTIP_ID = 'DEFAULT_TOOLTIP_ID';
150
295
  const DEFAULT_CONTEXT_DATA = {
151
296
  anchorRefs: new Set(),
@@ -244,137 +389,6 @@ const TooltipWrapper = ({ tooltipId, children, className, place, content, html,
244
389
  return (React__default["default"].createElement("span", { ref: anchorRef, className: classNames__default["default"]('react-tooltip-wrapper', className), "data-tooltip-place": place, "data-tooltip-content": content, "data-tooltip-html": html, "data-tooltip-variant": variant, "data-tooltip-offset": offset, "data-tooltip-wrapper": wrapper, "data-tooltip-events": events, "data-tooltip-position-strategy": positionStrategy, "data-tooltip-delay-show": delayShow, "data-tooltip-delay-hide": delayHide }, children));
245
390
  };
246
391
 
247
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
248
-
249
- const isScrollable = (node) => {
250
- if (!(node instanceof HTMLElement || node instanceof SVGElement)) {
251
- return false;
252
- }
253
- const style = getComputedStyle(node);
254
- return ['overflow', 'overflow-x', 'overflow-y'].some((propertyName) => {
255
- const value = style.getPropertyValue(propertyName);
256
- return value === 'auto' || value === 'scroll';
257
- });
258
- };
259
- const getScrollParent = (node) => {
260
- if (!node) {
261
- return null;
262
- }
263
- let currentParent = node.parentElement;
264
- while (currentParent) {
265
- if (isScrollable(currentParent)) {
266
- return currentParent;
267
- }
268
- currentParent = currentParent.parentElement;
269
- }
270
- return document.scrollingElement || document.documentElement;
271
- };
272
-
273
- const computeTooltipPosition = async ({ elementReference = null, tooltipReference = null, tooltipArrowReference = null, place = 'top', offset: offsetValue = 10, strategy = 'absolute', middlewares = [
274
- dom.offset(Number(offsetValue)),
275
- dom.flip({
276
- fallbackAxisSideDirection: 'start',
277
- }),
278
- dom.shift({ padding: 5 }),
279
- ], border, }) => {
280
- if (!elementReference) {
281
- // elementReference can be null or undefined and we will not compute the position
282
- // eslint-disable-next-line no-console
283
- // console.error('The reference element for tooltip was not defined: ', elementReference)
284
- return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
285
- }
286
- if (tooltipReference === null) {
287
- return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
288
- }
289
- const middleware = middlewares;
290
- if (tooltipArrowReference) {
291
- middleware.push(dom.arrow({ element: tooltipArrowReference, padding: 5 }));
292
- return dom.computePosition(elementReference, tooltipReference, {
293
- placement: place,
294
- strategy,
295
- middleware,
296
- }).then(({ x, y, placement, middlewareData }) => {
297
- var _a, _b;
298
- const styles = { left: `${x}px`, top: `${y}px`, border };
299
- const { x: arrowX, y: arrowY } = (_a = middlewareData.arrow) !== null && _a !== void 0 ? _a : { x: 0, y: 0 };
300
- const staticSide = (_b = {
301
- top: 'bottom',
302
- right: 'left',
303
- bottom: 'top',
304
- left: 'right',
305
- }[placement.split('-')[0]]) !== null && _b !== void 0 ? _b : 'bottom';
306
- const borderSide = border && {
307
- borderBottom: border,
308
- borderRight: border,
309
- };
310
- let borderWidth = 0;
311
- if (border) {
312
- const match = `${border}`.match(/(\d+)px/);
313
- if (match === null || match === void 0 ? void 0 : match[1]) {
314
- borderWidth = Number(match[1]);
315
- }
316
- else {
317
- /**
318
- * this means `border` was set without `width`, or non-px value
319
- */
320
- borderWidth = 1;
321
- }
322
- }
323
- const arrowStyle = {
324
- left: arrowX != null ? `${arrowX}px` : '',
325
- top: arrowY != null ? `${arrowY}px` : '',
326
- right: '',
327
- bottom: '',
328
- ...borderSide,
329
- [staticSide]: `-${4 + borderWidth}px`,
330
- };
331
- return { tooltipStyles: styles, tooltipArrowStyles: arrowStyle, place: placement };
332
- });
333
- }
334
- return dom.computePosition(elementReference, tooltipReference, {
335
- placement: 'bottom',
336
- strategy,
337
- middleware,
338
- }).then(({ x, y, placement }) => {
339
- const styles = { left: `${x}px`, top: `${y}px` };
340
- return { tooltipStyles: styles, tooltipArrowStyles: {}, place: placement };
341
- });
342
- };
343
-
344
- const cssTimeToMs = (time) => {
345
- const match = time.match(/^([\d.]+)(m?s?)$/);
346
- if (!match) {
347
- return 0;
348
- }
349
- const [, amount, unit] = match;
350
- if (unit !== 's' && unit !== 'ms') {
351
- return 0;
352
- }
353
- return Number(amount) * (unit === 'ms' ? 1 : 1000);
354
- };
355
-
356
- const isObject = (object) => {
357
- return object !== null && typeof object === 'object';
358
- };
359
- const deepEqual = (object1, object2) => {
360
- if (!isObject(object1) || !isObject(object2)) {
361
- return object1 === object2;
362
- }
363
- const keys1 = Object.keys(object1);
364
- const keys2 = Object.keys(object2);
365
- if (keys1.length !== keys2.length) {
366
- return false;
367
- }
368
- return keys1.every((key) => {
369
- const val1 = object1[key];
370
- const val2 = object2[key];
371
- if (isObject(val1) && isObject(val2)) {
372
- return deepEqual(val1, val2);
373
- }
374
- return val1 === val2;
375
- });
376
- };
377
-
378
392
  var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE","closing":"core-styles-module_closing__sGnxF"};
379
393
 
380
394
  var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_arrow__K0L3T","dark":"styles-module_dark__xNqje","light":"styles-module_light__Z6W-X","success":"styles-module_success__A2AKt","warning":"styles-module_warning__SCK0X","error":"styles-module_error__JvumD","info":"styles-module_info__BWdHW"};
@@ -925,7 +939,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
925
939
  var _a, _b;
926
940
  let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
927
941
  if (!selector && id) {
928
- selector = `[data-tooltip-id='${id}']`;
942
+ selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']`;
929
943
  }
930
944
  const documentObserverCallback = (mutationList) => {
931
945
  const newAnchors = [];
@@ -1064,7 +1078,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1064
1078
  var _a;
1065
1079
  let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
1066
1080
  if (!selector && id) {
1067
- selector = `[data-tooltip-id='${id}']`;
1081
+ selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']`;
1068
1082
  }
1069
1083
  if (!selector) {
1070
1084
  return;
@@ -1149,11 +1163,6 @@ const TooltipContent = ({ content }) => {
1149
1163
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
1150
1164
  };
1151
1165
 
1152
- const cssSupports = (property, value) => {
1153
- const hasCssSupports = 'CSS' in window && 'supports' in window.CSS;
1154
- return hasCssSupports ? window.CSS.supports(property, value) : true;
1155
- };
1156
-
1157
1166
  const TooltipController = React__default["default"].forwardRef(({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly = false, style, position, isOpen, defaultIsOpen = false, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, role = 'tooltip', }, ref) => {
1158
1167
  const [tooltipContent, setTooltipContent] = React.useState(content);
1159
1168
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
@@ -1274,10 +1283,12 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1274
1283
  if (styleInjectionRef.current === disableStyleInjection) {
1275
1284
  return;
1276
1285
  }
1286
+ /* c8 ignore start */
1277
1287
  {
1278
1288
  // eslint-disable-next-line no-console
1279
1289
  console.warn('[react-tooltip] Do not change `disableStyleInjection` dynamically.');
1280
1290
  }
1291
+ /* c8 ignore end */
1281
1292
  }, [disableStyleInjection]);
1282
1293
  React.useEffect(() => {
1283
1294
  if (typeof window !== 'undefined') {
@@ -1294,7 +1305,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1294
1305
  const elementRefs = new Set(anchorRefs);
1295
1306
  let selector = anchorSelect;
1296
1307
  if (!selector && id) {
1297
- selector = `[data-tooltip-id='${id}']`;
1308
+ selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']`;
1298
1309
  }
1299
1310
  if (selector) {
1300
1311
  try {
@@ -1304,10 +1315,12 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1304
1315
  });
1305
1316
  }
1306
1317
  catch (_b) {
1318
+ /* c8 ignore start */
1307
1319
  {
1308
1320
  // eslint-disable-next-line no-console
1309
1321
  console.warn(`[react-tooltip] "${selector}" is not a valid CSS selector`);
1310
1322
  }
1323
+ /* c8 ignore end */
1311
1324
  }
1312
1325
  }
1313
1326
  const anchorById = document.querySelector(`[id='${anchorId}']`);
@@ -1348,6 +1361,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1348
1361
  };
1349
1362
  }, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
1350
1363
  React.useEffect(() => {
1364
+ /* c8 ignore end */
1351
1365
  if (style === null || style === void 0 ? void 0 : style.border) {
1352
1366
  // eslint-disable-next-line no-console
1353
1367
  console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.');