@tanstack/react-query-devtools 4.15.1 → 4.16.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.
@@ -449,6 +449,36 @@ const ExpandButton = styled('button', {
449
449
  border: 'none',
450
450
  padding: 0
451
451
  });
452
+ const CopyButton = ({
453
+ value
454
+ }) => {
455
+ const [copyState, setCopyState] = React__namespace.useState('NoCopy');
456
+ return /*#__PURE__*/React__namespace.createElement("button", {
457
+ onClick: copyState === 'NoCopy' ? () => {
458
+ navigator.clipboard.writeText(SuperJSON__default["default"].stringify(value)).then(() => {
459
+ setCopyState('SuccessCopy');
460
+ setTimeout(() => {
461
+ setCopyState('NoCopy');
462
+ }, 1500);
463
+ }, err => {
464
+ console.error('Failed to copy: ', err);
465
+ setCopyState('ErrorCopy');
466
+ setTimeout(() => {
467
+ setCopyState('NoCopy');
468
+ }, 1500);
469
+ });
470
+ } : undefined,
471
+ style: {
472
+ cursor: 'pointer',
473
+ color: 'inherit',
474
+ font: 'inherit',
475
+ outline: 'inherit',
476
+ background: 'transparent',
477
+ border: 'none',
478
+ padding: 0
479
+ }
480
+ }, copyState === 'NoCopy' ? /*#__PURE__*/React__namespace.createElement(Copier, null) : copyState === 'SuccessCopy' ? /*#__PURE__*/React__namespace.createElement(CopiedCopier, null) : /*#__PURE__*/React__namespace.createElement(ErrorCopier, null));
481
+ };
452
482
  const Value = styled('span', (_props, theme) => ({
453
483
  color: theme.danger
454
484
  }));
@@ -473,6 +503,68 @@ const Expander = ({
473
503
  }
474
504
  }, "\u25B6");
475
505
 
506
+ const Copier = () => /*#__PURE__*/React__namespace.createElement("span", {
507
+ "aria-label": "Copy object to clipboard",
508
+ title: "Copy object to clipboard",
509
+ style: {
510
+ paddingLeft: '1em'
511
+ }
512
+ }, /*#__PURE__*/React__namespace.createElement("svg", {
513
+ height: "12",
514
+ viewBox: "0 0 16 12",
515
+ width: "10"
516
+ }, /*#__PURE__*/React__namespace.createElement("path", {
517
+ fill: "currentColor",
518
+ 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"
519
+ }), /*#__PURE__*/React__namespace.createElement("path", {
520
+ fill: "currentColor",
521
+ 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"
522
+ })));
523
+
524
+ const ErrorCopier = () => /*#__PURE__*/React__namespace.createElement("span", {
525
+ "aria-label": "Failed copying to clipboard",
526
+ title: "Failed copying to clipboard",
527
+ style: {
528
+ paddingLeft: '1em',
529
+ display: 'flex',
530
+ alignItems: 'center'
531
+ }
532
+ }, /*#__PURE__*/React__namespace.createElement("svg", {
533
+ height: "12",
534
+ viewBox: "0 0 16 12",
535
+ width: "10",
536
+ display: "block"
537
+ }, /*#__PURE__*/React__namespace.createElement("path", {
538
+ fill: "red",
539
+ 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"
540
+ })), /*#__PURE__*/React__namespace.createElement("span", {
541
+ style: {
542
+ color: 'red',
543
+ fontSize: '12px',
544
+ paddingLeft: '4px',
545
+ position: 'relative',
546
+ top: '2px'
547
+ }
548
+ }, "See console"));
549
+
550
+ const CopiedCopier = () => /*#__PURE__*/React__namespace.createElement("span", {
551
+ "aria-label": "Object copied to clipboard",
552
+ title: "Object copied to clipboard",
553
+ style: {
554
+ paddingLeft: '1em',
555
+ display: 'inline-block',
556
+ verticalAlign: 'middle'
557
+ }
558
+ }, /*#__PURE__*/React__namespace.createElement("svg", {
559
+ height: "16",
560
+ viewBox: "0 0 16 16",
561
+ width: "16",
562
+ display: "block"
563
+ }, /*#__PURE__*/React__namespace.createElement("path", {
564
+ fill: "green",
565
+ 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"
566
+ })));
567
+
476
568
  /**
477
569
  * Chunk elements in the array by size
478
570
  *
@@ -502,6 +594,7 @@ const DefaultRenderer = ({
502
594
  subEntryPages = [],
503
595
  type,
504
596
  expanded = false,
597
+ copyable = false,
505
598
  toggleExpanded,
506
599
  pageSize
507
600
  }) => {
@@ -512,7 +605,9 @@ const DefaultRenderer = ({
512
605
  onClick: () => toggleExpanded()
513
606
  }, /*#__PURE__*/React__namespace.createElement(Expander, {
514
607
  expanded: expanded
515
- }), " ", label, ' ', /*#__PURE__*/React__namespace.createElement(Info, null, String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : '', subEntries.length, " ", subEntries.length > 1 ? "items" : "item")), expanded ? subEntryPages.length === 1 ? /*#__PURE__*/React__namespace.createElement(SubEntries, null, subEntries.map(handleEntry)) : /*#__PURE__*/React__namespace.createElement(SubEntries, null, subEntryPages.map((entries, index) => /*#__PURE__*/React__namespace.createElement("div", {
608
+ }), " ", label, ' ', /*#__PURE__*/React__namespace.createElement(Info, null, String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : '', subEntries.length, " ", subEntries.length > 1 ? "items" : "item")), copyable ? /*#__PURE__*/React__namespace.createElement(CopyButton, {
609
+ value: value
610
+ }) : null, expanded ? subEntryPages.length === 1 ? /*#__PURE__*/React__namespace.createElement(SubEntries, null, subEntries.map(handleEntry)) : /*#__PURE__*/React__namespace.createElement(SubEntries, null, subEntryPages.map((entries, index) => /*#__PURE__*/React__namespace.createElement("div", {
516
611
  key: index
517
612
  }, /*#__PURE__*/React__namespace.createElement(Entry, null, /*#__PURE__*/React__namespace.createElement(LabelButton, {
518
613
  onClick: () => setExpandedPages(old => old.includes(index) ? old.filter(d => d !== index) : [...old, index])
@@ -530,6 +625,7 @@ function Explorer({
530
625
  defaultExpanded,
531
626
  renderer = DefaultRenderer,
532
627
  pageSize = 100,
628
+ copyable = false,
533
629
  ...rest
534
630
  }) {
535
631
  const [expanded, setExpanded] = React__namespace.useState(Boolean(defaultExpanded));
@@ -571,13 +667,15 @@ function Explorer({
571
667
  handleEntry: entry => /*#__PURE__*/React__namespace.createElement(Explorer, _extends({
572
668
  key: entry.label,
573
669
  value: value,
574
- renderer: renderer
670
+ renderer: renderer,
671
+ copyable: copyable
575
672
  }, rest, entry)),
576
673
  type,
577
674
  subEntries,
578
675
  subEntryPages,
579
676
  value,
580
677
  expanded,
678
+ copyable,
581
679
  toggleExpanded,
582
680
  pageSize,
583
681
  ...rest
@@ -1254,7 +1352,8 @@ const ActiveQuery = ({
1254
1352
  }, /*#__PURE__*/React__namespace.createElement(Explorer, {
1255
1353
  label: "Data",
1256
1354
  value: activeQueryState.data,
1257
- defaultExpanded: {}
1355
+ defaultExpanded: {},
1356
+ copyable: true
1258
1357
  })), /*#__PURE__*/React__namespace.createElement("div", {
1259
1358
  style: {
1260
1359
  background: defaultTheme.backgroundAlt,