@tanstack/react-query-devtools 4.15.1 → 4.16.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.
@@ -422,6 +422,36 @@ const ExpandButton = styled('button', {
422
422
  border: 'none',
423
423
  padding: 0
424
424
  });
425
+ const CopyButton = ({
426
+ value
427
+ }) => {
428
+ const [copyState, setCopyState] = React.useState('NoCopy');
429
+ return /*#__PURE__*/React.createElement("button", {
430
+ onClick: copyState === 'NoCopy' ? () => {
431
+ navigator.clipboard.writeText(SuperJSON.stringify(value)).then(() => {
432
+ setCopyState('SuccessCopy');
433
+ setTimeout(() => {
434
+ setCopyState('NoCopy');
435
+ }, 1500);
436
+ }, err => {
437
+ console.error('Failed to copy: ', err);
438
+ setCopyState('ErrorCopy');
439
+ setTimeout(() => {
440
+ setCopyState('NoCopy');
441
+ }, 1500);
442
+ });
443
+ } : undefined,
444
+ style: {
445
+ cursor: 'pointer',
446
+ color: 'inherit',
447
+ font: 'inherit',
448
+ outline: 'inherit',
449
+ background: 'transparent',
450
+ border: 'none',
451
+ padding: 0
452
+ }
453
+ }, copyState === 'NoCopy' ? /*#__PURE__*/React.createElement(Copier, null) : copyState === 'SuccessCopy' ? /*#__PURE__*/React.createElement(CopiedCopier, null) : /*#__PURE__*/React.createElement(ErrorCopier, null));
454
+ };
425
455
  const Value = styled('span', (_props, theme) => ({
426
456
  color: theme.danger
427
457
  }));
@@ -446,6 +476,68 @@ const Expander = ({
446
476
  }
447
477
  }, "\u25B6");
448
478
 
479
+ const Copier = () => /*#__PURE__*/React.createElement("span", {
480
+ "aria-label": "Copy object to clipboard",
481
+ title: "Copy object to clipboard",
482
+ style: {
483
+ paddingLeft: '1em'
484
+ }
485
+ }, /*#__PURE__*/React.createElement("svg", {
486
+ height: "12",
487
+ viewBox: "0 0 16 12",
488
+ width: "10"
489
+ }, /*#__PURE__*/React.createElement("path", {
490
+ fill: "currentColor",
491
+ d: "M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"
492
+ }), /*#__PURE__*/React.createElement("path", {
493
+ fill: "currentColor",
494
+ d: "M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"
495
+ })));
496
+
497
+ const ErrorCopier = () => /*#__PURE__*/React.createElement("span", {
498
+ "aria-label": "Failed copying to clipboard",
499
+ title: "Failed copying to clipboard",
500
+ style: {
501
+ paddingLeft: '1em',
502
+ display: 'flex',
503
+ alignItems: 'center'
504
+ }
505
+ }, /*#__PURE__*/React.createElement("svg", {
506
+ height: "12",
507
+ viewBox: "0 0 16 12",
508
+ width: "10",
509
+ display: "block"
510
+ }, /*#__PURE__*/React.createElement("path", {
511
+ fill: "red",
512
+ d: "M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"
513
+ })), /*#__PURE__*/React.createElement("span", {
514
+ style: {
515
+ color: 'red',
516
+ fontSize: '12px',
517
+ paddingLeft: '4px',
518
+ position: 'relative',
519
+ top: '2px'
520
+ }
521
+ }, "See console"));
522
+
523
+ const CopiedCopier = () => /*#__PURE__*/React.createElement("span", {
524
+ "aria-label": "Object copied to clipboard",
525
+ title: "Object copied to clipboard",
526
+ style: {
527
+ paddingLeft: '1em',
528
+ display: 'inline-block',
529
+ verticalAlign: 'middle'
530
+ }
531
+ }, /*#__PURE__*/React.createElement("svg", {
532
+ height: "16",
533
+ viewBox: "0 0 16 16",
534
+ width: "16",
535
+ display: "block"
536
+ }, /*#__PURE__*/React.createElement("path", {
537
+ fill: "green",
538
+ d: "M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"
539
+ })));
540
+
449
541
  /**
450
542
  * Chunk elements in the array by size
451
543
  *
@@ -475,6 +567,7 @@ const DefaultRenderer = ({
475
567
  subEntryPages = [],
476
568
  type,
477
569
  expanded = false,
570
+ copyable = false,
478
571
  toggleExpanded,
479
572
  pageSize
480
573
  }) => {
@@ -485,7 +578,9 @@ const DefaultRenderer = ({
485
578
  onClick: () => toggleExpanded()
486
579
  }, /*#__PURE__*/React.createElement(Expander, {
487
580
  expanded: expanded
488
- }), " ", label, ' ', /*#__PURE__*/React.createElement(Info, null, String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : '', subEntries.length, " ", subEntries.length > 1 ? "items" : "item")), expanded ? subEntryPages.length === 1 ? /*#__PURE__*/React.createElement(SubEntries, null, subEntries.map(handleEntry)) : /*#__PURE__*/React.createElement(SubEntries, null, subEntryPages.map((entries, index) => /*#__PURE__*/React.createElement("div", {
581
+ }), " ", label, ' ', /*#__PURE__*/React.createElement(Info, null, String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : '', subEntries.length, " ", subEntries.length > 1 ? "items" : "item")), copyable ? /*#__PURE__*/React.createElement(CopyButton, {
582
+ value: value
583
+ }) : null, expanded ? subEntryPages.length === 1 ? /*#__PURE__*/React.createElement(SubEntries, null, subEntries.map(handleEntry)) : /*#__PURE__*/React.createElement(SubEntries, null, subEntryPages.map((entries, index) => /*#__PURE__*/React.createElement("div", {
489
584
  key: index
490
585
  }, /*#__PURE__*/React.createElement(Entry, null, /*#__PURE__*/React.createElement(LabelButton, {
491
586
  onClick: () => setExpandedPages(old => old.includes(index) ? old.filter(d => d !== index) : [...old, index])
@@ -503,6 +598,7 @@ function Explorer({
503
598
  defaultExpanded,
504
599
  renderer = DefaultRenderer,
505
600
  pageSize = 100,
601
+ copyable = false,
506
602
  ...rest
507
603
  }) {
508
604
  const [expanded, setExpanded] = React.useState(Boolean(defaultExpanded));
@@ -544,13 +640,15 @@ function Explorer({
544
640
  handleEntry: entry => /*#__PURE__*/React.createElement(Explorer, _extends({
545
641
  key: entry.label,
546
642
  value: value,
547
- renderer: renderer
643
+ renderer: renderer,
644
+ copyable: copyable
548
645
  }, rest, entry)),
549
646
  type,
550
647
  subEntries,
551
648
  subEntryPages,
552
649
  value,
553
650
  expanded,
651
+ copyable,
554
652
  toggleExpanded,
555
653
  pageSize,
556
654
  ...rest
@@ -1227,7 +1325,8 @@ const ActiveQuery = ({
1227
1325
  }, /*#__PURE__*/React.createElement(Explorer, {
1228
1326
  label: "Data",
1229
1327
  value: activeQueryState.data,
1230
- defaultExpanded: {}
1328
+ defaultExpanded: {},
1329
+ copyable: true
1231
1330
  })), /*#__PURE__*/React.createElement("div", {
1232
1331
  style: {
1233
1332
  background: defaultTheme.backgroundAlt,