@sanity/cross-dataset-duplicator 1.5.1 → 2.0.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.
- package/dist/index.d.ts +42 -61
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +720 -492
- package/dist/index.js.map +1 -1
- package/package.json +38 -77
- package/dist/index.d.mts +0 -81
- package/dist/index.mjs +0 -654
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/actions/DuplicateToAction.tsx +0 -34
- package/src/components/CrossDatasetDuplicator.tsx +0 -93
- package/src/components/CrossDatasetDuplicatorAction.tsx +0 -13
- package/src/components/CrossDatasetDuplicatorTool.tsx +0 -17
- package/src/components/Duplicator.tsx +0 -568
- package/src/components/DuplicatorQuery.tsx +0 -144
- package/src/components/DuplicatorWrapper.tsx +0 -67
- package/src/components/Feedback.tsx +0 -18
- package/src/components/ResetSecret.tsx +0 -30
- package/src/components/SelectButtons.tsx +0 -84
- package/src/components/StatusBadge.tsx +0 -111
- package/src/context/ConfigProvider.tsx +0 -30
- package/src/helpers/constants.ts +0 -12
- package/src/helpers/getDocumentsInArray.ts +0 -86
- package/src/helpers/index.ts +0 -19
- package/src/index.ts +0 -5
- package/src/plugin.tsx +0 -31
- package/src/tool/index.ts +0 -14
- package/src/types/index.ts +0 -27
- package/v2-incompatible.js +0 -11
package/dist/index.js
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
2
|
+
import { useClient, useSchema, useWorkspaces, Preview, definePlugin } from "sanity";
|
|
3
|
+
import { InfoOutlineIcon, ArrowRightIcon, SearchIcon, LaunchIcon } from "@sanity/icons";
|
|
4
|
+
import { createContext, useContext, useState, useEffectEvent, useEffect, Fragment } from "react";
|
|
5
|
+
import { c } from "react/compiler-runtime";
|
|
6
|
+
import { useSecrets, SettingsView } from "@sanity/studio-secrets";
|
|
7
|
+
import { Card, Text, Button, Flex, Badge, Tooltip, Box, useTheme, Select, Stack, Checkbox, Spinner, Container, Label, Grid, TextInput } from "@sanity/ui";
|
|
8
|
+
import { isAssetId, isSanityFileAsset } from "@sanity/asset-utils";
|
|
9
|
+
import { extractWithPath } from "@sanity/mutator";
|
|
10
|
+
import { getTheme_v2 } from "@sanity/ui/theme";
|
|
11
|
+
import { dset } from "dset";
|
|
12
|
+
const SECRET_NAMESPACE = "CrossDatasetDuplicator", DEFAULT_CONFIG = {
|
|
13
|
+
apiVersion: "2025-02-19",
|
|
14
|
+
tool: !0,
|
|
15
|
+
types: [],
|
|
16
|
+
filter: "",
|
|
17
|
+
follow: ["outbound"],
|
|
18
|
+
queries: []
|
|
19
|
+
}, CrossDatasetDuplicatorContext = createContext(DEFAULT_CONFIG);
|
|
20
|
+
function useCrossDatasetDuplicatorConfig() {
|
|
21
|
+
return useContext(CrossDatasetDuplicatorContext);
|
|
22
|
+
}
|
|
23
|
+
function ConfigProvider(props) {
|
|
24
|
+
const $ = c(8);
|
|
25
|
+
let T0, t0, t1;
|
|
26
|
+
if ($[0] !== props) {
|
|
27
|
+
const {
|
|
28
|
+
pluginConfig,
|
|
29
|
+
...rest
|
|
30
|
+
} = props;
|
|
31
|
+
T0 = CrossDatasetDuplicatorContext.Provider, t0 = pluginConfig, t1 = props.renderDefault(rest), $[0] = props, $[1] = T0, $[2] = t0, $[3] = t1;
|
|
32
|
+
} else
|
|
33
|
+
T0 = $[1], t0 = $[2], t1 = $[3];
|
|
34
|
+
let t2;
|
|
35
|
+
return $[4] !== T0 || $[5] !== t0 || $[6] !== t1 ? (t2 = /* @__PURE__ */ jsx(T0, { value: t0, children: t1 }), $[4] = T0, $[5] = t0, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
6
36
|
}
|
|
7
|
-
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), mapLimit__default = /* @__PURE__ */ _interopDefaultCompat(mapLimit), asyncify__default = /* @__PURE__ */ _interopDefaultCompat(asyncify);
|
|
8
37
|
function createInitialMessage(docCount = 0, refsCount = 0) {
|
|
9
|
-
return [
|
|
10
|
-
docCount === 1 ? "This Document contains" : `These ${docCount} Documents contain`,
|
|
11
|
-
refsCount === 1 ? "1 Reference." : `${refsCount} References.`,
|
|
12
|
-
refsCount === 1 ? "That Document" : "Those Documents",
|
|
13
|
-
"may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."
|
|
14
|
-
].join(" ");
|
|
38
|
+
return [docCount === 1 ? "This Document contains" : `These ${docCount} Documents contain`, refsCount === 1 ? "1 Reference." : `${refsCount} References.`, refsCount === 1 ? "That Document" : "Those Documents", "may have References too. If referenced Documents do not exist at the target Destination, this transaction will fail."].join(" ");
|
|
15
39
|
}
|
|
16
40
|
const stickyStyles = (isDarkMode = !0) => ({
|
|
17
41
|
position: "sticky",
|
|
@@ -20,21 +44,26 @@ const stickyStyles = (isDarkMode = !0) => ({
|
|
|
20
44
|
backgroundColor: isDarkMode ? "rgba(10,10,10,0.95)" : "rgba(255,255,255,0.95)"
|
|
21
45
|
});
|
|
22
46
|
async function getDocumentsInArray(options) {
|
|
23
|
-
const {
|
|
47
|
+
const {
|
|
48
|
+
fetchIds,
|
|
49
|
+
client,
|
|
50
|
+
pluginConfig,
|
|
51
|
+
currentIds,
|
|
52
|
+
projection
|
|
53
|
+
} = options, collection = [], query = `*[${["_id in $fetchIds", pluginConfig.filter].filter(Boolean).join(" && ")}]${projection ?? ""}`, data = await client.fetch(query, {
|
|
24
54
|
fetchIds: fetchIds ?? []
|
|
25
55
|
});
|
|
26
56
|
if (!data?.length)
|
|
27
57
|
return [];
|
|
28
|
-
const localCurrentIds = currentIds ?? /* @__PURE__ */ new Set(), newDataIds = new Set(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
58
|
+
const localCurrentIds = currentIds ?? /* @__PURE__ */ new Set(), newDataIds = new Set(data.map((dataDoc) => dataDoc._id).filter((id) => currentIds?.size ? !localCurrentIds.has(id) : !!id));
|
|
59
|
+
if (newDataIds.size) {
|
|
60
|
+
collection.push(...data);
|
|
61
|
+
for (const id of newDataIds)
|
|
62
|
+
localCurrentIds.add(id);
|
|
63
|
+
await Promise.all(data.map(async (doc) => {
|
|
64
|
+
const references = extractWithPath(".._ref", doc).flatMap((ref) => typeof ref.value == "string" ? [ref.value] : []);
|
|
34
65
|
if (references.length) {
|
|
35
|
-
const newReferenceIds = new Set(
|
|
36
|
-
references.filter((ref) => !localCurrentIds.has(ref))
|
|
37
|
-
);
|
|
66
|
+
const newReferenceIds = new Set(references.filter((ref) => !localCurrentIds.has(ref)));
|
|
38
67
|
if (newReferenceIds.size) {
|
|
39
68
|
const referenceDocs = await getDocumentsInArray({
|
|
40
69
|
fetchIds: Array.from(newReferenceIds),
|
|
@@ -45,60 +74,92 @@ async function getDocumentsInArray(options) {
|
|
|
45
74
|
referenceDocs?.length && collection.push(...referenceDocs);
|
|
46
75
|
}
|
|
47
76
|
}
|
|
48
|
-
})
|
|
49
|
-
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
const seenIds = /* @__PURE__ */ new Set(), uniqueCollection = [];
|
|
80
|
+
for (const doc of collection)
|
|
81
|
+
doc && !seenIds.has(doc._id) && (seenIds.add(doc._id), uniqueCollection.push(doc));
|
|
82
|
+
return uniqueCollection;
|
|
50
83
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
function Feedback(props) {
|
|
85
|
+
const $ = c(5), {
|
|
86
|
+
children,
|
|
87
|
+
tone: t0
|
|
88
|
+
} = props, tone = t0 === void 0 ? "caution" : t0;
|
|
89
|
+
let t1;
|
|
90
|
+
$[0] !== children ? (t1 = /* @__PURE__ */ jsx(Text, { size: 1, children }), $[0] = children, $[1] = t1) : t1 = $[1];
|
|
91
|
+
let t2;
|
|
92
|
+
return $[2] !== t1 || $[3] !== tone ? (t2 = /* @__PURE__ */ jsx(Card, { padding: 3, radius: 2, shadow: 1, tone, children: t1 }), $[2] = t1, $[3] = tone, $[4] = t2) : t2 = $[4], t2;
|
|
93
|
+
}
|
|
94
|
+
const buttons = [{
|
|
95
|
+
label: "All",
|
|
96
|
+
action: "ALL"
|
|
97
|
+
}, {
|
|
98
|
+
label: "None",
|
|
99
|
+
action: "NONE"
|
|
100
|
+
}, {
|
|
101
|
+
divider: "divider-1"
|
|
102
|
+
}, {
|
|
103
|
+
label: "New",
|
|
104
|
+
action: "NEW"
|
|
105
|
+
}, {
|
|
106
|
+
label: "Existing",
|
|
107
|
+
action: "EXISTING"
|
|
108
|
+
}, {
|
|
109
|
+
label: "Older",
|
|
110
|
+
action: "OLDER"
|
|
111
|
+
}, {
|
|
112
|
+
divider: "divider-2"
|
|
113
|
+
}, {
|
|
114
|
+
label: "Documents",
|
|
115
|
+
action: "DOCUMENTS"
|
|
116
|
+
}, {
|
|
117
|
+
label: "Assets",
|
|
118
|
+
action: "ASSETS"
|
|
119
|
+
}];
|
|
120
|
+
function shouldInclude(item, action) {
|
|
121
|
+
switch (action) {
|
|
122
|
+
case "ALL":
|
|
123
|
+
return !0;
|
|
124
|
+
case "NONE":
|
|
125
|
+
return !1;
|
|
126
|
+
case "NEW":
|
|
127
|
+
return item.status === "CREATE";
|
|
128
|
+
case "EXISTING":
|
|
129
|
+
return item.status === "EXISTS";
|
|
130
|
+
case "OLDER":
|
|
131
|
+
return item.status === "OVERWRITE";
|
|
132
|
+
case "ASSETS":
|
|
133
|
+
return isAssetId(item.doc._id);
|
|
134
|
+
case "DOCUMENTS":
|
|
135
|
+
return !isAssetId(item.doc._id);
|
|
136
|
+
default:
|
|
137
|
+
return item.include;
|
|
84
138
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
139
|
+
}
|
|
140
|
+
function SelectButtons(props) {
|
|
141
|
+
const $ = c(10), {
|
|
142
|
+
payload,
|
|
143
|
+
setPayload
|
|
144
|
+
} = props;
|
|
145
|
+
let t0;
|
|
146
|
+
$[0] !== payload ? (t0 = () => payload.length && payload.every(_temp$2) ? ["ALL"] : [], $[0] = payload, $[1] = t0) : t0 = $[1];
|
|
147
|
+
const [disabledActions, setDisabledActions] = useState(t0);
|
|
148
|
+
let t1;
|
|
149
|
+
$[2] !== payload.length || $[3] !== setPayload ? (t1 = function(action) {
|
|
150
|
+
payload.length && (setPayload((current) => current.map((item_0) => ({
|
|
151
|
+
...item_0,
|
|
152
|
+
include: shouldInclude(item_0, action)
|
|
153
|
+
}))), setDisabledActions([action]));
|
|
154
|
+
}, $[2] = payload.length, $[3] = setPayload, $[4] = t1) : t1 = $[4];
|
|
155
|
+
const handleSelectButton = t1;
|
|
156
|
+
let t2;
|
|
157
|
+
$[5] !== disabledActions || $[6] !== handleSelectButton ? (t2 = buttons.map((button) => "action" in button ? /* @__PURE__ */ jsx(Button, { fontSize: 1, mode: "bleed", padding: 2, text: button.label, disabled: disabledActions.includes(button.action), onClick: () => handleSelectButton(button.action) }, button.action) : /* @__PURE__ */ jsx(Card, { borderLeft: !0 }, button.divider)), $[5] = disabledActions, $[6] = handleSelectButton, $[7] = t2) : t2 = $[7];
|
|
158
|
+
let t3;
|
|
159
|
+
return $[8] !== t2 ? (t3 = /* @__PURE__ */ jsx(Card, { padding: 1, radius: 3, shadow: 1, children: /* @__PURE__ */ jsx(Flex, { gap: 2, wrap: "wrap", children: t2 }) }), $[8] = t2, $[9] = t3) : t3 = $[9], t3;
|
|
160
|
+
}
|
|
161
|
+
function _temp$2(item) {
|
|
162
|
+
return item.include;
|
|
102
163
|
}
|
|
103
164
|
const documentTones = {
|
|
104
165
|
EXISTS: "primary",
|
|
@@ -138,511 +199,678 @@ const documentTones = {
|
|
|
138
199
|
UNPUBLISHED: ""
|
|
139
200
|
};
|
|
140
201
|
function StatusBadge(props) {
|
|
141
|
-
const
|
|
202
|
+
const $ = c(12), {
|
|
203
|
+
status,
|
|
204
|
+
isAsset
|
|
205
|
+
} = props;
|
|
142
206
|
if (!status)
|
|
143
207
|
return null;
|
|
144
208
|
const badgeTone = isAsset ? assetTones[status] : documentTones[status];
|
|
145
|
-
if (!badgeTone)
|
|
146
|
-
|
|
209
|
+
if (!badgeTone) {
|
|
210
|
+
let t02;
|
|
211
|
+
return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(Badge, { muted: !0, padding: 2, fontSize: 1, children: "Checking..." }), $[0] = t02) : t02 = $[0], t02;
|
|
212
|
+
}
|
|
147
213
|
const badgeText = isAsset ? assetMessages[status] : documentMessages[status], badgeStatus = isAsset ? assetStatus[status] : status;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
214
|
+
let t0;
|
|
215
|
+
$[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
216
|
+
maxWidth: 200
|
|
217
|
+
}, $[1] = t0) : t0 = $[1];
|
|
218
|
+
let t1;
|
|
219
|
+
$[2] !== badgeText ? (t1 = /* @__PURE__ */ jsx(Box, { padding: 3, style: t0, children: /* @__PURE__ */ jsx(Text, { size: 1, children: badgeText }) }), $[2] = badgeText, $[3] = t1) : t1 = $[3];
|
|
220
|
+
let t2;
|
|
221
|
+
$[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = ["right", "left"], $[4] = t2) : t2 = $[4];
|
|
222
|
+
let t3;
|
|
223
|
+
$[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(Box, { marginLeft: 2, display: "inline-block", as: "span", children: /* @__PURE__ */ jsx(InfoOutlineIcon, {}) }), $[5] = t3) : t3 = $[5];
|
|
224
|
+
let t4;
|
|
225
|
+
$[6] !== badgeStatus || $[7] !== badgeTone ? (t4 = /* @__PURE__ */ jsxs(Badge, { muted: !0, padding: 3, fontSize: 1, tone: badgeTone, children: [
|
|
226
|
+
badgeStatus,
|
|
227
|
+
t3
|
|
228
|
+
] }), $[6] = badgeStatus, $[7] = badgeTone, $[8] = t4) : t4 = $[8];
|
|
229
|
+
let t5;
|
|
230
|
+
return $[9] !== t1 || $[10] !== t4 ? (t5 = /* @__PURE__ */ jsx(Tooltip, { content: t1, fallbackPlacements: t2, placement: "top", portal: !0, children: t4 }), $[9] = t1, $[10] = t4, $[11] = t5) : t5 = $[11], t5;
|
|
161
231
|
}
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
232
|
+
function isAssetDocument(doc) {
|
|
233
|
+
return isAssetId(doc._id);
|
|
234
|
+
}
|
|
235
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
236
|
+
const queue = [...items];
|
|
237
|
+
async function work() {
|
|
238
|
+
const item = queue.shift();
|
|
239
|
+
if (item !== void 0)
|
|
240
|
+
return await fn(item), work();
|
|
241
|
+
}
|
|
242
|
+
const workers = Array.from({
|
|
243
|
+
length: Math.min(limit, queue.length)
|
|
244
|
+
}, () => work());
|
|
245
|
+
await Promise.all(workers);
|
|
165
246
|
}
|
|
166
247
|
function Duplicator(props) {
|
|
167
|
-
const
|
|
248
|
+
const $ = c(105), {
|
|
249
|
+
docs,
|
|
250
|
+
token,
|
|
251
|
+
pluginConfig,
|
|
252
|
+
onDuplicated
|
|
253
|
+
} = props, theme = useTheme(), isDarkMode = getTheme_v2({
|
|
254
|
+
sanity: theme.sanity
|
|
255
|
+
}).color._dark;
|
|
256
|
+
let t0;
|
|
257
|
+
$[0] !== pluginConfig.apiVersion ? (t0 = {
|
|
258
|
+
apiVersion: pluginConfig.apiVersion
|
|
259
|
+
}, $[0] = pluginConfig.apiVersion, $[1] = t0) : t0 = $[1];
|
|
260
|
+
const originClient = useClient(t0), schema = useSchema(), workspaces = useWorkspaces();
|
|
261
|
+
let t1;
|
|
262
|
+
$[2] !== originClient ? (t1 = (workspace) => ({
|
|
168
263
|
...workspace,
|
|
169
264
|
disabled: workspace.dataset === originClient.config().dataset && workspace.projectId === originClient.config().projectId
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
async function updatePayloadStatuses(newPayload = []) {
|
|
188
|
-
const payloadActual = newPayload.length ? newPayload : payload;
|
|
189
|
-
if (!payloadActual.length || !destination?.name)
|
|
265
|
+
}), $[2] = originClient, $[3] = t1) : t1 = $[3];
|
|
266
|
+
const workspacesOptions = workspaces.map(t1), [destination, setDestination] = useState(workspaces.length ? workspacesOptions.find(_temp$1) ?? null : null), [message, setMessage] = useState(null);
|
|
267
|
+
let t2;
|
|
268
|
+
$[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[4] = t2) : t2 = $[4];
|
|
269
|
+
const [payload, setPayload] = useState(t2), [isDuplicating, setIsDuplicating] = useState(!1), [isGathering, setIsGathering] = useState(!1);
|
|
270
|
+
let t3;
|
|
271
|
+
$[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = [0, 0], $[5] = t3) : t3 = $[5];
|
|
272
|
+
const [progress, setProgress] = useState(t3), initialRefsCount = docs.reduce(_temp2, 0), hasReferences = initialRefsCount > 0;
|
|
273
|
+
let t4;
|
|
274
|
+
$[6] !== docs.length || $[7] !== hasReferences || $[8] !== initialRefsCount ? (t4 = hasReferences ? {
|
|
275
|
+
tone: "caution",
|
|
276
|
+
text: createInitialMessage(docs.length, initialRefsCount)
|
|
277
|
+
} : null, $[6] = docs.length, $[7] = hasReferences, $[8] = initialRefsCount, $[9] = t4) : t4 = $[9];
|
|
278
|
+
const displayMessage = message ?? t4;
|
|
279
|
+
let t5;
|
|
280
|
+
$[10] !== originClient || $[11] !== setPayload ? (t5 = async function(payloadActual, dest) {
|
|
281
|
+
if (!payloadActual.length || !dest?.name)
|
|
190
282
|
return;
|
|
191
|
-
const payloadIds = payloadActual.map(
|
|
192
|
-
dataset:
|
|
193
|
-
projectId:
|
|
194
|
-
}).fetch(
|
|
195
|
-
|
|
196
|
-
{ payloadIds }
|
|
197
|
-
), updatedPayload = payloadActual.map((item) => {
|
|
198
|
-
const existingDoc = destinationData.find((doc) => doc._id === item.doc._id);
|
|
199
|
-
return existingDoc?._updatedAt && item?.doc?._updatedAt ? existingDoc._updatedAt === item.doc._updatedAt ? item.status = "EXISTS" : existingDoc._updatedAt && item.doc._updatedAt && (item.status = new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt) ? (
|
|
200
|
-
// Document at destination is newer
|
|
201
|
-
"OVERWRITE"
|
|
202
|
-
) : (
|
|
203
|
-
// Document at destination is older
|
|
204
|
-
"UPDATE"
|
|
205
|
-
)) : item.status = "CREATE", item;
|
|
283
|
+
const payloadIds = payloadActual.map(_temp3), destinationData = await originClient.withConfig({
|
|
284
|
+
dataset: dest.dataset,
|
|
285
|
+
projectId: dest.projectId
|
|
286
|
+
}).fetch("*[_id in $payloadIds]{ _id, _updatedAt }", {
|
|
287
|
+
payloadIds
|
|
206
288
|
});
|
|
207
|
-
setPayload(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
setIsGathering(!0);
|
|
215
|
-
const docIds = docs.map((doc) => doc._id), payloadDocs = await getDocumentsInArray({
|
|
216
|
-
fetchIds: docIds,
|
|
217
|
-
client: originClient,
|
|
218
|
-
pluginConfig
|
|
219
|
-
}), draftDocs = await getDocumentsInArray({
|
|
220
|
-
fetchIds: docIds.map((id) => `drafts.${id}`),
|
|
221
|
-
client: originClient,
|
|
222
|
-
projection: "{_id}",
|
|
223
|
-
pluginConfig
|
|
224
|
-
}), draftDocsIds = new Set(draftDocs.map(({ _id }) => _id)), payloadShaped = payloadDocs.map((doc) => ({
|
|
225
|
-
doc,
|
|
226
|
-
// Include this in the transaction?
|
|
227
|
-
include: !0,
|
|
228
|
-
// Does it exist at the destination?
|
|
229
|
-
status: void 0,
|
|
230
|
-
// Does it have any drafts?
|
|
231
|
-
hasDraft: draftDocsIds.has(`drafts.${doc._id}`)
|
|
289
|
+
setPayload(payloadActual.map((item) => {
|
|
290
|
+
const existingDoc = destinationData.find((doc_1) => doc_1._id === item.doc._id);
|
|
291
|
+
let status = "CREATE";
|
|
292
|
+
return existingDoc?._updatedAt && item.doc._updatedAt && (existingDoc._updatedAt === item.doc._updatedAt ? status = "EXISTS" : status = new Date(existingDoc._updatedAt) > new Date(item.doc._updatedAt) ? "OVERWRITE" : "UPDATE"), {
|
|
293
|
+
...item,
|
|
294
|
+
status
|
|
295
|
+
};
|
|
232
296
|
}));
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
297
|
+
}, $[10] = originClient, $[11] = setPayload, $[12] = t5) : t5 = $[12];
|
|
298
|
+
const updatePayloadStatuses = t5;
|
|
299
|
+
let t6;
|
|
300
|
+
$[13] !== destination || $[14] !== updatePayloadStatuses ? (t6 = (nextDocs) => {
|
|
301
|
+
const initialPayload = nextDocs.map(_temp4);
|
|
302
|
+
updatePayloadStatuses(initialPayload, destination).catch(console.error);
|
|
303
|
+
}, $[13] = destination, $[14] = updatePayloadStatuses, $[15] = t6) : t6 = $[15];
|
|
304
|
+
const initializePayload = useEffectEvent(t6);
|
|
305
|
+
let t7;
|
|
306
|
+
$[16] !== docs || $[17] !== initializePayload ? (t7 = () => {
|
|
307
|
+
initializePayload(docs);
|
|
308
|
+
}, $[16] = docs, $[17] = initializePayload, $[18] = t7) : t7 = $[18];
|
|
309
|
+
let t8;
|
|
310
|
+
$[19] !== docs ? (t8 = [docs], $[19] = docs, $[20] = t8) : t8 = $[20], useEffect(t7, t8);
|
|
311
|
+
let t9;
|
|
312
|
+
$[21] !== setPayload ? (t9 = function(_id) {
|
|
313
|
+
setPayload((current) => current.map((item_0) => item_0.doc._id === _id ? {
|
|
314
|
+
...item_0,
|
|
315
|
+
include: !item_0.include
|
|
316
|
+
} : item_0));
|
|
317
|
+
}, $[21] = setPayload, $[22] = t9) : t9 = $[22];
|
|
318
|
+
const handleCheckbox = t9;
|
|
319
|
+
let t10;
|
|
320
|
+
$[23] !== destination || $[24] !== docs || $[25] !== originClient || $[26] !== pluginConfig || $[27] !== setPayload || $[28] !== updatePayloadStatuses ? (t10 = async function() {
|
|
321
|
+
setIsGathering(!0);
|
|
322
|
+
try {
|
|
323
|
+
const docIds = docs.map(_temp5), payloadDocs = await getDocumentsInArray({
|
|
324
|
+
fetchIds: docIds,
|
|
325
|
+
client: originClient,
|
|
326
|
+
pluginConfig
|
|
327
|
+
}), draftDocs = await getDocumentsInArray({
|
|
328
|
+
fetchIds: docIds.map(_temp6),
|
|
329
|
+
client: originClient,
|
|
330
|
+
projection: "{_id}",
|
|
331
|
+
pluginConfig
|
|
332
|
+
}), draftDocsIds = new Set(draftDocs.map(_temp7)), payloadShaped = payloadDocs.map((doc_4) => ({
|
|
333
|
+
doc: doc_4,
|
|
334
|
+
include: !0,
|
|
335
|
+
status: void 0,
|
|
336
|
+
hasDraft: draftDocsIds.has(`drafts.${doc_4._id}`)
|
|
337
|
+
}));
|
|
338
|
+
setPayload(payloadShaped), updatePayloadStatuses(payloadShaped, destination).catch(console.error);
|
|
339
|
+
} catch (t112) {
|
|
340
|
+
console.error(t112);
|
|
341
|
+
}
|
|
342
|
+
setIsGathering(!1);
|
|
343
|
+
}, $[23] = destination, $[24] = docs, $[25] = originClient, $[26] = pluginConfig, $[27] = setPayload, $[28] = updatePayloadStatuses, $[29] = t10) : t10 = $[29];
|
|
344
|
+
const handleReferences = t10;
|
|
345
|
+
let t11;
|
|
346
|
+
$[30] !== destination || $[31] !== onDuplicated || $[32] !== originClient || $[33] !== payload || $[34] !== pluginConfig.apiVersion || $[35] !== token || $[36] !== updatePayloadStatuses ? (t11 = async function() {
|
|
236
347
|
if (!destination)
|
|
237
348
|
return;
|
|
238
349
|
setIsDuplicating(!0);
|
|
239
|
-
const assetsCount = payload.filter(
|
|
350
|
+
const assetsCount = payload.filter(_temp8).length;
|
|
240
351
|
let currentProgress = 0;
|
|
241
|
-
setProgress([currentProgress, assetsCount]), setMessage({
|
|
242
|
-
|
|
352
|
+
setProgress([currentProgress, assetsCount]), setMessage({
|
|
353
|
+
text: "Duplicating...",
|
|
354
|
+
tone: "transparent"
|
|
355
|
+
});
|
|
356
|
+
const destinationClient_0 = originClient.withConfig({
|
|
243
357
|
apiVersion: pluginConfig.apiVersion,
|
|
244
358
|
dataset: destination.dataset,
|
|
245
359
|
projectId: destination.projectId
|
|
246
|
-
}), transactionDocs = [], svgMaps = []
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
await fetch(downloadUrl, downloadConfig).then(async (res) => {
|
|
251
|
-
const assetData = await res.blob(), options = { filename: doc.originalFilename }, assetDoc = await destinationClient.assets.upload(
|
|
252
|
-
typeIsFile ? "file" : "image",
|
|
253
|
-
assetData,
|
|
254
|
-
options
|
|
255
|
-
);
|
|
256
|
-
doc?.extension === "svg" && svgMaps.push({ old: doc._id, new: assetDoc._id }), transactionDocs.push(assetDoc), doc.url = assetDoc.url, doc.path = assetDoc.path;
|
|
257
|
-
}), currentProgress += 1, setMessage({
|
|
258
|
-
text: `Duplicating ${currentProgress}/${assetsCount} Assets`,
|
|
259
|
-
tone: "default"
|
|
260
|
-
}), setProgress([currentProgress, assetsCount]);
|
|
360
|
+
}), transactionDocs = [], svgMaps = [], processDoc = async function(doc_6) {
|
|
361
|
+
if (!isAssetDocument(doc_6)) {
|
|
362
|
+
transactionDocs.push(doc_6);
|
|
363
|
+
return;
|
|
261
364
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
365
|
+
const typeIsFile = isSanityFileAsset(doc_6), downloadUrl = typeIsFile ? doc_6.url : `${doc_6.url}?dlRaw=true`, downloadConfig = typeIsFile ? {} : {
|
|
366
|
+
headers: {
|
|
367
|
+
Authorization: `Bearer ${token}`
|
|
368
|
+
}
|
|
369
|
+
}, assetData = await (await fetch(downloadUrl, downloadConfig)).blob(), options = {
|
|
370
|
+
filename: doc_6.originalFilename
|
|
371
|
+
}, assetDoc = await destinationClient_0.assets.upload(typeIsFile ? "file" : "image", assetData, options);
|
|
372
|
+
doc_6.extension === "svg" && svgMaps.push({
|
|
373
|
+
old: doc_6._id,
|
|
374
|
+
new: assetDoc._id
|
|
375
|
+
}), transactionDocs.push(assetDoc), transactionDocs.push({
|
|
376
|
+
...doc_6,
|
|
377
|
+
url: assetDoc.url,
|
|
378
|
+
path: assetDoc.path
|
|
379
|
+
}), currentProgress = currentProgress + 1, setMessage({
|
|
380
|
+
text: `Duplicating ${currentProgress}/${assetsCount} Assets`,
|
|
381
|
+
tone: "default"
|
|
382
|
+
}), setProgress([currentProgress, assetsCount]);
|
|
383
|
+
};
|
|
384
|
+
try {
|
|
385
|
+
const payloadIncludedDocs = payload.filter(_temp9).map(_temp0);
|
|
386
|
+
await mapWithConcurrency(payloadIncludedDocs, 3, processDoc);
|
|
387
|
+
} catch (t122) {
|
|
388
|
+
console.error(t122), setIsDuplicating(!1), setProgress([0, 0]), setMessage({
|
|
389
|
+
tone: "critical",
|
|
390
|
+
text: "Duplication Failed"
|
|
268
391
|
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const transactionDocsMapped = transactionDocs.map((doc_7) => {
|
|
395
|
+
const references = extractWithPath(".._ref", doc_7);
|
|
272
396
|
return references.length && references.forEach((ref) => {
|
|
273
397
|
const newRefValue = svgMaps.find((asset) => asset.old === ref.value)?.new;
|
|
274
398
|
if (newRefValue) {
|
|
275
399
|
const refPath = ref.path.join(".");
|
|
276
|
-
dset
|
|
400
|
+
dset(doc_7, refPath, newRefValue);
|
|
277
401
|
}
|
|
278
|
-
}),
|
|
279
|
-
}), transaction =
|
|
280
|
-
|
|
281
|
-
transaction.createOrReplace(
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
402
|
+
}), doc_7;
|
|
403
|
+
}), transaction = destinationClient_0.transaction();
|
|
404
|
+
transactionDocsMapped.forEach((doc_8) => {
|
|
405
|
+
transaction.createOrReplace(doc_8);
|
|
406
|
+
});
|
|
407
|
+
try {
|
|
408
|
+
await transaction.commit(), setMessage({
|
|
409
|
+
tone: "positive",
|
|
410
|
+
text: "Duplication complete!"
|
|
411
|
+
}), updatePayloadStatuses(payload, destination).catch(console.error);
|
|
412
|
+
} catch (t132) {
|
|
413
|
+
const err_1 = t132;
|
|
414
|
+
setMessage({
|
|
415
|
+
tone: "critical",
|
|
416
|
+
text: err_1 instanceof Error ? err_1.message : "Duplication Failed"
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
if (setIsDuplicating(!1), setProgress([0, 0]), onDuplicated)
|
|
287
420
|
try {
|
|
288
421
|
await onDuplicated();
|
|
289
|
-
} catch (
|
|
290
|
-
|
|
422
|
+
} catch (t142) {
|
|
423
|
+
const error = t142, text = error instanceof Error ? error.message : String(error);
|
|
424
|
+
setMessage({
|
|
425
|
+
tone: "critical",
|
|
426
|
+
text: `Error in onDuplicated hook: ${text}`
|
|
427
|
+
});
|
|
291
428
|
}
|
|
292
|
-
}
|
|
293
|
-
|
|
429
|
+
}, $[30] = destination, $[31] = onDuplicated, $[32] = originClient, $[33] = payload, $[34] = pluginConfig.apiVersion, $[35] = token, $[36] = updatePayloadStatuses, $[37] = t11) : t11 = $[37];
|
|
430
|
+
const handleDuplicate = t11, handleChange = function(e) {
|
|
294
431
|
if (!workspacesOptions.length)
|
|
295
432
|
return;
|
|
296
|
-
const targeted = workspacesOptions.find((
|
|
297
|
-
targeted && setDestination(targeted);
|
|
433
|
+
const targeted = workspacesOptions.find((space_0) => space_0.name === e.currentTarget.value);
|
|
434
|
+
targeted && (setDestination(targeted), updatePayloadStatuses(payload, targeted).catch(console.error));
|
|
435
|
+
}, payloadCount = payload.length;
|
|
436
|
+
let t12;
|
|
437
|
+
$[38] !== payload ? (t12 = payload.findIndex(_temp1), $[38] = payload, $[39] = t12) : t12 = $[39];
|
|
438
|
+
const firstSvgIndex = t12;
|
|
439
|
+
let t13;
|
|
440
|
+
$[40] !== payload ? (t13 = payload.filter(_temp10), $[40] = payload, $[41] = t13) : t13 = $[41];
|
|
441
|
+
const selectedDocumentsCount = t13.length;
|
|
442
|
+
let t14;
|
|
443
|
+
$[42] !== payload ? (t14 = payload.filter(_temp11), $[42] = payload, $[43] = t14) : t14 = $[43];
|
|
444
|
+
const selectedAssetsCount = t14.length, selectedTotal = selectedDocumentsCount + selectedAssetsCount, destinationTitle = destination?.title ?? destination?.name, hasMultipleProjectIds = new Set(workspacesOptions.map(_temp12).filter(Boolean)).size > 1;
|
|
445
|
+
let t15;
|
|
446
|
+
$[44] !== payloadCount || $[45] !== selectedTotal ? (t15 = [selectedTotal, "/", payloadCount, "Documents and Assets selected"], $[44] = payloadCount, $[45] = selectedTotal, $[46] = t15) : t15 = $[46];
|
|
447
|
+
const headingText = t15.join(" ");
|
|
448
|
+
let buttonTextParts;
|
|
449
|
+
$[47] !== destination?.projectId || $[48] !== destinationTitle || $[49] !== originClient || $[50] !== selectedAssetsCount || $[51] !== selectedDocumentsCount ? (buttonTextParts = ["Duplicate"], selectedDocumentsCount > 1 && buttonTextParts.push(String(selectedDocumentsCount), selectedDocumentsCount === 1 ? "Document" : "Documents"), selectedAssetsCount > 1 && buttonTextParts.push("and", String(selectedAssetsCount), selectedAssetsCount === 1 ? "Asset" : "Assets"), originClient.config().projectId !== destination?.projectId && buttonTextParts.push("between Projects"), buttonTextParts.push("to", String(destinationTitle)), $[47] = destination?.projectId, $[48] = destinationTitle, $[49] = originClient, $[50] = selectedAssetsCount, $[51] = selectedDocumentsCount, $[52] = buttonTextParts) : buttonTextParts = $[52];
|
|
450
|
+
const buttonText = buttonTextParts.join(" ");
|
|
451
|
+
if (workspacesOptions.length < 2) {
|
|
452
|
+
let t162;
|
|
453
|
+
return $[53] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t162 = /* @__PURE__ */ jsxs(Feedback, { tone: "critical", children: [
|
|
454
|
+
/* @__PURE__ */ jsx("code", { children: "sanity.config.ts" }),
|
|
455
|
+
" must contain at least two Workspaces to use this plugin."
|
|
456
|
+
] }), $[53] = t162) : t162 = $[53], t162;
|
|
298
457
|
}
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
])
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
458
|
+
const t16 = stickyStyles(isDarkMode);
|
|
459
|
+
let t17;
|
|
460
|
+
$[54] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t17 = {
|
|
461
|
+
flex: 1
|
|
462
|
+
}, $[54] = t17) : t17 = $[54];
|
|
463
|
+
let t18;
|
|
464
|
+
$[55] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t18 = /* @__PURE__ */ jsx(Label, { children: "Duplicate from" }), $[55] = t18) : t18 = $[55];
|
|
465
|
+
let t19;
|
|
466
|
+
$[56] !== hasMultipleProjectIds ? (t19 = (space_4) => /* @__PURE__ */ jsxs("option", { value: space_4.name, disabled: space_4.disabled, children: [
|
|
467
|
+
space_4.title ?? space_4.name,
|
|
468
|
+
hasMultipleProjectIds ? ` (${space_4.projectId})` : ""
|
|
469
|
+
] }, space_4.name), $[56] = hasMultipleProjectIds, $[57] = t19) : t19 = $[57];
|
|
470
|
+
let t20;
|
|
471
|
+
$[58] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t20 = /* @__PURE__ */ jsx(Box, { padding: 4, paddingTop: 5, paddingBottom: 0, children: /* @__PURE__ */ jsx(Text, { size: 3, children: /* @__PURE__ */ jsx(ArrowRightIcon, {}) }) }), $[58] = t20) : t20 = $[58];
|
|
472
|
+
const T0 = Stack;
|
|
473
|
+
let t21;
|
|
474
|
+
$[59] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t21 = {
|
|
475
|
+
flex: 1
|
|
476
|
+
}, $[59] = t21) : t21 = $[59];
|
|
477
|
+
const t22 = 3;
|
|
478
|
+
let t23;
|
|
479
|
+
$[60] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t23 = /* @__PURE__ */ jsx(Label, { children: "To Destination" }), $[60] = t23) : t23 = $[60];
|
|
480
|
+
const T1 = Select;
|
|
481
|
+
let t24;
|
|
482
|
+
$[61] !== hasMultipleProjectIds ? (t24 = (space_5) => /* @__PURE__ */ jsxs("option", { value: space_5.name, disabled: space_5.disabled, children: [
|
|
483
|
+
space_5.title ?? space_5.name,
|
|
484
|
+
hasMultipleProjectIds ? ` (${space_5.projectId})` : "",
|
|
485
|
+
space_5.disabled ? " (Current)" : ""
|
|
486
|
+
] }, space_5.name), $[61] = hasMultipleProjectIds, $[62] = t24) : t24 = $[62];
|
|
487
|
+
const t25 = workspacesOptions.map(t24);
|
|
488
|
+
let t26;
|
|
489
|
+
$[63] !== T1 || $[64] !== handleChange || $[65] !== t25 ? (t26 = /* @__PURE__ */ jsx(T1, { onChange: handleChange, children: t25 }), $[63] = T1, $[64] = handleChange, $[65] = t25, $[66] = t26) : t26 = $[66];
|
|
490
|
+
let t27;
|
|
491
|
+
$[67] !== T0 || $[68] !== t21 || $[69] !== t23 || $[70] !== t26 ? (t27 = /* @__PURE__ */ jsxs(T0, { style: t21, gap: t22, children: [
|
|
492
|
+
t23,
|
|
493
|
+
t26
|
|
494
|
+
] }), $[67] = T0, $[68] = t21, $[69] = t23, $[70] = t26, $[71] = t27) : t27 = $[71];
|
|
495
|
+
let t28;
|
|
496
|
+
$[72] !== isDuplicating || $[73] !== progress ? (t28 = isDuplicating && /* @__PURE__ */ jsx(Card, { border: !0, radius: 2, children: /* @__PURE__ */ jsx(Card, { style: {
|
|
497
|
+
width: "100%",
|
|
498
|
+
transform: `scaleX(${progress[0] / progress[1]})`,
|
|
499
|
+
transformOrigin: "left",
|
|
500
|
+
transition: "transform .2s ease",
|
|
501
|
+
boxSizing: "border-box"
|
|
502
|
+
}, padding: 1, tone: "positive" }) }), $[72] = isDuplicating, $[73] = progress, $[74] = t28) : t28 = $[74];
|
|
503
|
+
let t29;
|
|
504
|
+
$[75] !== headingText || $[76] !== payload || $[77] !== setPayload ? (t29 = payload.length > 0 && /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
505
|
+
/* @__PURE__ */ jsx(Label, { children: headingText }),
|
|
506
|
+
/* @__PURE__ */ jsx(SelectButtons, { payload, setPayload })
|
|
507
|
+
] }), $[75] = headingText, $[76] = payload, $[77] = setPayload, $[78] = t29) : t29 = $[78];
|
|
508
|
+
let t30;
|
|
509
|
+
$[79] !== displayMessage ? (t30 = displayMessage && /* @__PURE__ */ jsx(Card, { padding: 3, radius: 2, shadow: 1, tone: displayMessage.tone, children: /* @__PURE__ */ jsx(Text, { size: 1, children: displayMessage.text }) }), $[79] = displayMessage, $[80] = t30) : t30 = $[80];
|
|
510
|
+
let t31;
|
|
511
|
+
$[81] !== firstSvgIndex || $[82] !== handleCheckbox || $[83] !== payload || $[84] !== schema ? (t31 = payload.length > 0 ? /* @__PURE__ */ jsx(Stack, { children: payload.map((t322, index) => {
|
|
512
|
+
const {
|
|
513
|
+
doc: doc_10,
|
|
514
|
+
include: include_0,
|
|
515
|
+
status: status_0,
|
|
516
|
+
hasDraft
|
|
517
|
+
} = t322, schemaType = schema.get(doc_10._type);
|
|
518
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
519
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", children: [
|
|
520
|
+
/* @__PURE__ */ jsx(Checkbox, { checked: include_0, onChange: () => handleCheckbox(doc_10._id) }),
|
|
521
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, paddingX: 3, children: schemaType ? /* @__PURE__ */ jsx(Preview, { value: doc_10, schemaType }) : /* @__PURE__ */ jsx(Card, { tone: "caution", children: "Invalid schema type" }) }),
|
|
522
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
523
|
+
hasDraft ? /* @__PURE__ */ jsx(StatusBadge, { status: "UNPUBLISHED", isAsset: !1 }) : null,
|
|
524
|
+
/* @__PURE__ */ jsx(StatusBadge, { status: status_0, isAsset: isAssetId(doc_10._id) })
|
|
337
525
|
] })
|
|
338
526
|
] }),
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
{
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
527
|
+
doc_10.extension === "svg" && index === firstSvgIndex && /* @__PURE__ */ jsx(Card, { padding: 3, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
528
|
+
"Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ",
|
|
529
|
+
/* @__PURE__ */ jsx("code", { children: "_id" }),
|
|
530
|
+
"'s at the destination. The newly generated ",
|
|
531
|
+
/* @__PURE__ */ jsx("code", { children: "_id" }),
|
|
532
|
+
" will be the same in each duplication, but it will never be the same ",
|
|
533
|
+
/* @__PURE__ */ jsx("code", { children: "_id" }),
|
|
534
|
+
" as the first time this Asset was uploaded. References to the asset will be updated to use the new ",
|
|
535
|
+
/* @__PURE__ */ jsx("code", { children: "_id" }),
|
|
536
|
+
"."
|
|
537
|
+
] }) })
|
|
538
|
+
] }, doc_10._id);
|
|
539
|
+
}) }) : /* @__PURE__ */ jsx(Flex, { padding: 4, align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) }), $[81] = firstSvgIndex, $[82] = handleCheckbox, $[83] = payload, $[84] = schema, $[85] = t31) : t31 = $[85];
|
|
540
|
+
let t32;
|
|
541
|
+
$[86] !== handleReferences || $[87] !== hasReferences || $[88] !== isDuplicating || $[89] !== isGathering || $[90] !== selectedTotal ? (t32 = hasReferences && /* @__PURE__ */ jsx(Button, { fontSize: 2, padding: 4, tone: "positive", mode: "ghost", icon: SearchIcon, onClick: () => {
|
|
542
|
+
handleReferences();
|
|
543
|
+
}, text: "Gather References", disabled: isDuplicating || !selectedTotal || isGathering }), $[86] = handleReferences, $[87] = hasReferences, $[88] = isDuplicating, $[89] = isGathering, $[90] = selectedTotal, $[91] = t32) : t32 = $[91];
|
|
544
|
+
let t33;
|
|
545
|
+
$[92] !== handleDuplicate ? (t33 = () => {
|
|
546
|
+
handleDuplicate();
|
|
547
|
+
}, $[92] = handleDuplicate, $[93] = t33) : t33 = $[93];
|
|
548
|
+
const t34 = isDuplicating || !selectedTotal || isGathering;
|
|
549
|
+
let t35;
|
|
550
|
+
$[94] !== buttonText || $[95] !== t33 || $[96] !== t34 ? (t35 = /* @__PURE__ */ jsx(Button, { fontSize: 2, padding: 4, tone: "positive", icon: LaunchIcon, onClick: t33, text: buttonText, disabled: t34 }), $[94] = buttonText, $[95] = t33, $[96] = t34, $[97] = t35) : t35 = $[97];
|
|
551
|
+
let t36;
|
|
552
|
+
$[98] !== t32 || $[99] !== t35 ? (t36 = /* @__PURE__ */ jsxs(Stack, { gap: 2, children: [
|
|
553
|
+
t32,
|
|
554
|
+
t35
|
|
555
|
+
] }), $[98] = t32, $[99] = t35, $[100] = t36) : t36 = $[100];
|
|
556
|
+
let t37;
|
|
557
|
+
return $[101] !== t30 || $[102] !== t31 || $[103] !== t36 ? (t37 = /* @__PURE__ */ jsx(Card, { borderTop: !0, padding: 4, children: /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
558
|
+
t30,
|
|
559
|
+
t31,
|
|
560
|
+
t36
|
|
561
|
+
] }) }), $[101] = t30, $[102] = t31, $[103] = t36, $[104] = t37) : t37 = $[104], /* @__PURE__ */ jsx(Container, { width: 1, children: /* @__PURE__ */ jsx(Card, { border: !0, children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
562
|
+
/* @__PURE__ */ jsx(Card, { padding: 4, style: t16, children: /* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
|
|
563
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 3, children: [
|
|
564
|
+
/* @__PURE__ */ jsxs(Stack, { style: t17, gap: 3, children: [
|
|
565
|
+
t18,
|
|
566
|
+
/* @__PURE__ */ jsx(Select, { readOnly: !0, value: workspacesOptions.find(_temp13)?.name, children: workspacesOptions.filter(_temp14).map(t19) })
|
|
567
|
+
] }),
|
|
568
|
+
t20,
|
|
569
|
+
t27
|
|
570
|
+
] }),
|
|
571
|
+
t28,
|
|
572
|
+
t29
|
|
357
573
|
] }) }),
|
|
358
|
-
|
|
359
|
-
message && /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, radius: 2, shadow: 1, tone: message.tone, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: message.text }) }),
|
|
360
|
-
payload.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { children: payload.map(({ doc, include, status, hasDraft }, index) => {
|
|
361
|
-
const schemaType = schema.get(doc._type);
|
|
362
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(React__default.default.Fragment, { children: [
|
|
363
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [
|
|
364
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { checked: include, onChange: () => handleCheckbox(doc._id) }),
|
|
365
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, paddingX: 3, children: schemaType ? /* @__PURE__ */ jsxRuntime.jsx(sanity.Preview, { value: doc, schemaType }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "caution", children: "Invalid schema type" }) }),
|
|
366
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 2, children: [
|
|
367
|
-
hasDraft ? /* @__PURE__ */ jsxRuntime.jsx(StatusBadge, { status: "UNPUBLISHED", isAsset: !1 }) : null,
|
|
368
|
-
/* @__PURE__ */ jsxRuntime.jsx(StatusBadge, { status, isAsset: assetUtils.isAssetId(doc._id) })
|
|
369
|
-
] })
|
|
370
|
-
] }),
|
|
371
|
-
doc?.extension === "svg" && index === firstSvgIndex && /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
|
|
372
|
-
"Due to how SVGs are sanitized after first uploaded, duplicated SVG assets may have new ",
|
|
373
|
-
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "_id" }),
|
|
374
|
-
"'s at the destination. The newly generated ",
|
|
375
|
-
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "_id" }),
|
|
376
|
-
" will be the same in each duplication, but it will never be the same ",
|
|
377
|
-
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "_id" }),
|
|
378
|
-
" as the first time this Asset was uploaded. References to the asset will be updated to use the new ",
|
|
379
|
-
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "_id" }),
|
|
380
|
-
"."
|
|
381
|
-
] }) })
|
|
382
|
-
] }, doc._id);
|
|
383
|
-
}) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { padding: 4, align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }),
|
|
384
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
|
|
385
|
-
hasReferences && /* @__PURE__ */ jsxRuntime.jsx(
|
|
386
|
-
ui.Button,
|
|
387
|
-
{
|
|
388
|
-
fontSize: 2,
|
|
389
|
-
padding: 4,
|
|
390
|
-
tone: "positive",
|
|
391
|
-
mode: "ghost",
|
|
392
|
-
icon: icons.SearchIcon,
|
|
393
|
-
onClick: handleReferences,
|
|
394
|
-
text: "Gather References",
|
|
395
|
-
disabled: isDuplicating || !selectedTotal || isGathering
|
|
396
|
-
}
|
|
397
|
-
),
|
|
398
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
399
|
-
ui.Button,
|
|
400
|
-
{
|
|
401
|
-
fontSize: 2,
|
|
402
|
-
padding: 4,
|
|
403
|
-
tone: "positive",
|
|
404
|
-
icon: icons.LaunchIcon,
|
|
405
|
-
onClick: handleDuplicate,
|
|
406
|
-
text: buttonText,
|
|
407
|
-
disabled: isDuplicating || !selectedTotal || isGathering
|
|
408
|
-
}
|
|
409
|
-
)
|
|
410
|
-
] })
|
|
411
|
-
] }) })
|
|
574
|
+
t37
|
|
412
575
|
] }) }) });
|
|
413
576
|
}
|
|
577
|
+
function _temp14(space_3) {
|
|
578
|
+
return space_3.disabled;
|
|
579
|
+
}
|
|
580
|
+
function _temp13(space_2) {
|
|
581
|
+
return space_2.disabled;
|
|
582
|
+
}
|
|
583
|
+
function _temp12(space_1) {
|
|
584
|
+
return space_1?.projectId;
|
|
585
|
+
}
|
|
586
|
+
function _temp11(item_4) {
|
|
587
|
+
return item_4.include && isAssetId(item_4.doc._id);
|
|
588
|
+
}
|
|
589
|
+
function _temp10(item_3) {
|
|
590
|
+
return item_3.include && !isAssetId(item_3.doc._id);
|
|
591
|
+
}
|
|
592
|
+
function _temp1(t0) {
|
|
593
|
+
const {
|
|
594
|
+
doc: doc_9
|
|
595
|
+
} = t0;
|
|
596
|
+
return doc_9.extension === "svg";
|
|
597
|
+
}
|
|
598
|
+
function _temp0(item_2) {
|
|
599
|
+
return item_2.doc;
|
|
600
|
+
}
|
|
601
|
+
function _temp9(item_1) {
|
|
602
|
+
return item_1.include;
|
|
603
|
+
}
|
|
604
|
+
function _temp8(t0) {
|
|
605
|
+
const {
|
|
606
|
+
doc: doc_5,
|
|
607
|
+
include
|
|
608
|
+
} = t0;
|
|
609
|
+
return include && isAssetId(doc_5._id);
|
|
610
|
+
}
|
|
611
|
+
function _temp7(t0) {
|
|
612
|
+
const {
|
|
613
|
+
_id: _id_0
|
|
614
|
+
} = t0;
|
|
615
|
+
return _id_0;
|
|
616
|
+
}
|
|
617
|
+
function _temp6(id) {
|
|
618
|
+
return `drafts.${id}`;
|
|
619
|
+
}
|
|
620
|
+
function _temp5(doc_3) {
|
|
621
|
+
return doc_3._id;
|
|
622
|
+
}
|
|
623
|
+
function _temp4(doc_2) {
|
|
624
|
+
return {
|
|
625
|
+
include: !0,
|
|
626
|
+
doc: doc_2
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function _temp3(t0) {
|
|
630
|
+
const {
|
|
631
|
+
doc: doc_0
|
|
632
|
+
} = t0;
|
|
633
|
+
return doc_0._id;
|
|
634
|
+
}
|
|
635
|
+
function _temp2(acc, doc) {
|
|
636
|
+
return acc + extractWithPath(".._ref", doc).length;
|
|
637
|
+
}
|
|
638
|
+
function _temp$1(space) {
|
|
639
|
+
return !space.disabled;
|
|
640
|
+
}
|
|
414
641
|
function DuplicatorQuery(props) {
|
|
415
|
-
const {
|
|
642
|
+
const {
|
|
643
|
+
token,
|
|
644
|
+
pluginConfig
|
|
645
|
+
} = props, {
|
|
646
|
+
queries: preDefinedQueries,
|
|
647
|
+
apiVersion
|
|
648
|
+
} = pluginConfig, originClient = useClient({
|
|
649
|
+
apiVersion
|
|
650
|
+
}), schemaTypes = useSchema().getTypeNames(), [value, setValue] = useState(""), [fetched, setFetched] = useState(!1), [initialData, setInitialData] = useState({
|
|
416
651
|
docs: []
|
|
417
652
|
});
|
|
418
|
-
function
|
|
419
|
-
|
|
420
|
-
const registeredAndPublishedDocs = res.length ? res.filter((doc) => schemaTypes.includes(doc._type)).filter((
|
|
653
|
+
async function runQuery() {
|
|
654
|
+
try {
|
|
655
|
+
const res = await originClient.fetch(value), registeredAndPublishedDocs = res.length ? res.filter((doc) => schemaTypes.includes(doc._type)).filter((doc_0) => !doc_0._id.startsWith("drafts.")) : [];
|
|
421
656
|
setInitialData({
|
|
422
657
|
docs: registeredAndPublishedDocs
|
|
423
658
|
}), setFetched(!0);
|
|
424
|
-
}
|
|
659
|
+
} catch (err) {
|
|
660
|
+
console.error(err);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function handleSubmit(e) {
|
|
664
|
+
e && e.preventDefault(), runQuery();
|
|
425
665
|
}
|
|
426
|
-
return
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
/* @__PURE__ */
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
{
|
|
437
|
-
style: { fontFamily: "monospace" },
|
|
438
|
-
fontSize: 2,
|
|
439
|
-
onChange: (event) => setValue(event.currentTarget.value),
|
|
440
|
-
padding: 4,
|
|
441
|
-
placeholder: '*[_type == "article"]',
|
|
442
|
-
value: value ?? ""
|
|
443
|
-
}
|
|
444
|
-
) }),
|
|
445
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
446
|
-
ui.Button,
|
|
447
|
-
{
|
|
448
|
-
padding: 2,
|
|
449
|
-
paddingX: 4,
|
|
450
|
-
tone: "primary",
|
|
451
|
-
onClick: handleSubmit,
|
|
452
|
-
text: "Query",
|
|
453
|
-
disabled: !value
|
|
454
|
-
}
|
|
455
|
-
)
|
|
666
|
+
return /* @__PURE__ */ jsx(Card, { padding: [0, 0, 0, 5], children: /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsxs(Grid, { gridTemplateColumns: [1, 1, 1, 2], gap: [1, 1, 1, 4], children: [
|
|
667
|
+
/* @__PURE__ */ jsxs(Box, { padding: [2, 2, 2, 0], children: [
|
|
668
|
+
/* @__PURE__ */ jsx(Card, { padding: 4, radius: 3, border: !0, children: /* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
|
|
669
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Label, { children: "Initial Documents Query" }) }),
|
|
670
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { 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." }) }),
|
|
671
|
+
/* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, children: /* @__PURE__ */ jsxs(Flex, { children: [
|
|
672
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, paddingRight: 2, children: /* @__PURE__ */ jsx(TextInput, { style: {
|
|
673
|
+
fontFamily: "monospace"
|
|
674
|
+
}, fontSize: 2, onChange: (event) => setValue(event.currentTarget.value), padding: 4, placeholder: '*[_type == "article"]', value: value ?? "" }) }),
|
|
675
|
+
/* @__PURE__ */ jsx(Button, { padding: 2, paddingX: 4, tone: "primary", onClick: () => handleSubmit(), text: "Query", disabled: !value })
|
|
456
676
|
] }) })
|
|
457
677
|
] }) }),
|
|
458
|
-
preDefinedQueries && preDefinedQueries?.length > 0 && /* @__PURE__ */
|
|
459
|
-
/* @__PURE__ */
|
|
460
|
-
/* @__PURE__ */
|
|
461
|
-
ui.Button,
|
|
462
|
-
{
|
|
463
|
-
padding: 2,
|
|
464
|
-
paddingX: 4,
|
|
465
|
-
tone: "primary",
|
|
466
|
-
onClick: () => setValue(`*[${query.query}]`),
|
|
467
|
-
text: query.label
|
|
468
|
-
},
|
|
469
|
-
query.label.replace(/\s+/g, "-")
|
|
470
|
-
)) })
|
|
678
|
+
preDefinedQueries && preDefinedQueries?.length > 0 && /* @__PURE__ */ jsx(Card, { marginTop: 2, padding: 4, radius: 3, border: !0, children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
|
|
679
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Label, { children: "Predefined Queries" }) }),
|
|
680
|
+
/* @__PURE__ */ jsx(Stack, { gap: 2, children: preDefinedQueries.map((query) => /* @__PURE__ */ jsx(Button, { padding: 2, paddingX: 4, tone: "primary", onClick: () => setValue(`*[${query.query}]`), text: query.label }, query.label.replace(/\s+/g, "-"))) })
|
|
471
681
|
] }) }) })
|
|
472
682
|
] }),
|
|
473
|
-
fetched && initialData.docs.length < 1 && /* @__PURE__ */
|
|
474
|
-
initialData.docs?.length > 0 && /* @__PURE__ */
|
|
475
|
-
Duplicator,
|
|
476
|
-
{
|
|
477
|
-
docs: initialData.docs,
|
|
478
|
-
token,
|
|
479
|
-
pluginConfig
|
|
480
|
-
}
|
|
481
|
-
)
|
|
683
|
+
fetched && initialData.docs.length < 1 && /* @__PURE__ */ jsx(Container, { width: 1, children: /* @__PURE__ */ jsx(Card, { padding: 5, children: value ? "No documents match this query" : "Start with a valid GROQ query" }) }),
|
|
684
|
+
initialData.docs?.length > 0 && /* @__PURE__ */ jsx(Duplicator, { docs: initialData.docs, token, pluginConfig })
|
|
482
685
|
] }) }) });
|
|
483
686
|
}
|
|
484
687
|
function DuplicatorWrapper(props) {
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
)
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
)
|
|
528
|
-
] });
|
|
529
|
-
}
|
|
530
|
-
const SECRET_NAMESPACE = "CrossDatasetDuplicator", DEFAULT_CONFIG = {
|
|
531
|
-
apiVersion: "2025-02-19",
|
|
532
|
-
tool: !0,
|
|
533
|
-
types: [],
|
|
534
|
-
filter: "",
|
|
535
|
-
follow: ["outbound"],
|
|
536
|
-
queries: []
|
|
537
|
-
};
|
|
538
|
-
function ResetSecret({ apiVersion }) {
|
|
539
|
-
const client = sanity.useClient({ apiVersion }), handleClick = React.useCallback(() => {
|
|
540
|
-
client.delete({ query: `*[_id == "secrets.${SECRET_NAMESPACE}"]` });
|
|
541
|
-
}, [client]);
|
|
542
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", justify: "flex-end", paddingX: [2, 2, 2, 5], paddingY: 5, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
543
|
-
ui.Button,
|
|
544
|
-
{
|
|
545
|
-
text: "Reset Secret",
|
|
546
|
-
onClick: handleClick,
|
|
547
|
-
mode: "ghost",
|
|
548
|
-
tone: "critical",
|
|
549
|
-
fontSize: 1,
|
|
550
|
-
padding: 2
|
|
551
|
-
}
|
|
552
|
-
) });
|
|
688
|
+
const $ = c(20), {
|
|
689
|
+
docs,
|
|
690
|
+
token,
|
|
691
|
+
pluginConfig,
|
|
692
|
+
onDuplicated
|
|
693
|
+
} = props;
|
|
694
|
+
let t0;
|
|
695
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
|
|
696
|
+
const [inbound, setInbound] = useState(t0), {
|
|
697
|
+
follow,
|
|
698
|
+
apiVersion
|
|
699
|
+
} = pluginConfig, [mode, setMode] = useState(follow.length === 1 ? follow[0] ?? "outbound" : "outbound");
|
|
700
|
+
let t1;
|
|
701
|
+
$[1] !== apiVersion ? (t1 = {
|
|
702
|
+
apiVersion
|
|
703
|
+
}, $[1] = apiVersion, $[2] = t1) : t1 = $[2];
|
|
704
|
+
const client = useClient(t1);
|
|
705
|
+
let t2, t3;
|
|
706
|
+
$[3] !== client || $[4] !== docs || $[5] !== follow ? (t2 = () => {
|
|
707
|
+
(async function() {
|
|
708
|
+
const firstDocId = docs[0]?._id;
|
|
709
|
+
if (!follow.includes("inbound") || !firstDocId)
|
|
710
|
+
return;
|
|
711
|
+
const inboundReferences = await client.fetch("*[references($id)]", {
|
|
712
|
+
id: firstDocId
|
|
713
|
+
});
|
|
714
|
+
setInbound([...docs, ...inboundReferences]);
|
|
715
|
+
})().catch(console.error);
|
|
716
|
+
}, t3 = [client, docs, follow], $[3] = client, $[4] = docs, $[5] = follow, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
|
|
717
|
+
let t4;
|
|
718
|
+
$[8] !== follow || $[9] !== inbound || $[10] !== mode ? (t4 = follow.length > 1 && (follow.includes("inbound") || follow.includes("outbound")) ? /* @__PURE__ */ jsx(Card, { paddingX: 4, paddingBottom: 4, marginBottom: 4, borderBottom: !0, children: /* @__PURE__ */ jsxs(Grid, { gridTemplateColumns: 2, gap: 4, children: [
|
|
719
|
+
follow.includes("outbound") ? /* @__PURE__ */ jsx(Button, { mode: "ghost", tone: "primary", selected: mode === "outbound", onClick: () => setMode("outbound"), text: "Outbound" }) : null,
|
|
720
|
+
follow.includes("inbound") ? /* @__PURE__ */ jsx(Button, { mode: "ghost", tone: "primary", selected: mode === "inbound", onClick: () => setMode("inbound"), disabled: inbound.length === 0, text: inbound.length > 0 ? `Inbound (${inbound.length})` : "No inbound references" }) : null
|
|
721
|
+
] }) }) : null, $[8] = follow, $[9] = inbound, $[10] = mode, $[11] = t4) : t4 = $[11];
|
|
722
|
+
const t5 = mode === "outbound" ? docs : inbound;
|
|
723
|
+
let t6;
|
|
724
|
+
$[12] !== onDuplicated || $[13] !== pluginConfig || $[14] !== t5 || $[15] !== token ? (t6 = /* @__PURE__ */ jsx(Duplicator, { docs: t5, token, pluginConfig, onDuplicated }), $[12] = onDuplicated, $[13] = pluginConfig, $[14] = t5, $[15] = token, $[16] = t6) : t6 = $[16];
|
|
725
|
+
let t7;
|
|
726
|
+
return $[17] !== t4 || $[18] !== t6 ? (t7 = /* @__PURE__ */ jsxs(Container, { children: [
|
|
727
|
+
t4,
|
|
728
|
+
t6
|
|
729
|
+
] }), $[17] = t4, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
|
|
553
730
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
731
|
+
function ResetSecret(t0) {
|
|
732
|
+
const $ = c(7), {
|
|
733
|
+
apiVersion
|
|
734
|
+
} = t0;
|
|
735
|
+
let t1;
|
|
736
|
+
$[0] !== apiVersion ? (t1 = {
|
|
737
|
+
apiVersion
|
|
738
|
+
}, $[0] = apiVersion, $[1] = t1) : t1 = $[1];
|
|
739
|
+
const client = useClient(t1);
|
|
740
|
+
let t2;
|
|
741
|
+
$[2] !== client ? (t2 = () => {
|
|
742
|
+
client.delete({
|
|
743
|
+
query: `*[_id == "secrets.${SECRET_NAMESPACE}"]`
|
|
744
|
+
}).catch(console.error);
|
|
745
|
+
}, $[2] = client, $[3] = t2) : t2 = $[3];
|
|
746
|
+
const handleClick = t2;
|
|
747
|
+
let t3;
|
|
748
|
+
$[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = [2, 2, 2, 5], $[4] = t3) : t3 = $[4];
|
|
749
|
+
let t4;
|
|
750
|
+
return $[5] !== handleClick ? (t4 = /* @__PURE__ */ jsx(Flex, { align: "center", justify: "flex-end", paddingX: t3, paddingY: 5, children: /* @__PURE__ */ jsx(Button, { text: "Reset Secret", onClick: handleClick, mode: "ghost", tone: "critical", fontSize: 1, padding: 2 }) }), $[5] = handleClick, $[6] = t4) : t4 = $[6], t4;
|
|
557
751
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
{
|
|
564
|
-
key: "bearerToken",
|
|
565
|
-
title: "An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage",
|
|
566
|
-
description: ""
|
|
567
|
-
}
|
|
568
|
-
];
|
|
752
|
+
const secretConfigKeys = [{
|
|
753
|
+
key: "bearerToken",
|
|
754
|
+
title: "An API token with Viewer permissions is required to duplicate the original files of assets, and will be used for all Duplications. Create one at sanity.io/manage",
|
|
755
|
+
description: ""
|
|
756
|
+
}];
|
|
569
757
|
function CrossDatasetDuplicator(props) {
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
758
|
+
const $ = c(17), {
|
|
759
|
+
mode,
|
|
760
|
+
docs,
|
|
761
|
+
onDuplicated
|
|
762
|
+
} = props, pluginConfig = useCrossDatasetDuplicatorConfig(), {
|
|
763
|
+
loading,
|
|
764
|
+
secrets
|
|
765
|
+
} = useSecrets(SECRET_NAMESPACE);
|
|
766
|
+
if (loading) {
|
|
767
|
+
let t02;
|
|
768
|
+
return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", children: /* @__PURE__ */ jsx(Box, { padding: 5, children: /* @__PURE__ */ jsx(Spinner, {}) }) }), $[0] = t02) : t02 = $[0], t02;
|
|
769
|
+
}
|
|
770
|
+
if (!secrets?.bearerToken) {
|
|
771
|
+
let t02;
|
|
772
|
+
return $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(SettingsView, { title: "Token Required", namespace: SECRET_NAMESPACE, keys: secretConfigKeys, onClose: _temp }), $[1] = t02) : t02 = $[1], t02;
|
|
773
|
+
}
|
|
774
|
+
if (mode === "tool" && pluginConfig) {
|
|
775
|
+
let t02;
|
|
776
|
+
$[2] !== pluginConfig || $[3] !== secrets.bearerToken ? (t02 = /* @__PURE__ */ jsx(DuplicatorQuery, { token: secrets.bearerToken, pluginConfig }), $[2] = pluginConfig, $[3] = secrets.bearerToken, $[4] = t02) : t02 = $[4];
|
|
777
|
+
let t1;
|
|
778
|
+
$[5] !== pluginConfig.apiVersion ? (t1 = /* @__PURE__ */ jsx(ResetSecret, { apiVersion: pluginConfig.apiVersion }), $[5] = pluginConfig.apiVersion, $[6] = t1) : t1 = $[6];
|
|
779
|
+
let t2;
|
|
780
|
+
return $[7] !== t02 || $[8] !== t1 ? (t2 = /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
781
|
+
t02,
|
|
782
|
+
t1
|
|
783
|
+
] }), $[7] = t02, $[8] = t1, $[9] = t2) : t2 = $[9], t2;
|
|
784
|
+
}
|
|
785
|
+
if (!docs?.length) {
|
|
786
|
+
let t02;
|
|
787
|
+
return $[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(Feedback, { children: "No docs passed into Duplicator Tool" }), $[10] = t02) : t02 = $[10], t02;
|
|
788
|
+
}
|
|
789
|
+
if (!pluginConfig) {
|
|
790
|
+
let t02;
|
|
791
|
+
return $[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(Feedback, { children: "No plugin config" }), $[11] = t02) : t02 = $[11], t02;
|
|
792
|
+
}
|
|
793
|
+
let t0;
|
|
794
|
+
return $[12] !== docs || $[13] !== onDuplicated || $[14] !== pluginConfig || $[15] !== secrets.bearerToken ? (t0 = /* @__PURE__ */ jsx(DuplicatorWrapper, { docs, token: secrets.bearerToken, pluginConfig, onDuplicated }), $[12] = docs, $[13] = onDuplicated, $[14] = pluginConfig, $[15] = secrets.bearerToken, $[16] = t0) : t0 = $[16], t0;
|
|
795
|
+
}
|
|
796
|
+
function _temp() {
|
|
797
|
+
return null;
|
|
593
798
|
}
|
|
594
799
|
function CrossDatasetDuplicatorAction(props) {
|
|
595
|
-
const
|
|
596
|
-
|
|
800
|
+
const $ = c(3), {
|
|
801
|
+
docs,
|
|
802
|
+
onDuplicated
|
|
803
|
+
} = props;
|
|
804
|
+
let t0;
|
|
805
|
+
return $[0] !== docs || $[1] !== onDuplicated ? (t0 = /* @__PURE__ */ jsx(CrossDatasetDuplicator, { mode: "action", docs, onDuplicated }), $[0] = docs, $[1] = onDuplicated, $[2] = t0) : t0 = $[2], t0;
|
|
597
806
|
}
|
|
598
807
|
const DuplicateToAction = (props) => {
|
|
599
|
-
const {
|
|
808
|
+
const {
|
|
809
|
+
draft,
|
|
810
|
+
published
|
|
811
|
+
} = props, [dialogOpen, setDialogOpen] = useState(!1);
|
|
600
812
|
return {
|
|
601
|
-
disabled: draft,
|
|
813
|
+
disabled: !!draft,
|
|
602
814
|
title: draft ? "Document must be Published to begin" : null,
|
|
603
815
|
label: "Duplicate to...",
|
|
604
816
|
dialog: dialogOpen && published && {
|
|
605
817
|
type: "modal",
|
|
606
818
|
title: "Cross Dataset Duplicator",
|
|
607
|
-
content: /* @__PURE__ */
|
|
608
|
-
onClose: () =>
|
|
609
|
-
onComplete(), setDialogOpen(!1);
|
|
610
|
-
}
|
|
819
|
+
content: /* @__PURE__ */ jsx(CrossDatasetDuplicatorAction, { docs: [published] }),
|
|
820
|
+
onClose: () => setDialogOpen(!1)
|
|
611
821
|
},
|
|
612
822
|
onHandle: () => setDialogOpen(!0),
|
|
613
|
-
icon:
|
|
823
|
+
icon: LaunchIcon
|
|
614
824
|
};
|
|
615
825
|
};
|
|
616
826
|
DuplicateToAction.action = "duplicateTo";
|
|
617
827
|
function CrossDatasetDuplicatorTool(props) {
|
|
618
|
-
const
|
|
619
|
-
|
|
828
|
+
const $ = c(6);
|
|
829
|
+
let t0;
|
|
830
|
+
$[0] !== props.tool.options ? (t0 = props.tool.options ?? {}, $[0] = props.tool.options, $[1] = t0) : t0 = $[1];
|
|
831
|
+
const {
|
|
832
|
+
docs: t1
|
|
833
|
+
} = t0;
|
|
834
|
+
let t2;
|
|
835
|
+
$[2] !== t1 ? (t2 = t1 === void 0 ? [] : t1, $[2] = t1, $[3] = t2) : t2 = $[3];
|
|
836
|
+
const docs = t2;
|
|
837
|
+
let t3;
|
|
838
|
+
return $[4] !== docs ? (t3 = /* @__PURE__ */ jsx(CrossDatasetDuplicator, { mode: "tool", docs }), $[4] = docs, $[5] = t3) : t3 = $[5], t3;
|
|
620
839
|
}
|
|
621
840
|
const crossDatasetDuplicatorTool = () => ({
|
|
622
841
|
title: "Duplicator",
|
|
623
842
|
name: "duplicator",
|
|
624
|
-
icon:
|
|
843
|
+
icon: LaunchIcon,
|
|
625
844
|
component: CrossDatasetDuplicatorTool,
|
|
626
845
|
options: {
|
|
627
846
|
docs: []
|
|
628
847
|
}
|
|
629
|
-
}), crossDatasetDuplicator =
|
|
630
|
-
const pluginConfig = {
|
|
848
|
+
}), crossDatasetDuplicator = definePlugin((config = {}) => {
|
|
849
|
+
const pluginConfig = {
|
|
850
|
+
...DEFAULT_CONFIG,
|
|
851
|
+
...config
|
|
852
|
+
}, {
|
|
853
|
+
types
|
|
854
|
+
} = pluginConfig;
|
|
631
855
|
return {
|
|
632
856
|
name: "@sanity/cross-dataset-duplicator",
|
|
633
857
|
tools: (prev) => pluginConfig.tool ? [...prev, crossDatasetDuplicatorTool()] : prev,
|
|
634
858
|
studio: {
|
|
635
859
|
components: {
|
|
636
|
-
layout: (props) => ConfigProvider
|
|
860
|
+
layout: (props) => /* @__PURE__ */ jsx(ConfigProvider, { ...props, pluginConfig })
|
|
637
861
|
}
|
|
638
862
|
},
|
|
639
863
|
document: {
|
|
640
|
-
actions: (prev, {
|
|
864
|
+
actions: (prev, {
|
|
865
|
+
schemaType
|
|
866
|
+
}) => types && types.includes(schemaType) ? [...prev, DuplicateToAction] : prev
|
|
641
867
|
}
|
|
642
868
|
};
|
|
643
869
|
});
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
870
|
+
export {
|
|
871
|
+
CrossDatasetDuplicatorAction,
|
|
872
|
+
DuplicateToAction,
|
|
873
|
+
crossDatasetDuplicator,
|
|
874
|
+
useCrossDatasetDuplicatorConfig
|
|
875
|
+
};
|
|
648
876
|
//# sourceMappingURL=index.js.map
|