@sanity/cross-dataset-duplicator 1.2.3 → 1.3.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/dist/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import React, { useState, useEffect, useCallback, createContext, useContext } from 'react';
4
4
  import { ArrowRightIcon, SearchIcon, LaunchIcon } from '@sanity/icons';
5
5
  import { useSecrets, SettingsView } from '@sanity/studio-secrets';
6
- import { Card, Flex, Button, Badge, Tooltip, Box, Text, useTheme, Container, Stack, Label, Select, Checkbox, Grid, TextInput, Spinner } from '@sanity/ui';
6
+ import { Card, Flex, Button, Badge, Tooltip, Box, Text, useTheme, Container, Stack, Label, Select, Checkbox, Spinner, Grid, TextInput } from '@sanity/ui';
7
7
  import mapLimit from 'async/mapLimit';
8
8
  import asyncify from 'async/asyncify';
9
9
  import { extractWithPath } from '@sanity/mutator';
@@ -120,6 +120,7 @@ function SelectButtons(props) {
120
120
  shadow: 1,
121
121
  children: /* @__PURE__ */jsx(Flex, {
122
122
  gap: 2,
123
+ wrap: "wrap",
123
124
  children: buttons.map((action, actionIndex) => action ? /* @__PURE__ */jsx(Button, {
124
125
  fontSize: 1,
125
126
  mode: "bleed",
@@ -385,7 +386,7 @@ function Duplicator(props) {
385
386
  setProgress([currentProgress, assetsCount]);
386
387
  setMessage({
387
388
  text: "Duplicating...",
388
- tone: "default"
389
+ tone: "transparent"
389
390
  });
390
391
  const destinationClient = originClient.withConfig({
391
392
  ...clientConfig,
@@ -416,6 +417,8 @@ function Duplicator(props) {
416
417
  });
417
418
  }
418
419
  transactionDocs.push(assetDoc);
420
+ doc.url = assetDoc.url;
421
+ doc.path = assetDoc.path;
419
422
  });
420
423
  currentProgress += 1;
421
424
  setMessage({
@@ -535,89 +538,89 @@ function Duplicator(props) {
535
538
  width: 1,
536
539
  children: /* @__PURE__ */jsx(Card, {
537
540
  border: true,
538
- children: /* @__PURE__ */jsx(Stack, {
539
- children: /* @__PURE__ */jsxs(Fragment, {
540
- children: [/* @__PURE__ */jsx(Card, {
541
- borderBottom: true,
542
- padding: 4,
543
- style: stickyStyles(isDarkMode),
544
- children: /* @__PURE__ */jsxs(Stack, {
545
- space: 4,
546
- children: [/* @__PURE__ */jsxs(Flex, {
547
- gap: 3,
548
- children: [/* @__PURE__ */jsxs(Stack, {
549
- style: {
550
- flex: 1
551
- },
552
- space: 3,
553
- children: [/* @__PURE__ */jsx(Label, {
554
- children: "Duplicate from"
555
- }), /* @__PURE__ */jsx(Select, {
556
- readOnly: true,
557
- value: (_c = workspacesOptions.find(space => space.disabled)) == null ? void 0 : _c.name,
558
- children: workspacesOptions.filter(space => space.disabled).map(space => {
559
- var _a2;
560
- return /* @__PURE__ */jsxs("option", {
561
- value: space.name,
562
- disabled: space.disabled,
563
- children: [(_a2 = space.title) != null ? _a2 : space.name, hasMultipleProjectIds ? " (".concat(space.projectId, ")") : ""]
564
- }, space.name);
565
- })
566
- })]
567
- }), /* @__PURE__ */jsx(Box, {
568
- padding: 4,
569
- paddingTop: 5,
570
- paddingBottom: 0,
571
- children: /* @__PURE__ */jsx(Text, {
572
- size: 3,
573
- children: /* @__PURE__ */jsx(ArrowRightIcon, {})
541
+ children: /* @__PURE__ */jsxs(Stack, {
542
+ children: [/* @__PURE__ */jsx(Card, {
543
+ padding: 4,
544
+ style: stickyStyles(isDarkMode),
545
+ children: /* @__PURE__ */jsxs(Stack, {
546
+ space: 4,
547
+ children: [/* @__PURE__ */jsxs(Flex, {
548
+ gap: 3,
549
+ children: [/* @__PURE__ */jsxs(Stack, {
550
+ style: {
551
+ flex: 1
552
+ },
553
+ space: 3,
554
+ children: [/* @__PURE__ */jsx(Label, {
555
+ children: "Duplicate from"
556
+ }), /* @__PURE__ */jsx(Select, {
557
+ readOnly: true,
558
+ value: (_c = workspacesOptions.find(space => space.disabled)) == null ? void 0 : _c.name,
559
+ children: workspacesOptions.filter(space => space.disabled).map(space => {
560
+ var _a2;
561
+ return /* @__PURE__ */jsxs("option", {
562
+ value: space.name,
563
+ disabled: space.disabled,
564
+ children: [(_a2 = space.title) != null ? _a2 : space.name, hasMultipleProjectIds ? " (".concat(space.projectId, ")") : ""]
565
+ }, space.name);
574
566
  })
575
- }), /* @__PURE__ */jsxs(Stack, {
576
- style: {
577
- flex: 1
578
- },
579
- space: 3,
580
- children: [/* @__PURE__ */jsx(Label, {
581
- children: "To Destination"
582
- }), /* @__PURE__ */jsx(Select, {
583
- onChange: handleChange,
584
- children: workspacesOptions.map(space => {
585
- var _a2;
586
- return /* @__PURE__ */jsxs("option", {
587
- value: space.name,
588
- disabled: space.disabled,
589
- children: [(_a2 = space.title) != null ? _a2 : space.name, hasMultipleProjectIds ? " (".concat(space.projectId, ")") : "", space.disabled ? " (Current)" : ""]
590
- }, space.name);
591
- })
592
- })]
593
567
  })]
594
- }), isDuplicating && /* @__PURE__ */jsx(Card, {
595
- border: true,
596
- radius: 2,
597
- children: /* @__PURE__ */jsx(Card, {
598
- style: {
599
- width: "100%",
600
- transform: "scaleX(".concat(progress[0] / progress[1], ")"),
601
- transformOrigin: "left",
602
- transition: "transform .2s ease",
603
- boxSizing: "border-box"
604
- },
605
- padding: 1,
606
- tone: "positive"
568
+ }), /* @__PURE__ */jsx(Box, {
569
+ padding: 4,
570
+ paddingTop: 5,
571
+ paddingBottom: 0,
572
+ children: /* @__PURE__ */jsx(Text, {
573
+ size: 3,
574
+ children: /* @__PURE__ */jsx(ArrowRightIcon, {})
607
575
  })
608
- }), payload.length > 0 && /* @__PURE__ */jsxs(Fragment, {
576
+ }), /* @__PURE__ */jsxs(Stack, {
577
+ style: {
578
+ flex: 1
579
+ },
580
+ space: 3,
609
581
  children: [/* @__PURE__ */jsx(Label, {
610
- children: headingText
611
- }), /* @__PURE__ */jsx(SelectButtons, {
612
- payload,
613
- setPayload
582
+ children: "To Destination"
583
+ }), /* @__PURE__ */jsx(Select, {
584
+ onChange: handleChange,
585
+ children: workspacesOptions.map(space => {
586
+ var _a2;
587
+ return /* @__PURE__ */jsxs("option", {
588
+ value: space.name,
589
+ disabled: space.disabled,
590
+ children: [(_a2 = space.title) != null ? _a2 : space.name, hasMultipleProjectIds ? " (".concat(space.projectId, ")") : "", space.disabled ? " (Current)" : ""]
591
+ }, space.name);
592
+ })
614
593
  })]
615
594
  })]
616
- })
617
- }), message && /* @__PURE__ */jsx(Box, {
618
- paddingX: 4,
619
- paddingTop: 4,
620
- children: /* @__PURE__ */jsx(Card, {
595
+ }), isDuplicating && /* @__PURE__ */jsx(Card, {
596
+ border: true,
597
+ radius: 2,
598
+ children: /* @__PURE__ */jsx(Card, {
599
+ style: {
600
+ width: "100%",
601
+ transform: "scaleX(".concat(progress[0] / progress[1], ")"),
602
+ transformOrigin: "left",
603
+ transition: "transform .2s ease",
604
+ boxSizing: "border-box"
605
+ },
606
+ padding: 1,
607
+ tone: "positive"
608
+ })
609
+ }), payload.length > 0 && /* @__PURE__ */jsxs(Fragment, {
610
+ children: [/* @__PURE__ */jsx(Label, {
611
+ children: headingText
612
+ }), /* @__PURE__ */jsx(SelectButtons, {
613
+ payload,
614
+ setPayload
615
+ })]
616
+ })]
617
+ })
618
+ }), /* @__PURE__ */jsx(Card, {
619
+ borderTop: true,
620
+ padding: 4,
621
+ children: /* @__PURE__ */jsxs(Stack, {
622
+ space: 3,
623
+ children: [message && /* @__PURE__ */jsx(Card, {
621
624
  padding: 3,
622
625
  radius: 2,
623
626
  shadow: 1,
@@ -626,89 +629,90 @@ function Duplicator(props) {
626
629
  size: 1,
627
630
  children: message.text
628
631
  })
629
- })
630
- }), payload.length > 0 && /* @__PURE__ */jsx(Stack, {
631
- padding: 4,
632
- space: 3,
633
- children: payload.map((_ref5, index) => {
634
- let {
635
- doc,
636
- include,
637
- status,
638
- hasDraft
639
- } = _ref5;
640
- const schemaType = schema.get(doc._type);
641
- return /* @__PURE__ */jsxs(React.Fragment, {
642
- children: [/* @__PURE__ */jsxs(Flex, {
643
- align: "center",
644
- children: [/* @__PURE__ */jsx(Checkbox, {
645
- checked: include,
646
- onChange: () => handleCheckbox(doc._id)
647
- }), /* @__PURE__ */jsx(Box, {
648
- flex: 1,
649
- paddingX: 3,
650
- children: schemaType ? /* @__PURE__ */jsx(Preview, {
651
- value: doc,
652
- schemaType
653
- }) : /* @__PURE__ */jsx(Card, {
654
- tone: "caution",
655
- children: "Invalid schema type"
656
- })
657
- }), /* @__PURE__ */jsxs(Flex, {
632
+ }), payload.length > 0 ? /* @__PURE__ */jsx(Stack, {
633
+ children: payload.map((_ref5, index) => {
634
+ let {
635
+ doc,
636
+ include,
637
+ status,
638
+ hasDraft
639
+ } = _ref5;
640
+ const schemaType = schema.get(doc._type);
641
+ return /* @__PURE__ */jsxs(React.Fragment, {
642
+ children: [/* @__PURE__ */jsxs(Flex, {
658
643
  align: "center",
659
- gap: 2,
660
- children: [hasDraft ? /* @__PURE__ */jsx(StatusBadge, {
661
- status: "UNPUBLISHED",
662
- isAsset: false
663
- }) : null, /* @__PURE__ */jsx(StatusBadge, {
664
- status,
665
- isAsset: isAssetId(doc._id)
644
+ children: [/* @__PURE__ */jsx(Checkbox, {
645
+ checked: include,
646
+ onChange: () => handleCheckbox(doc._id)
647
+ }), /* @__PURE__ */jsx(Box, {
648
+ flex: 1,
649
+ paddingX: 3,
650
+ children: schemaType ? /* @__PURE__ */jsx(Preview, {
651
+ value: doc,
652
+ schemaType
653
+ }) : /* @__PURE__ */jsx(Card, {
654
+ tone: "caution",
655
+ children: "Invalid schema type"
656
+ })
657
+ }), /* @__PURE__ */jsxs(Flex, {
658
+ align: "center",
659
+ gap: 2,
660
+ children: [hasDraft ? /* @__PURE__ */jsx(StatusBadge, {
661
+ status: "UNPUBLISHED",
662
+ isAsset: false
663
+ }) : null, /* @__PURE__ */jsx(StatusBadge, {
664
+ status,
665
+ isAsset: isAssetId(doc._id)
666
+ })]
666
667
  })]
668
+ }), (doc == null ? void 0 : doc.extension) === "svg" && index === firstSvgIndex && /* @__PURE__ */jsx(Card, {
669
+ padding: 3,
670
+ radius: 2,
671
+ shadow: 1,
672
+ tone: "caution",
673
+ children: /* @__PURE__ */jsxs(Text, {
674
+ size: 1,
675
+ children: ["Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ", /* @__PURE__ */jsx("code", {
676
+ children: "_id"
677
+ }), "'s at the destination. The newly generated ", /* @__PURE__ */jsx("code", {
678
+ children: "_id"
679
+ }), " will be the same in each duplication, but it will never be the same ", /* @__PURE__ */jsx("code", {
680
+ children: "_id"
681
+ }), " as the first time this Asset was uploaded. References to the asset will be updated to use the new ", /* @__PURE__ */jsx("code", {
682
+ children: "_id"
683
+ }), "."]
684
+ })
667
685
  })]
668
- }), (doc == null ? void 0 : doc.extension) === "svg" && index === firstSvgIndex && /* @__PURE__ */jsx(Card, {
669
- padding: 3,
670
- radius: 2,
671
- shadow: 1,
672
- tone: "caution",
673
- children: /* @__PURE__ */jsxs(Text, {
674
- size: 1,
675
- children: ["Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ", /* @__PURE__ */jsx("code", {
676
- children: "_id"
677
- }), "'s at the destination. The newly generated ", /* @__PURE__ */jsx("code", {
678
- children: "_id"
679
- }), " will be the same in each duplication, but it will never be the same ", /* @__PURE__ */jsx("code", {
680
- children: "_id"
681
- }), " as the first time this Asset was uploaded. References to the asset will be updated to use the new", " ", /* @__PURE__ */jsx("code", {
682
- children: "_id"
683
- }), "."]
684
- })
685
- })]
686
- }, doc._id);
687
- })
688
- }), /* @__PURE__ */jsxs(Stack, {
689
- space: 2,
690
- padding: 4,
691
- paddingTop: 0,
692
- children: [hasReferences && /* @__PURE__ */jsx(Button, {
693
- fontSize: 2,
694
- padding: 4,
695
- tone: "positive",
696
- mode: "ghost",
697
- icon: SearchIcon,
698
- onClick: handleReferences,
699
- text: "Gather References",
700
- disabled: isDuplicating || !selectedTotal || isGathering
701
- }), /* @__PURE__ */jsx(Button, {
702
- fontSize: 2,
686
+ }, doc._id);
687
+ })
688
+ }) : /* @__PURE__ */jsx(Flex, {
703
689
  padding: 4,
704
- tone: "positive",
705
- icon: LaunchIcon,
706
- onClick: handleDuplicate,
707
- text: buttonText,
708
- disabled: isDuplicating || !selectedTotal || isGathering
690
+ align: "center",
691
+ justify: "center",
692
+ children: /* @__PURE__ */jsx(Spinner, {})
693
+ }), /* @__PURE__ */jsxs(Stack, {
694
+ space: 2,
695
+ children: [hasReferences && /* @__PURE__ */jsx(Button, {
696
+ fontSize: 2,
697
+ padding: 4,
698
+ tone: "positive",
699
+ mode: "ghost",
700
+ icon: SearchIcon,
701
+ onClick: handleReferences,
702
+ text: "Gather References",
703
+ disabled: isDuplicating || !selectedTotal || isGathering
704
+ }), /* @__PURE__ */jsx(Button, {
705
+ fontSize: 2,
706
+ padding: 4,
707
+ tone: "positive",
708
+ icon: LaunchIcon,
709
+ onClick: handleDuplicate,
710
+ text: buttonText,
711
+ disabled: isDuplicating || !selectedTotal || isGathering
712
+ })]
709
713
  })]
710
- })]
711
- })
714
+ })
715
+ })]
712
716
  })
713
717
  })
714
718
  });
@@ -744,67 +748,68 @@ function DuplicatorQuery(props) {
744
748
  handleSubmit();
745
749
  }
746
750
  }, []);
747
- return /* @__PURE__ */jsx(Container, {
748
- width: [1, 1, 1, 3],
751
+ return /* @__PURE__ */jsx(Card, {
749
752
  padding: [0, 0, 0, 5],
750
- children: /* @__PURE__ */jsxs(Grid, {
751
- columns: [1, 1, 1, 2],
752
- gap: [1, 1, 1, 4],
753
- children: [/* @__PURE__ */jsx(Box, {
754
- padding: [2, 2, 2, 0],
755
- children: /* @__PURE__ */jsx(Card, {
756
- padding: 4,
757
- radius: 3,
758
- border: true,
759
- children: /* @__PURE__ */jsxs(Stack, {
760
- space: 4,
761
- children: [/* @__PURE__ */jsx(Box, {
762
- children: /* @__PURE__ */jsx(Label, {
763
- children: "Initial Documents Query"
764
- })
765
- }), /* @__PURE__ */jsx(Box, {
766
- children: /* @__PURE__ */jsx(Text, {
767
- children: "Start with a valid GROQ query to load initial documents. The query will need to return an Array of Objects. Drafts will be removed from the results."
768
- })
769
- }), /* @__PURE__ */jsx("form", {
770
- onSubmit: handleSubmit,
771
- children: /* @__PURE__ */jsxs(Flex, {
772
- children: [/* @__PURE__ */jsx(Box, {
773
- flex: 1,
774
- paddingRight: 2,
775
- children: /* @__PURE__ */jsx(TextInput, {
776
- style: {
777
- fontFamily: "monospace"
778
- },
779
- fontSize: 2,
780
- onChange: event => setValue(event.currentTarget.value),
781
- padding: 4,
782
- placeholder: "*[_type == \"article\"]",
783
- value: value != null ? value : ""
784
- })
785
- }), /* @__PURE__ */jsx(Button, {
786
- padding: 2,
787
- paddingX: 4,
788
- tone: "primary",
789
- onClick: handleSubmit,
790
- text: "Query",
791
- disabled: !value
792
- })]
793
- })
794
- })]
753
+ children: /* @__PURE__ */jsx(Container, {
754
+ children: /* @__PURE__ */jsxs(Grid, {
755
+ columns: [1, 1, 1, 2],
756
+ gap: [1, 1, 1, 4],
757
+ children: [/* @__PURE__ */jsx(Box, {
758
+ padding: [2, 2, 2, 0],
759
+ children: /* @__PURE__ */jsx(Card, {
760
+ padding: 4,
761
+ radius: 3,
762
+ border: true,
763
+ children: /* @__PURE__ */jsxs(Stack, {
764
+ space: 4,
765
+ children: [/* @__PURE__ */jsx(Box, {
766
+ children: /* @__PURE__ */jsx(Label, {
767
+ children: "Initial Documents Query"
768
+ })
769
+ }), /* @__PURE__ */jsx(Box, {
770
+ children: /* @__PURE__ */jsx(Text, {
771
+ children: "Start with a valid GROQ query to load initial documents. The query will need to return an Array of Objects. Drafts will be removed from the results."
772
+ })
773
+ }), /* @__PURE__ */jsx("form", {
774
+ onSubmit: handleSubmit,
775
+ children: /* @__PURE__ */jsxs(Flex, {
776
+ children: [/* @__PURE__ */jsx(Box, {
777
+ flex: 1,
778
+ paddingRight: 2,
779
+ children: /* @__PURE__ */jsx(TextInput, {
780
+ style: {
781
+ fontFamily: "monospace"
782
+ },
783
+ fontSize: 2,
784
+ onChange: event => setValue(event.currentTarget.value),
785
+ padding: 4,
786
+ placeholder: "*[_type == \"article\"]",
787
+ value: value != null ? value : ""
788
+ })
789
+ }), /* @__PURE__ */jsx(Button, {
790
+ padding: 2,
791
+ paddingX: 4,
792
+ tone: "primary",
793
+ onClick: handleSubmit,
794
+ text: "Query",
795
+ disabled: !value
796
+ })]
797
+ })
798
+ })]
799
+ })
795
800
  })
796
- })
797
- }), !((_a = initialData.docs) == null ? void 0 : _a.length) || initialData.docs.length < 1 && /* @__PURE__ */jsx(Container, {
798
- width: 1,
799
- children: /* @__PURE__ */jsx(Card, {
800
- padding: 5,
801
- children: value ? "No Documents registered to the Schema match this query" : "Start with a valid GROQ query"
802
- })
803
- }), ((_b = initialData.docs) == null ? void 0 : _b.length) > 0 && /* @__PURE__ */jsx(Duplicator, {
804
- docs: initialData.docs,
805
- token,
806
- pluginConfig
807
- })]
801
+ }), !((_a = initialData.docs) == null ? void 0 : _a.length) || initialData.docs.length < 1 && /* @__PURE__ */jsx(Container, {
802
+ width: 1,
803
+ children: /* @__PURE__ */jsx(Card, {
804
+ padding: 5,
805
+ children: value ? "No Documents registered to the Schema match this query" : "Start with a valid GROQ query"
806
+ })
807
+ }), ((_b = initialData.docs) == null ? void 0 : _b.length) > 0 && /* @__PURE__ */jsx(Duplicator, {
808
+ docs: initialData.docs,
809
+ token,
810
+ pluginConfig
811
+ })]
812
+ })
808
813
  })
809
814
  });
810
815
  }