@sanity/document-internationalization 4.1.0 → 5.0.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/LICENSE +1 -1
- package/README.md +11 -35
- package/dist/_chunks-es/{resources.mjs → resources.js} +1 -1
- package/dist/{_chunks-cjs → _chunks-es}/resources.js.map +1 -1
- package/dist/index.d.ts +59 -92
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +997 -1327
- package/dist/index.js.map +1 -1
- package/package.json +35 -73
- package/dist/_chunks-cjs/resources.js +0 -8
- package/dist/_chunks-es/resources.mjs.map +0 -1
- package/dist/_legacy/resources.esm.js +0 -9
- package/dist/_legacy/resources.esm.js.map +0 -1
- package/dist/index.d.mts +0 -110
- package/dist/index.esm.js +0 -1647
- package/dist/index.esm.js.map +0 -1
- package/dist/index.mjs +0 -1647
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/actions/DeleteMetadataAction.tsx +0 -93
- package/src/actions/DeleteTranslationAction.tsx +0 -102
- package/src/actions/DuplicateWithTranslationsAction.tsx +0 -251
- package/src/badges/index.tsx +0 -27
- package/src/components/BulkPublish/DocumentCheck.tsx +0 -90
- package/src/components/BulkPublish/Info.tsx +0 -28
- package/src/components/BulkPublish/InfoIcon.tsx +0 -34
- package/src/components/BulkPublish/index.tsx +0 -181
- package/src/components/ConstrainedBox.tsx +0 -6
- package/src/components/DeleteTranslationDialog/DocumentPreview.tsx +0 -19
- package/src/components/DeleteTranslationDialog/index.tsx +0 -111
- package/src/components/DeleteTranslationDialog/separateReferences.ts +0 -23
- package/src/components/DeleteTranslationFooter.tsx +0 -28
- package/src/components/DocumentInternationalizationContext.tsx +0 -47
- package/src/components/DocumentInternationalizationMenu.tsx +0 -235
- package/src/components/LanguageManage.tsx +0 -108
- package/src/components/LanguageOption.tsx +0 -259
- package/src/components/LanguagePatch.tsx +0 -67
- package/src/components/OptimisticallyStrengthen/ReferencePatcher.tsx +0 -50
- package/src/components/OptimisticallyStrengthen/index.tsx +0 -34
- package/src/components/Warning.tsx +0 -18
- package/src/constants.ts +0 -16
- package/src/hooks/useLanguageMetadata.tsx +0 -26
- package/src/hooks/useOpenInNewPane.tsx +0 -33
- package/src/i18n/index.ts +0 -21
- package/src/i18n/resources.ts +0 -7
- package/src/index.ts +0 -6
- package/src/plugin.tsx +0 -239
- package/src/schema/translation/metadata.ts +0 -68
- package/src/types.ts +0 -99
- package/src/utils/createReference.ts +0 -20
- package/src/utils/excludePaths.ts +0 -123
- package/v2-incompatible.js +0 -11
package/dist/index.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { TrashIcon, CopyIcon, CogIcon, SplitVerticalIcon, CheckmarkIcon, AddIcon, EditIcon, TranslateIcon, InfoOutlineIcon } from "@sanity/icons";
|
|
3
|
+
import { Flex, Spinner, Card, Text, Stack, Grid, Button, useToast, Tooltip, Box, Badge, useClickOutsideEvent, TextInput, Popover, Inline, Dialog } from "@sanity/ui";
|
|
4
|
+
import { useEffect, createContext, use, useContext, useState, useCallback, useRef, useMemo } from "react";
|
|
5
|
+
import { useSchema, Preview, useClient, useWorkspace, defineLocaleResourceBundle, useDocumentStore, useDocumentOperation, useDocumentPairPermissions, DEFAULT_STUDIO_CLIENT_OPTIONS, useTranslation, useCurrentUser, InsufficientPermissionsMessage, isDocumentSchemaType, pathToString, useEditState, useValidationStatus, TextWithTone, PatchEvent, unset, defineType, defineField, definePlugin, isSanityDocument } from "sanity";
|
|
6
|
+
import { c } from "react/compiler-runtime";
|
|
7
|
+
import { Feedback, useListeningQuery } from "sanity-plugin-utils";
|
|
8
|
+
import { uuid } from "@sanity/uuid";
|
|
9
|
+
import { firstValueFrom, filter } from "rxjs";
|
|
10
|
+
import { useRouter } from "sanity/router";
|
|
11
|
+
import { structureLocaleNamespace, usePaneRouter, useDocumentPane } from "sanity/structure";
|
|
12
|
+
import { Mutation, extractWithPath } from "@sanity/mutator";
|
|
13
|
+
import { internationalizedArray } from "sanity-plugin-internationalized-array";
|
|
4
14
|
function DocumentPreview(props) {
|
|
5
|
-
const
|
|
6
|
-
|
|
15
|
+
const $ = c(7), schema = useSchema();
|
|
16
|
+
let t0;
|
|
17
|
+
$[0] !== props.type || $[1] !== schema ? (t0 = schema.get(props.type), $[0] = props.type, $[1] = schema, $[2] = t0) : t0 = $[2];
|
|
18
|
+
const schemaType = t0;
|
|
19
|
+
if (!schemaType) {
|
|
20
|
+
let t12;
|
|
21
|
+
return $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t12 = /* @__PURE__ */ jsx(Feedback, { tone: "critical", title: "Schema type not found" }), $[3] = t12) : t12 = $[3], t12;
|
|
22
|
+
}
|
|
23
|
+
let t1;
|
|
24
|
+
return $[4] !== props.value || $[5] !== schemaType ? (t1 = /* @__PURE__ */ jsx(Preview, { value: props.value, schemaType }), $[4] = props.value, $[5] = schemaType, $[6] = t1) : t1 = $[6], t1;
|
|
7
25
|
}
|
|
8
26
|
const METADATA_SCHEMA_NAME = "translation.metadata", TRANSLATIONS_ARRAY_NAME = "translations", API_VERSION = "2025-02-19", DEFAULT_CONFIG = {
|
|
9
27
|
supportedLanguages: [],
|
|
@@ -20,156 +38,175 @@ function separateReferences(data = []) {
|
|
|
20
38
|
const translations = [], otherReferences = [];
|
|
21
39
|
return data && data.length > 0 && data.forEach((doc) => {
|
|
22
40
|
doc._type === METADATA_SCHEMA_NAME ? translations.push(doc) : otherReferences.push(doc);
|
|
23
|
-
}), {
|
|
41
|
+
}), {
|
|
42
|
+
translations,
|
|
43
|
+
otherReferences
|
|
44
|
+
};
|
|
24
45
|
}
|
|
25
46
|
function DeleteTranslationDialog(props) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
const $ = c(33), {
|
|
48
|
+
doc,
|
|
49
|
+
documentId,
|
|
50
|
+
setTranslations
|
|
51
|
+
} = props;
|
|
52
|
+
let t0;
|
|
53
|
+
$[0] !== documentId ? (t0 = {
|
|
54
|
+
id: documentId
|
|
55
|
+
}, $[0] = documentId, $[1] = t0) : t0 = $[1];
|
|
56
|
+
let t1;
|
|
57
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[2] = t1) : t1 = $[2];
|
|
58
|
+
let t2;
|
|
59
|
+
$[3] !== t0 ? (t2 = {
|
|
60
|
+
params: t0,
|
|
61
|
+
initialValue: t1
|
|
62
|
+
}, $[3] = t0, $[4] = t2) : t2 = $[4];
|
|
63
|
+
const {
|
|
64
|
+
data,
|
|
65
|
+
loading
|
|
66
|
+
} = useListeningQuery("*[references($id)]{_id, _type}", t2), t3 = data;
|
|
67
|
+
let t4;
|
|
68
|
+
$[5] !== t3 ? (t4 = separateReferences(t3), $[5] = t3, $[6] = t4) : t4 = $[6];
|
|
69
|
+
const {
|
|
70
|
+
translations,
|
|
71
|
+
otherReferences
|
|
72
|
+
} = t4;
|
|
73
|
+
let t5, t6;
|
|
74
|
+
if ($[7] !== setTranslations || $[8] !== translations ? (t5 = () => {
|
|
34
75
|
setTranslations(translations);
|
|
35
|
-
}, [setTranslations, translations]
|
|
36
|
-
|
|
37
|
-
/* @__PURE__ */
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
76
|
+
}, t6 = [setTranslations, translations], $[7] = setTranslations, $[8] = translations, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]), useEffect(t5, t6), loading) {
|
|
77
|
+
let t72;
|
|
78
|
+
return $[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t72 = /* @__PURE__ */ jsx(Flex, { padding: 4, align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) }), $[11] = t72) : t72 = $[11], t72;
|
|
79
|
+
}
|
|
80
|
+
let t7;
|
|
81
|
+
$[12] !== translations ? (t7 = translations && translations.length > 0 ? /* @__PURE__ */ jsx(Text, { children: "This document is a language-specific version which other translations depend on." }) : /* @__PURE__ */ jsx(Text, { children: "This document does not have connected translations." }), $[12] = translations, $[13] = t7) : t7 = $[13];
|
|
82
|
+
let t8;
|
|
83
|
+
$[14] !== translations ? (t8 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: translations && translations.length > 0 ? /* @__PURE__ */ jsx(Fragment, { children: "Before this document can be deleted" }) : /* @__PURE__ */ jsx(Fragment, { children: "This document can now be deleted" }) }), $[14] = translations, $[15] = t8) : t8 = $[15];
|
|
84
|
+
let t9;
|
|
85
|
+
$[16] !== doc ? (t9 = /* @__PURE__ */ jsx(DocumentPreview, { value: doc, type: doc._type }), $[16] = doc, $[17] = t9) : t9 = $[17];
|
|
86
|
+
let t10;
|
|
87
|
+
$[18] !== translations ? (t10 = translations && translations.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
88
|
+
/* @__PURE__ */ jsx(Card, { borderTop: !0 }),
|
|
89
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
|
|
90
|
+
"The reference in",
|
|
91
|
+
" ",
|
|
92
|
+
translations.length === 1 ? "this translations document" : "these translations documents",
|
|
93
|
+
" ",
|
|
94
|
+
"must be removed"
|
|
95
|
+
] }),
|
|
96
|
+
translations.map(_temp$4)
|
|
97
|
+
] }) : null, $[18] = translations, $[19] = t10) : t10 = $[19];
|
|
98
|
+
let t11;
|
|
99
|
+
$[20] !== otherReferences ? (t11 = otherReferences && otherReferences.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
100
|
+
/* @__PURE__ */ jsx(Card, { borderTop: !0 }),
|
|
101
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
|
|
102
|
+
otherReferences.length === 1 ? "There is an additional reference" : "There are additional references",
|
|
103
|
+
" ",
|
|
104
|
+
"to this document"
|
|
105
|
+
] }),
|
|
106
|
+
otherReferences.map(_temp2$3)
|
|
107
|
+
] }) : null, $[20] = otherReferences, $[21] = t11) : t11 = $[21];
|
|
108
|
+
let t12;
|
|
109
|
+
$[22] !== t10 || $[23] !== t11 || $[24] !== t8 || $[25] !== t9 ? (t12 = /* @__PURE__ */ jsx(Card, { border: !0, padding: 3, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
110
|
+
t8,
|
|
111
|
+
t9,
|
|
112
|
+
t10,
|
|
113
|
+
t11
|
|
114
|
+
] }) }), $[22] = t10, $[23] = t11, $[24] = t8, $[25] = t9, $[26] = t12) : t12 = $[26];
|
|
115
|
+
let t13;
|
|
116
|
+
$[27] !== otherReferences.length ? (t13 = otherReferences.length === 0 ? /* @__PURE__ */ jsx(Text, { children: "This document has no other references." }) : /* @__PURE__ */ jsx(Text, { children: "You may not be able to delete this document because other documents refer to it." }), $[27] = otherReferences.length, $[28] = t13) : t13 = $[28];
|
|
117
|
+
let t14;
|
|
118
|
+
return $[29] !== t12 || $[30] !== t13 || $[31] !== t7 ? (t14 = /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
119
|
+
t7,
|
|
120
|
+
t12,
|
|
121
|
+
t13
|
|
122
|
+
] }), $[29] = t12, $[30] = t13, $[31] = t7, $[32] = t14) : t14 = $[32], t14;
|
|
77
123
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Grid, { columns: 2, gap: 2, children: [
|
|
81
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { text: "Cancel", onClick: onClose, mode: "ghost" }),
|
|
82
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
83
|
-
ui.Button,
|
|
84
|
-
{
|
|
85
|
-
text: translations && translations.length > 0 ? "Unset translation reference" : "Delete document",
|
|
86
|
-
onClick: onProceed,
|
|
87
|
-
tone: "critical"
|
|
88
|
-
}
|
|
89
|
-
)
|
|
90
|
-
] });
|
|
124
|
+
function _temp2$3(reference) {
|
|
125
|
+
return /* @__PURE__ */ jsx(DocumentPreview, { value: reference, type: reference._type }, reference._id);
|
|
91
126
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (arrA === arrB)
|
|
95
|
-
return !0;
|
|
96
|
-
if (!arrA || !arrB)
|
|
97
|
-
return !1;
|
|
98
|
-
const len = arrA.length;
|
|
99
|
-
if (arrB.length !== len)
|
|
100
|
-
return !1;
|
|
101
|
-
for (let i = 0; i < len; i++)
|
|
102
|
-
if (!equal(arrA[i], arrB[i]))
|
|
103
|
-
return !1;
|
|
104
|
-
return !0;
|
|
127
|
+
function _temp$4(translation) {
|
|
128
|
+
return /* @__PURE__ */ jsx(DocumentPreview, { value: translation, type: translation._type }, translation._id);
|
|
105
129
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
remove: () => {
|
|
123
|
-
const index = globalCache.indexOf(entry);
|
|
124
|
-
index !== -1 && globalCache.splice(index, 1);
|
|
125
|
-
},
|
|
126
|
-
promise: (
|
|
127
|
-
// Execute the promise
|
|
128
|
-
(isPromise(fn) ? fn : fn(...keys)).then((response) => {
|
|
129
|
-
entry.response = response, config2.lifespan && config2.lifespan > 0 && (entry.timeout = setTimeout(entry.remove, config2.lifespan));
|
|
130
|
-
}).catch((error) => entry.error = error)
|
|
131
|
-
)
|
|
132
|
-
};
|
|
133
|
-
if (globalCache.push(entry), !preload)
|
|
134
|
-
throw entry.promise;
|
|
130
|
+
function DeleteTranslationFooter(props) {
|
|
131
|
+
const $ = c(8), {
|
|
132
|
+
translations,
|
|
133
|
+
onClose,
|
|
134
|
+
onProceed
|
|
135
|
+
} = props;
|
|
136
|
+
let t0;
|
|
137
|
+
$[0] !== onClose ? (t0 = /* @__PURE__ */ jsx(Button, { text: "Cancel", onClick: onClose, mode: "ghost" }), $[0] = onClose, $[1] = t0) : t0 = $[1];
|
|
138
|
+
const t1 = translations && translations.length > 0 ? "Unset translation reference" : "Delete document";
|
|
139
|
+
let t2;
|
|
140
|
+
$[2] !== onProceed || $[3] !== t1 ? (t2 = /* @__PURE__ */ jsx(Button, { text: t1, onClick: onProceed, tone: "critical" }), $[2] = onProceed, $[3] = t1, $[4] = t2) : t2 = $[4];
|
|
141
|
+
let t3;
|
|
142
|
+
return $[5] !== t0 || $[6] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Grid, { columns: 2, gap: 2, children: [
|
|
143
|
+
t0,
|
|
144
|
+
t2
|
|
145
|
+
] }), $[5] = t0, $[6] = t2, $[7] = t3) : t3 = $[7], t3;
|
|
135
146
|
}
|
|
136
|
-
const
|
|
137
|
-
var __defProp$3 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
|
|
138
|
-
for (var prop in b || (b = {}))
|
|
139
|
-
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
140
|
-
if (__getOwnPropSymbols$3)
|
|
141
|
-
for (var prop of __getOwnPropSymbols$3(b))
|
|
142
|
-
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
143
|
-
return a;
|
|
144
|
-
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
145
|
-
const DocumentInternationalizationContext = react.createContext(DEFAULT_CONFIG);
|
|
147
|
+
const DocumentInternationalizationContext = createContext(DEFAULT_CONFIG);
|
|
146
148
|
function useDocumentInternationalizationContext() {
|
|
147
|
-
return
|
|
149
|
+
return useContext(DocumentInternationalizationContext);
|
|
150
|
+
}
|
|
151
|
+
const promiseCache = /* @__PURE__ */ new Map();
|
|
152
|
+
function createCacheKey(workspaceId) {
|
|
153
|
+
return `languages-${workspaceId}`;
|
|
154
|
+
}
|
|
155
|
+
function createOrGetPromise(fn, cacheKey) {
|
|
156
|
+
const cached = promiseCache.get(cacheKey);
|
|
157
|
+
if (cached)
|
|
158
|
+
return cached;
|
|
159
|
+
const promise = fn();
|
|
160
|
+
return promiseCache.set(cacheKey, promise), promise;
|
|
148
161
|
}
|
|
149
162
|
function DocumentInternationalizationProvider(props) {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const $ = c(18), {
|
|
164
|
+
pluginConfig
|
|
165
|
+
} = props;
|
|
166
|
+
let t0;
|
|
167
|
+
$[0] !== pluginConfig.apiVersion ? (t0 = {
|
|
168
|
+
apiVersion: pluginConfig.apiVersion
|
|
169
|
+
}, $[0] = pluginConfig.apiVersion, $[1] = t0) : t0 = $[1];
|
|
170
|
+
const client = useClient(t0), workspaceId = useWorkspace().name ?? "";
|
|
171
|
+
let t1;
|
|
172
|
+
$[2] !== workspaceId ? (t1 = createCacheKey(workspaceId), $[2] = workspaceId, $[3] = t1) : t1 = $[3];
|
|
173
|
+
const cacheKey = t1;
|
|
174
|
+
let t2;
|
|
175
|
+
bb0: {
|
|
176
|
+
if (Array.isArray(pluginConfig.supportedLanguages)) {
|
|
177
|
+
t2 = null;
|
|
178
|
+
break bb0;
|
|
159
179
|
}
|
|
160
|
-
|
|
180
|
+
let t32;
|
|
181
|
+
$[4] !== client || $[5] !== pluginConfig ? (t32 = async () => typeof pluginConfig.supportedLanguages == "function" ? pluginConfig.supportedLanguages(client) : pluginConfig.supportedLanguages, $[4] = client, $[5] = pluginConfig, $[6] = t32) : t32 = $[6];
|
|
182
|
+
let t42;
|
|
183
|
+
$[7] !== cacheKey || $[8] !== t32 ? (t42 = createOrGetPromise(t32, cacheKey), $[7] = cacheKey, $[8] = t32, $[9] = t42) : t42 = $[9], t2 = t42;
|
|
184
|
+
}
|
|
185
|
+
const languagesPromise = t2, supportedLanguages = languagesPromise ? use(languagesPromise) : pluginConfig.supportedLanguages;
|
|
186
|
+
let t3;
|
|
187
|
+
$[10] !== pluginConfig || $[11] !== supportedLanguages ? (t3 = {
|
|
188
|
+
...pluginConfig,
|
|
189
|
+
supportedLanguages
|
|
190
|
+
}, $[10] = pluginConfig, $[11] = supportedLanguages, $[12] = t3) : t3 = $[12];
|
|
191
|
+
let t4;
|
|
192
|
+
$[13] !== props ? (t4 = props.renderDefault(props), $[13] = props, $[14] = t4) : t4 = $[14];
|
|
193
|
+
let t5;
|
|
194
|
+
return $[15] !== t3 || $[16] !== t4 ? (t5 = /* @__PURE__ */ jsx(DocumentInternationalizationContext.Provider, { value: t3, children: t4 }), $[15] = t3, $[16] = t4, $[17] = t5) : t5 = $[17], t5;
|
|
161
195
|
}
|
|
162
196
|
const DeleteTranslationAction = (props) => {
|
|
163
|
-
const {
|
|
197
|
+
const {
|
|
198
|
+
id: documentId,
|
|
199
|
+
published,
|
|
200
|
+
draft
|
|
201
|
+
} = props, doc = draft || published, {
|
|
202
|
+
languageField
|
|
203
|
+
} = useDocumentInternationalizationContext(), [isDialogOpen, setDialogOpen] = useState(!1), [translations, setTranslations] = useState([]), onClose = useCallback(() => setDialogOpen(!1), []), rawDocumentLanguage = doc ? doc[languageField] : null, documentLanguage = typeof rawDocumentLanguage == "string" ? rawDocumentLanguage : null, toast = useToast(), client = useClient({
|
|
204
|
+
apiVersion: API_VERSION
|
|
205
|
+
}), onProceed = useCallback(() => {
|
|
164
206
|
const tx = client.transaction();
|
|
165
207
|
let operation = "DELETE";
|
|
166
208
|
documentLanguage && translations.length > 0 ? (operation = "UNSET", translations.forEach((translation) => {
|
|
167
|
-
tx.patch(
|
|
168
|
-
translation._id,
|
|
169
|
-
(patch) => patch.unset([
|
|
170
|
-
`${TRANSLATIONS_ARRAY_NAME}[_key == "${documentLanguage}"]`
|
|
171
|
-
])
|
|
172
|
-
);
|
|
209
|
+
tx.patch(translation._id, (patch) => patch.unset([`${TRANSLATIONS_ARRAY_NAME}[_key == "${documentLanguage}"]`]));
|
|
173
210
|
})) : (tx.delete(documentId), tx.delete(`drafts.${documentId}`)), tx.commit().then(() => {
|
|
174
211
|
operation === "DELETE" && onClose(), toast.push({
|
|
175
212
|
status: "success",
|
|
@@ -187,7 +224,7 @@ const DeleteTranslationAction = (props) => {
|
|
|
187
224
|
return {
|
|
188
225
|
label: "Delete translation...",
|
|
189
226
|
disabled: !doc || !documentLanguage,
|
|
190
|
-
icon:
|
|
227
|
+
icon: TrashIcon,
|
|
191
228
|
tone: "critical",
|
|
192
229
|
onHandle: () => {
|
|
193
230
|
setDialogOpen(!0);
|
|
@@ -196,593 +233,260 @@ const DeleteTranslationAction = (props) => {
|
|
|
196
233
|
type: "dialog",
|
|
197
234
|
onClose,
|
|
198
235
|
header: "Delete translation",
|
|
199
|
-
content: doc ? /* @__PURE__ */
|
|
200
|
-
|
|
201
|
-
{
|
|
202
|
-
doc,
|
|
203
|
-
documentId,
|
|
204
|
-
setTranslations
|
|
205
|
-
}
|
|
206
|
-
) : null,
|
|
207
|
-
footer: /* @__PURE__ */ jsxRuntime.jsx(
|
|
208
|
-
DeleteTranslationFooter,
|
|
209
|
-
{
|
|
210
|
-
onClose,
|
|
211
|
-
onProceed,
|
|
212
|
-
translations
|
|
213
|
-
}
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
var extendStatics = function(d, b) {
|
|
219
|
-
return extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
220
|
-
d2.__proto__ = b2;
|
|
221
|
-
} || function(d2, b2) {
|
|
222
|
-
for (var p in b2)
|
|
223
|
-
Object.prototype.hasOwnProperty.call(b2, p) && (d2[p] = b2[p]);
|
|
224
|
-
}, extendStatics(d, b);
|
|
225
|
-
};
|
|
226
|
-
function __extends(d, b) {
|
|
227
|
-
if (typeof b != "function" && b !== null)
|
|
228
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
229
|
-
extendStatics(d, b);
|
|
230
|
-
function __() {
|
|
231
|
-
this.constructor = d;
|
|
232
|
-
}
|
|
233
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
234
|
-
}
|
|
235
|
-
function __values(o) {
|
|
236
|
-
var s = typeof Symbol == "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
237
|
-
if (m)
|
|
238
|
-
return m.call(o);
|
|
239
|
-
if (o && typeof o.length == "number")
|
|
240
|
-
return {
|
|
241
|
-
next: function() {
|
|
242
|
-
return o && i >= o.length && (o = void 0), { value: o && o[i++], done: !o };
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
246
|
-
}
|
|
247
|
-
function __read(o, n) {
|
|
248
|
-
var m = typeof Symbol == "function" && o[Symbol.iterator];
|
|
249
|
-
if (!m)
|
|
250
|
-
return o;
|
|
251
|
-
var i = m.call(o), r, ar = [], e;
|
|
252
|
-
try {
|
|
253
|
-
for (; (n === void 0 || n-- > 0) && !(r = i.next()).done; )
|
|
254
|
-
ar.push(r.value);
|
|
255
|
-
} catch (error) {
|
|
256
|
-
e = { error };
|
|
257
|
-
} finally {
|
|
258
|
-
try {
|
|
259
|
-
r && !r.done && (m = i.return) && m.call(i);
|
|
260
|
-
} finally {
|
|
261
|
-
if (e)
|
|
262
|
-
throw e.error;
|
|
236
|
+
content: doc ? /* @__PURE__ */ jsx(DeleteTranslationDialog, { doc, documentId, setTranslations }) : null,
|
|
237
|
+
footer: /* @__PURE__ */ jsx(DeleteTranslationFooter, { onClose, onProceed, translations })
|
|
263
238
|
}
|
|
264
|
-
}
|
|
265
|
-
return ar;
|
|
266
|
-
}
|
|
267
|
-
function __spreadArray(to, from, pack) {
|
|
268
|
-
if (pack || arguments.length === 2)
|
|
269
|
-
for (var i = 0, l = from.length, ar; i < l; i++)
|
|
270
|
-
(ar || !(i in from)) && (ar || (ar = Array.prototype.slice.call(from, 0, i)), ar[i] = from[i]);
|
|
271
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
272
|
-
}
|
|
273
|
-
function isFunction(value) {
|
|
274
|
-
return typeof value == "function";
|
|
275
|
-
}
|
|
276
|
-
function createErrorClass(createImpl) {
|
|
277
|
-
var _super = function(instance) {
|
|
278
|
-
Error.call(instance), instance.stack = new Error().stack;
|
|
279
|
-
}, ctorFunc = createImpl(_super);
|
|
280
|
-
return ctorFunc.prototype = Object.create(Error.prototype), ctorFunc.prototype.constructor = ctorFunc, ctorFunc;
|
|
281
|
-
}
|
|
282
|
-
var UnsubscriptionError = createErrorClass(function(_super) {
|
|
283
|
-
return function(errors) {
|
|
284
|
-
_super(this), this.message = errors ? errors.length + ` errors occurred during unsubscription:
|
|
285
|
-
` + errors.map(function(err, i) {
|
|
286
|
-
return i + 1 + ") " + err.toString();
|
|
287
|
-
}).join(`
|
|
288
|
-
`) : "", this.name = "UnsubscriptionError", this.errors = errors;
|
|
289
239
|
};
|
|
290
|
-
}
|
|
291
|
-
function arrRemove(arr, item) {
|
|
292
|
-
if (arr) {
|
|
293
|
-
var index = arr.indexOf(item);
|
|
294
|
-
0 <= index && arr.splice(index, 1);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
var Subscription = function() {
|
|
298
|
-
function Subscription2(initialTeardown) {
|
|
299
|
-
this.initialTeardown = initialTeardown, this.closed = !1, this._parentage = null, this._finalizers = null;
|
|
300
|
-
}
|
|
301
|
-
return Subscription2.prototype.unsubscribe = function() {
|
|
302
|
-
var e_1, _a, e_2, _b, errors;
|
|
303
|
-
if (!this.closed) {
|
|
304
|
-
this.closed = !0;
|
|
305
|
-
var _parentage = this._parentage;
|
|
306
|
-
if (_parentage)
|
|
307
|
-
if (this._parentage = null, Array.isArray(_parentage))
|
|
308
|
-
try {
|
|
309
|
-
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
310
|
-
var parent_1 = _parentage_1_1.value;
|
|
311
|
-
parent_1.remove(this);
|
|
312
|
-
}
|
|
313
|
-
} catch (e_1_1) {
|
|
314
|
-
e_1 = { error: e_1_1 };
|
|
315
|
-
} finally {
|
|
316
|
-
try {
|
|
317
|
-
_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return) && _a.call(_parentage_1);
|
|
318
|
-
} finally {
|
|
319
|
-
if (e_1)
|
|
320
|
-
throw e_1.error;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else
|
|
324
|
-
_parentage.remove(this);
|
|
325
|
-
var initialFinalizer = this.initialTeardown;
|
|
326
|
-
if (isFunction(initialFinalizer))
|
|
327
|
-
try {
|
|
328
|
-
initialFinalizer();
|
|
329
|
-
} catch (e) {
|
|
330
|
-
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
331
|
-
}
|
|
332
|
-
var _finalizers = this._finalizers;
|
|
333
|
-
if (_finalizers) {
|
|
334
|
-
this._finalizers = null;
|
|
335
|
-
try {
|
|
336
|
-
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
337
|
-
var finalizer = _finalizers_1_1.value;
|
|
338
|
-
try {
|
|
339
|
-
execFinalizer(finalizer);
|
|
340
|
-
} catch (err) {
|
|
341
|
-
errors = errors != null ? errors : [], err instanceof UnsubscriptionError ? errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors)) : errors.push(err);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
} catch (e_2_1) {
|
|
345
|
-
e_2 = { error: e_2_1 };
|
|
346
|
-
} finally {
|
|
347
|
-
try {
|
|
348
|
-
_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return) && _b.call(_finalizers_1);
|
|
349
|
-
} finally {
|
|
350
|
-
if (e_2)
|
|
351
|
-
throw e_2.error;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
if (errors)
|
|
356
|
-
throw new UnsubscriptionError(errors);
|
|
357
|
-
}
|
|
358
|
-
}, Subscription2.prototype.add = function(teardown) {
|
|
359
|
-
var _a;
|
|
360
|
-
if (teardown && teardown !== this)
|
|
361
|
-
if (this.closed)
|
|
362
|
-
execFinalizer(teardown);
|
|
363
|
-
else {
|
|
364
|
-
if (teardown instanceof Subscription2) {
|
|
365
|
-
if (teardown.closed || teardown._hasParent(this))
|
|
366
|
-
return;
|
|
367
|
-
teardown._addParent(this);
|
|
368
|
-
}
|
|
369
|
-
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
370
|
-
}
|
|
371
|
-
}, Subscription2.prototype._hasParent = function(parent) {
|
|
372
|
-
var _parentage = this._parentage;
|
|
373
|
-
return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
|
|
374
|
-
}, Subscription2.prototype._addParent = function(parent) {
|
|
375
|
-
var _parentage = this._parentage;
|
|
376
|
-
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
377
|
-
}, Subscription2.prototype._removeParent = function(parent) {
|
|
378
|
-
var _parentage = this._parentage;
|
|
379
|
-
_parentage === parent ? this._parentage = null : Array.isArray(_parentage) && arrRemove(_parentage, parent);
|
|
380
|
-
}, Subscription2.prototype.remove = function(teardown) {
|
|
381
|
-
var _finalizers = this._finalizers;
|
|
382
|
-
_finalizers && arrRemove(_finalizers, teardown), teardown instanceof Subscription2 && teardown._removeParent(this);
|
|
383
|
-
}, Subscription2.EMPTY = function() {
|
|
384
|
-
var empty = new Subscription2();
|
|
385
|
-
return empty.closed = !0, empty;
|
|
386
|
-
}(), Subscription2;
|
|
387
|
-
}();
|
|
388
|
-
function isSubscription(value) {
|
|
389
|
-
return value instanceof Subscription || value && "closed" in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
|
|
390
|
-
}
|
|
391
|
-
function execFinalizer(finalizer) {
|
|
392
|
-
isFunction(finalizer) ? finalizer() : finalizer.unsubscribe();
|
|
393
|
-
}
|
|
394
|
-
var config = {
|
|
395
|
-
onUnhandledError: null,
|
|
396
|
-
onStoppedNotification: null,
|
|
397
|
-
Promise: void 0,
|
|
398
|
-
useDeprecatedSynchronousErrorHandling: !1,
|
|
399
|
-
useDeprecatedNextContext: !1
|
|
400
|
-
}, timeoutProvider = {
|
|
401
|
-
setTimeout: function(handler, timeout) {
|
|
402
|
-
for (var args = [], _i = 2; _i < arguments.length; _i++)
|
|
403
|
-
args[_i - 2] = arguments[_i];
|
|
404
|
-
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
405
|
-
},
|
|
406
|
-
clearTimeout: function(handle) {
|
|
407
|
-
return clearTimeout(handle);
|
|
408
|
-
},
|
|
409
|
-
delegate: void 0
|
|
410
|
-
};
|
|
411
|
-
function reportUnhandledError(err) {
|
|
412
|
-
timeoutProvider.setTimeout(function() {
|
|
413
|
-
throw err;
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
function noop() {
|
|
417
|
-
}
|
|
418
|
-
var Subscriber = function(_super) {
|
|
419
|
-
__extends(Subscriber2, _super);
|
|
420
|
-
function Subscriber2(destination) {
|
|
421
|
-
var _this = _super.call(this) || this;
|
|
422
|
-
return _this.isStopped = !1, destination ? (_this.destination = destination, isSubscription(destination) && destination.add(_this)) : _this.destination = EMPTY_OBSERVER, _this;
|
|
423
|
-
}
|
|
424
|
-
return Subscriber2.create = function(next, error, complete) {
|
|
425
|
-
return new SafeSubscriber(next, error, complete);
|
|
426
|
-
}, Subscriber2.prototype.next = function(value) {
|
|
427
|
-
this.isStopped || this._next(value);
|
|
428
|
-
}, Subscriber2.prototype.error = function(err) {
|
|
429
|
-
this.isStopped || (this.isStopped = !0, this._error(err));
|
|
430
|
-
}, Subscriber2.prototype.complete = function() {
|
|
431
|
-
this.isStopped || (this.isStopped = !0, this._complete());
|
|
432
|
-
}, Subscriber2.prototype.unsubscribe = function() {
|
|
433
|
-
this.closed || (this.isStopped = !0, _super.prototype.unsubscribe.call(this), this.destination = null);
|
|
434
|
-
}, Subscriber2.prototype._next = function(value) {
|
|
435
|
-
this.destination.next(value);
|
|
436
|
-
}, Subscriber2.prototype._error = function(err) {
|
|
437
|
-
try {
|
|
438
|
-
this.destination.error(err);
|
|
439
|
-
} finally {
|
|
440
|
-
this.unsubscribe();
|
|
441
|
-
}
|
|
442
|
-
}, Subscriber2.prototype._complete = function() {
|
|
443
|
-
try {
|
|
444
|
-
this.destination.complete();
|
|
445
|
-
} finally {
|
|
446
|
-
this.unsubscribe();
|
|
447
|
-
}
|
|
448
|
-
}, Subscriber2;
|
|
449
|
-
}(Subscription), _bind = Function.prototype.bind;
|
|
450
|
-
function bind(fn, thisArg) {
|
|
451
|
-
return _bind.call(fn, thisArg);
|
|
452
|
-
}
|
|
453
|
-
var ConsumerObserver = function() {
|
|
454
|
-
function ConsumerObserver2(partialObserver) {
|
|
455
|
-
this.partialObserver = partialObserver;
|
|
456
|
-
}
|
|
457
|
-
return ConsumerObserver2.prototype.next = function(value) {
|
|
458
|
-
var partialObserver = this.partialObserver;
|
|
459
|
-
if (partialObserver.next)
|
|
460
|
-
try {
|
|
461
|
-
partialObserver.next(value);
|
|
462
|
-
} catch (error) {
|
|
463
|
-
handleUnhandledError(error);
|
|
464
|
-
}
|
|
465
|
-
}, ConsumerObserver2.prototype.error = function(err) {
|
|
466
|
-
var partialObserver = this.partialObserver;
|
|
467
|
-
if (partialObserver.error)
|
|
468
|
-
try {
|
|
469
|
-
partialObserver.error(err);
|
|
470
|
-
} catch (error) {
|
|
471
|
-
handleUnhandledError(error);
|
|
472
|
-
}
|
|
473
|
-
else
|
|
474
|
-
handleUnhandledError(err);
|
|
475
|
-
}, ConsumerObserver2.prototype.complete = function() {
|
|
476
|
-
var partialObserver = this.partialObserver;
|
|
477
|
-
if (partialObserver.complete)
|
|
478
|
-
try {
|
|
479
|
-
partialObserver.complete();
|
|
480
|
-
} catch (error) {
|
|
481
|
-
handleUnhandledError(error);
|
|
482
|
-
}
|
|
483
|
-
}, ConsumerObserver2;
|
|
484
|
-
}(), SafeSubscriber = function(_super) {
|
|
485
|
-
__extends(SafeSubscriber2, _super);
|
|
486
|
-
function SafeSubscriber2(observerOrNext, error, complete) {
|
|
487
|
-
var _this = _super.call(this) || this, partialObserver;
|
|
488
|
-
if (isFunction(observerOrNext) || !observerOrNext)
|
|
489
|
-
partialObserver = {
|
|
490
|
-
next: observerOrNext != null ? observerOrNext : void 0,
|
|
491
|
-
error: error != null ? error : void 0,
|
|
492
|
-
complete: complete != null ? complete : void 0
|
|
493
|
-
};
|
|
494
|
-
else {
|
|
495
|
-
var context_1;
|
|
496
|
-
_this && config.useDeprecatedNextContext ? (context_1 = Object.create(observerOrNext), context_1.unsubscribe = function() {
|
|
497
|
-
return _this.unsubscribe();
|
|
498
|
-
}, partialObserver = {
|
|
499
|
-
next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
|
500
|
-
error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
|
501
|
-
complete: observerOrNext.complete && bind(observerOrNext.complete, context_1)
|
|
502
|
-
}) : partialObserver = observerOrNext;
|
|
503
|
-
}
|
|
504
|
-
return _this.destination = new ConsumerObserver(partialObserver), _this;
|
|
505
|
-
}
|
|
506
|
-
return SafeSubscriber2;
|
|
507
|
-
}(Subscriber);
|
|
508
|
-
function handleUnhandledError(error) {
|
|
509
|
-
reportUnhandledError(error);
|
|
510
|
-
}
|
|
511
|
-
function defaultErrorHandler(err) {
|
|
512
|
-
throw err;
|
|
513
|
-
}
|
|
514
|
-
var EMPTY_OBSERVER = {
|
|
515
|
-
closed: !0,
|
|
516
|
-
next: noop,
|
|
517
|
-
error: defaultErrorHandler,
|
|
518
|
-
complete: noop
|
|
519
|
-
};
|
|
520
|
-
function hasLift(source) {
|
|
521
|
-
return isFunction(source == null ? void 0 : source.lift);
|
|
522
|
-
}
|
|
523
|
-
function operate(init) {
|
|
524
|
-
return function(source) {
|
|
525
|
-
if (hasLift(source))
|
|
526
|
-
return source.lift(function(liftedSource) {
|
|
527
|
-
try {
|
|
528
|
-
return init(liftedSource, this);
|
|
529
|
-
} catch (err) {
|
|
530
|
-
this.error(err);
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
throw new TypeError("Unable to lift unknown Observable type");
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
537
|
-
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
538
|
-
}
|
|
539
|
-
var OperatorSubscriber = function(_super) {
|
|
540
|
-
__extends(OperatorSubscriber2, _super);
|
|
541
|
-
function OperatorSubscriber2(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
542
|
-
var _this = _super.call(this, destination) || this;
|
|
543
|
-
return _this.onFinalize = onFinalize, _this.shouldUnsubscribe = shouldUnsubscribe, _this._next = onNext ? function(value) {
|
|
544
|
-
try {
|
|
545
|
-
onNext(value);
|
|
546
|
-
} catch (err) {
|
|
547
|
-
destination.error(err);
|
|
548
|
-
}
|
|
549
|
-
} : _super.prototype._next, _this._error = onError ? function(err) {
|
|
550
|
-
try {
|
|
551
|
-
onError(err);
|
|
552
|
-
} catch (err2) {
|
|
553
|
-
destination.error(err2);
|
|
554
|
-
} finally {
|
|
555
|
-
this.unsubscribe();
|
|
556
|
-
}
|
|
557
|
-
} : _super.prototype._error, _this._complete = onComplete ? function() {
|
|
558
|
-
try {
|
|
559
|
-
onComplete();
|
|
560
|
-
} catch (err) {
|
|
561
|
-
destination.error(err);
|
|
562
|
-
} finally {
|
|
563
|
-
this.unsubscribe();
|
|
564
|
-
}
|
|
565
|
-
} : _super.prototype._complete, _this;
|
|
566
|
-
}
|
|
567
|
-
return OperatorSubscriber2.prototype.unsubscribe = function() {
|
|
568
|
-
var _a;
|
|
569
|
-
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
570
|
-
var closed_1 = this.closed;
|
|
571
|
-
_super.prototype.unsubscribe.call(this), !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 || _a.call(this));
|
|
572
|
-
}
|
|
573
|
-
}, OperatorSubscriber2;
|
|
574
|
-
}(Subscriber), EmptyError = createErrorClass(function(_super) {
|
|
575
|
-
return function() {
|
|
576
|
-
_super(this), this.name = "EmptyError", this.message = "no elements in sequence";
|
|
577
|
-
};
|
|
578
|
-
});
|
|
579
|
-
function firstValueFrom(source, config2) {
|
|
580
|
-
return new Promise(function(resolve, reject) {
|
|
581
|
-
var subscriber = new SafeSubscriber({
|
|
582
|
-
next: function(value) {
|
|
583
|
-
resolve(value), subscriber.unsubscribe();
|
|
584
|
-
},
|
|
585
|
-
error: reject,
|
|
586
|
-
complete: function() {
|
|
587
|
-
reject(new EmptyError());
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
source.subscribe(subscriber);
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
function filter(predicate, thisArg) {
|
|
594
|
-
return operate(function(source, subscriber) {
|
|
595
|
-
var index = 0;
|
|
596
|
-
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
597
|
-
return predicate.call(thisArg, value, index++) && subscriber.next(value);
|
|
598
|
-
}));
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
const query = `*[_type == $translationSchema && $id in translations[].value._ref]{
|
|
240
|
+
}, query = `*[_type == $translationSchema && $id in translations[].value._ref]{
|
|
602
241
|
_id,
|
|
603
242
|
_createdAt,
|
|
604
243
|
translations
|
|
605
244
|
}`;
|
|
606
245
|
function useTranslationMetadata(id) {
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
246
|
+
const $ = c(6);
|
|
247
|
+
let t0;
|
|
248
|
+
$[0] !== id ? (t0 = {
|
|
249
|
+
params: {
|
|
250
|
+
id,
|
|
251
|
+
translationSchema: METADATA_SCHEMA_NAME
|
|
252
|
+
}
|
|
253
|
+
}, $[0] = id, $[1] = t0) : t0 = $[1];
|
|
254
|
+
const {
|
|
255
|
+
data,
|
|
256
|
+
loading,
|
|
257
|
+
error
|
|
258
|
+
} = useListeningQuery(query, t0), t1 = data;
|
|
259
|
+
let t2;
|
|
260
|
+
return $[2] !== error || $[3] !== loading || $[4] !== t1 ? (t2 = {
|
|
261
|
+
data: t1,
|
|
262
|
+
loading,
|
|
263
|
+
error
|
|
264
|
+
}, $[2] = error, $[3] = loading, $[4] = t1, $[5] = t2) : t2 = $[5], t2;
|
|
611
265
|
}
|
|
612
|
-
const documenti18nLocaleNamespace = "document-internationalization", documentInternationalizationUsEnglishLocaleBundle =
|
|
266
|
+
const documenti18nLocaleNamespace = "document-internationalization", documentInternationalizationUsEnglishLocaleBundle = defineLocaleResourceBundle({
|
|
613
267
|
locale: "en-US",
|
|
614
268
|
namespace: documenti18nLocaleNamespace,
|
|
615
|
-
resources: () =>
|
|
616
|
-
return require("./_chunks-cjs/resources.js");
|
|
617
|
-
})
|
|
269
|
+
resources: () => import("./_chunks-es/resources.js")
|
|
618
270
|
}), DISABLED_REASON_KEY = {
|
|
619
271
|
METADATA_NOT_FOUND: "action.duplicate.disabled.missing-metadata",
|
|
620
272
|
MULTIPLE_METADATA: "action.duplicate.disabled.multiple-metadata",
|
|
621
273
|
NOTHING_TO_DUPLICATE: "action.duplicate.disabled.nothing-to-duplicate",
|
|
622
274
|
NOT_READY: "action.duplicate.disabled.not-ready"
|
|
623
|
-
}, DuplicateWithTranslationsAction = ({
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
275
|
+
}, DuplicateWithTranslationsAction = (t0) => {
|
|
276
|
+
const $ = c(44), {
|
|
277
|
+
id,
|
|
278
|
+
type,
|
|
279
|
+
onComplete
|
|
280
|
+
} = t0, documentStore = useDocumentStore(), {
|
|
281
|
+
duplicate
|
|
282
|
+
} = useDocumentOperation(id, type), {
|
|
283
|
+
navigateIntent
|
|
284
|
+
} = useRouter(), [isDuplicating, setDuplicating] = useState(!1);
|
|
285
|
+
let t1;
|
|
286
|
+
$[0] !== id || $[1] !== type ? (t1 = {
|
|
629
287
|
id,
|
|
630
288
|
type,
|
|
631
289
|
permission: "duplicate"
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
|
|
290
|
+
}, $[0] = id, $[1] = type, $[2] = t1) : t1 = $[2];
|
|
291
|
+
const [permissions, isPermissionsLoading] = useDocumentPairPermissions(t1), {
|
|
292
|
+
data,
|
|
293
|
+
loading: isMetadataDocumentLoading
|
|
294
|
+
} = useTranslationMetadata(id), hasOneMetadataDocument = Array.isArray(data) && data.length <= 1, metadataDocument = Array.isArray(data) && data.length ? data[0] : null, client = useClient(DEFAULT_STUDIO_CLIENT_OPTIONS), toast = useToast(), {
|
|
295
|
+
t: s
|
|
296
|
+
} = useTranslation(structureLocaleNamespace), {
|
|
297
|
+
t: d
|
|
298
|
+
} = useTranslation(documenti18nLocaleNamespace), currentUser = useCurrentUser();
|
|
299
|
+
let t2;
|
|
300
|
+
$[3] !== client || $[4] !== documentStore.pair || $[5] !== metadataDocument || $[6] !== navigateIntent || $[7] !== onComplete || $[8] !== toast || $[9] !== type ? (t2 = () => {
|
|
301
|
+
setDuplicating(!0), (async function() {
|
|
635
302
|
if (!metadataDocument)
|
|
636
|
-
|
|
303
|
+
return Promise.reject(new Error("Metadata document not found"));
|
|
637
304
|
const translations = /* @__PURE__ */ new Map();
|
|
638
|
-
await Promise.all(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
})
|
|
654
|
-
);
|
|
655
|
-
const { duplicate: duplicateMetadata } = await firstValueFrom(
|
|
656
|
-
documentStore.pair.editOperations(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter((op) => op.duplicate.disabled !== "NOT_READY"))
|
|
657
|
-
);
|
|
305
|
+
await Promise.all(metadataDocument[TRANSLATIONS_ARRAY_NAME].map(async (translation) => {
|
|
306
|
+
const dupeId = uuid(), locale = translation._key, docId = translation.value?._ref;
|
|
307
|
+
if (!docId)
|
|
308
|
+
return Promise.reject(new Error("Translation document not found"));
|
|
309
|
+
const {
|
|
310
|
+
duplicate: duplicateTranslation
|
|
311
|
+
} = await firstValueFrom(documentStore.pair.editOperations(docId, type).pipe(filter(_temp$3)));
|
|
312
|
+
if (duplicateTranslation.disabled)
|
|
313
|
+
return Promise.reject(new Error("Cannot duplicate document"));
|
|
314
|
+
const duplicateTranslationSuccess = firstValueFrom(documentStore.pair.operationEvents(docId, type).pipe(filter(_temp2$2)));
|
|
315
|
+
duplicateTranslation.execute(dupeId), await duplicateTranslationSuccess, translations.set(locale, dupeId);
|
|
316
|
+
}));
|
|
317
|
+
const {
|
|
318
|
+
duplicate: duplicateMetadata
|
|
319
|
+
} = await firstValueFrom(documentStore.pair.editOperations(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter(_temp3)));
|
|
658
320
|
if (duplicateMetadata.disabled)
|
|
659
|
-
|
|
660
|
-
const duplicateMetadataSuccess = firstValueFrom(
|
|
661
|
-
|
|
662
|
-
), dupeId = uuid.uuid();
|
|
663
|
-
duplicateMetadata.execute(dupeId), await duplicateMetadataSuccess;
|
|
321
|
+
return Promise.reject(new Error("Cannot duplicate document"));
|
|
322
|
+
const duplicateMetadataSuccess = firstValueFrom(documentStore.pair.operationEvents(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter(_temp4))), dupeId_0 = uuid();
|
|
323
|
+
duplicateMetadata.execute(dupeId_0), await duplicateMetadataSuccess;
|
|
664
324
|
const patch = {
|
|
665
|
-
set: Object.fromEntries(
|
|
666
|
-
Array.from(translations.entries()).map(([locale, documentId]) => [
|
|
667
|
-
`${TRANSLATIONS_ARRAY_NAME}[_key == "${locale}"].value._ref`,
|
|
668
|
-
documentId
|
|
669
|
-
])
|
|
670
|
-
)
|
|
325
|
+
set: Object.fromEntries(Array.from(translations.entries()).map(_temp5))
|
|
671
326
|
};
|
|
672
|
-
await client.transaction().patch(
|
|
327
|
+
await client.transaction().patch(dupeId_0, patch).commit(), navigateIntent("edit", {
|
|
673
328
|
id: Array.from(translations.values()).at(0),
|
|
674
329
|
type
|
|
675
330
|
}), onComplete();
|
|
676
|
-
}
|
|
331
|
+
})().catch((error) => {
|
|
677
332
|
console.error(error), toast.push({
|
|
678
333
|
status: "error",
|
|
679
334
|
title: "Error duplicating document",
|
|
680
335
|
description: error instanceof Error ? error.message : "Failed to duplicate document"
|
|
681
336
|
});
|
|
682
|
-
}
|
|
337
|
+
}).finally(() => {
|
|
683
338
|
setDuplicating(!1);
|
|
339
|
+
});
|
|
340
|
+
}, $[3] = client, $[4] = documentStore.pair, $[5] = metadataDocument, $[6] = navigateIntent, $[7] = onComplete, $[8] = toast, $[9] = type, $[10] = t2) : t2 = $[10];
|
|
341
|
+
const handle = t2;
|
|
342
|
+
let t3;
|
|
343
|
+
bb0: {
|
|
344
|
+
if (!isPermissionsLoading && !permissions?.granted) {
|
|
345
|
+
let t42;
|
|
346
|
+
$[11] !== d ? (t42 = d("action.duplicate.label"), $[11] = d, $[12] = t42) : t42 = $[12];
|
|
347
|
+
let t52;
|
|
348
|
+
$[13] !== currentUser ? (t52 = /* @__PURE__ */ jsx(InsufficientPermissionsMessage, { context: "duplicate-document", currentUser }), $[13] = currentUser, $[14] = t52) : t52 = $[14];
|
|
349
|
+
let t62;
|
|
350
|
+
$[15] !== t42 || $[16] !== t52 ? (t62 = {
|
|
351
|
+
icon: CopyIcon,
|
|
352
|
+
disabled: !0,
|
|
353
|
+
label: t42,
|
|
354
|
+
title: t52
|
|
355
|
+
}, $[15] = t42, $[16] = t52, $[17] = t62) : t62 = $[17], t3 = t62;
|
|
356
|
+
break bb0;
|
|
684
357
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
isPermissionsLoading,
|
|
729
|
-
metadataDocument,
|
|
730
|
-
permissions == null ? void 0 : permissions.granted,
|
|
731
|
-
s,
|
|
732
|
-
d
|
|
733
|
-
]);
|
|
358
|
+
if (!isMetadataDocumentLoading && !metadataDocument) {
|
|
359
|
+
let t42;
|
|
360
|
+
$[18] !== d ? (t42 = d("action.duplicate.label"), $[18] = d, $[19] = t42) : t42 = $[19];
|
|
361
|
+
let t52;
|
|
362
|
+
$[20] !== d ? (t52 = d(DISABLED_REASON_KEY.METADATA_NOT_FOUND), $[20] = d, $[21] = t52) : t52 = $[21];
|
|
363
|
+
let t62;
|
|
364
|
+
$[22] !== t42 || $[23] !== t52 ? (t62 = {
|
|
365
|
+
icon: CopyIcon,
|
|
366
|
+
disabled: !0,
|
|
367
|
+
label: t42,
|
|
368
|
+
title: t52
|
|
369
|
+
}, $[22] = t42, $[23] = t52, $[24] = t62) : t62 = $[24], t3 = t62;
|
|
370
|
+
break bb0;
|
|
371
|
+
}
|
|
372
|
+
if (!hasOneMetadataDocument) {
|
|
373
|
+
let t42;
|
|
374
|
+
$[25] !== d ? (t42 = d("action.duplicate.label"), $[25] = d, $[26] = t42) : t42 = $[26];
|
|
375
|
+
let t52;
|
|
376
|
+
$[27] !== d ? (t52 = d(DISABLED_REASON_KEY.MULTIPLE_METADATA), $[27] = d, $[28] = t52) : t52 = $[28];
|
|
377
|
+
let t62;
|
|
378
|
+
$[29] !== t42 || $[30] !== t52 ? (t62 = {
|
|
379
|
+
icon: CopyIcon,
|
|
380
|
+
disabled: !0,
|
|
381
|
+
label: t42,
|
|
382
|
+
title: t52
|
|
383
|
+
}, $[29] = t42, $[30] = t52, $[31] = t62) : t62 = $[31], t3 = t62;
|
|
384
|
+
break bb0;
|
|
385
|
+
}
|
|
386
|
+
const t4 = isDuplicating || !!duplicate.disabled || isPermissionsLoading || isMetadataDocumentLoading;
|
|
387
|
+
let t5;
|
|
388
|
+
$[32] !== d || $[33] !== isDuplicating || $[34] !== s ? (t5 = isDuplicating ? s("action.duplicate.running.label") : d("action.duplicate.label"), $[32] = d, $[33] = isDuplicating, $[34] = s, $[35] = t5) : t5 = $[35];
|
|
389
|
+
let t6;
|
|
390
|
+
$[36] !== duplicate.disabled || $[37] !== s ? (t6 = duplicate.disabled ? s(DISABLED_REASON_KEY[duplicate.disabled]) : "", $[36] = duplicate.disabled, $[37] = s, $[38] = t6) : t6 = $[38];
|
|
391
|
+
let t7;
|
|
392
|
+
$[39] !== handle || $[40] !== t4 || $[41] !== t5 || $[42] !== t6 ? (t7 = {
|
|
393
|
+
icon: CopyIcon,
|
|
394
|
+
disabled: t4,
|
|
395
|
+
label: t5,
|
|
396
|
+
title: t6,
|
|
397
|
+
onHandle: handle
|
|
398
|
+
}, $[39] = handle, $[40] = t4, $[41] = t5, $[42] = t6, $[43] = t7) : t7 = $[43], t3 = t7;
|
|
399
|
+
}
|
|
400
|
+
return t3;
|
|
734
401
|
};
|
|
735
402
|
DuplicateWithTranslationsAction.action = "duplicate";
|
|
736
403
|
DuplicateWithTranslationsAction.displayName = "DuplicateWithTranslationsAction";
|
|
404
|
+
function _temp$3(op) {
|
|
405
|
+
return op.duplicate.disabled !== "NOT_READY";
|
|
406
|
+
}
|
|
407
|
+
function _temp2$2(e) {
|
|
408
|
+
return e.op === "duplicate" && e.type === "success";
|
|
409
|
+
}
|
|
410
|
+
function _temp3(op_0) {
|
|
411
|
+
return op_0.duplicate.disabled !== "NOT_READY";
|
|
412
|
+
}
|
|
413
|
+
function _temp4(e_0) {
|
|
414
|
+
return e_0.op === "duplicate" && e_0.type === "success";
|
|
415
|
+
}
|
|
416
|
+
function _temp5(t0) {
|
|
417
|
+
const [locale_0, documentId] = t0;
|
|
418
|
+
return [`${TRANSLATIONS_ARRAY_NAME}[_key == "${locale_0}"].value._ref`, documentId];
|
|
419
|
+
}
|
|
737
420
|
function useOpenInNewPane(id, type) {
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
421
|
+
const $ = c(6), router = useRouter(), {
|
|
422
|
+
routerPanesState,
|
|
423
|
+
groupIndex
|
|
424
|
+
} = usePaneRouter();
|
|
425
|
+
let t0;
|
|
426
|
+
return $[0] !== groupIndex || $[1] !== id || $[2] !== router || $[3] !== routerPanesState || $[4] !== type ? (t0 = () => {
|
|
427
|
+
if (!id || !type)
|
|
741
428
|
return;
|
|
742
429
|
if (!routerPanesState.length) {
|
|
743
|
-
|
|
430
|
+
router.navigateIntent("edit", {
|
|
431
|
+
id,
|
|
432
|
+
type
|
|
433
|
+
});
|
|
744
434
|
return;
|
|
745
435
|
}
|
|
746
436
|
const panes = [...routerPanesState];
|
|
747
|
-
panes.splice(groupIndex + 1, 0, [
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
437
|
+
panes.splice(groupIndex + 1, 0, [{
|
|
438
|
+
id,
|
|
439
|
+
params: {
|
|
440
|
+
type
|
|
751
441
|
}
|
|
752
|
-
]);
|
|
753
|
-
const href =
|
|
754
|
-
|
|
755
|
-
|
|
442
|
+
}]);
|
|
443
|
+
const href = router.resolvePathFromState({
|
|
444
|
+
panes
|
|
445
|
+
});
|
|
446
|
+
router.navigateUrl({
|
|
447
|
+
path: href
|
|
448
|
+
});
|
|
449
|
+
}, $[0] = groupIndex, $[1] = id, $[2] = router, $[3] = routerPanesState, $[4] = type, $[5] = t0) : t0 = $[5], t0;
|
|
756
450
|
}
|
|
757
|
-
var __defProp$2 = Object.defineProperty, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
758
|
-
for (var prop in b || (b = {}))
|
|
759
|
-
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
760
|
-
if (__getOwnPropSymbols$2)
|
|
761
|
-
for (var prop of __getOwnPropSymbols$2(b))
|
|
762
|
-
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
763
|
-
return a;
|
|
764
|
-
};
|
|
765
451
|
function createReference(key, ref, type, strengthenOnPublish = !0) {
|
|
766
452
|
return {
|
|
767
453
|
_key: key,
|
|
768
454
|
_type: "internationalizedArrayReferenceValue",
|
|
769
|
-
value:
|
|
455
|
+
value: {
|
|
770
456
|
_type: "reference",
|
|
771
457
|
_ref: ref,
|
|
772
|
-
_weak: !0
|
|
773
|
-
|
|
458
|
+
_weak: !0,
|
|
459
|
+
// If the user has configured weakReferences, we won't want to strengthen them
|
|
460
|
+
...strengthenOnPublish ? {
|
|
461
|
+
_strengthenOnPublish: {
|
|
462
|
+
type
|
|
463
|
+
}
|
|
464
|
+
} : {}
|
|
465
|
+
}
|
|
774
466
|
};
|
|
775
467
|
}
|
|
776
468
|
function LanguageManage(props) {
|
|
777
|
-
const
|
|
469
|
+
const $ = c(21), {
|
|
470
|
+
id,
|
|
471
|
+
metadataId,
|
|
472
|
+
schemaType,
|
|
473
|
+
documentId,
|
|
474
|
+
sourceLanguageId
|
|
475
|
+
} = props, open = useOpenInNewPane(id, METADATA_SCHEMA_NAME), openCreated = useOpenInNewPane(metadataId, METADATA_SCHEMA_NAME), {
|
|
476
|
+
allowCreateMetaDoc,
|
|
477
|
+
apiVersion,
|
|
478
|
+
weakReferences
|
|
479
|
+
} = useDocumentInternationalizationContext();
|
|
480
|
+
let t0;
|
|
481
|
+
$[0] !== apiVersion ? (t0 = {
|
|
482
|
+
apiVersion
|
|
483
|
+
}, $[0] = apiVersion, $[1] = t0) : t0 = $[1];
|
|
484
|
+
const client = useClient(t0), [userHasClicked, setUserHasClicked] = useState(!1), canCreate = !id && !!metadataId && allowCreateMetaDoc;
|
|
485
|
+
let t1;
|
|
486
|
+
$[2] !== client || $[3] !== documentId || $[4] !== id || $[5] !== metadataId || $[6] !== open || $[7] !== openCreated || $[8] !== schemaType.name || $[9] !== sourceLanguageId || $[10] !== weakReferences ? (t1 = () => {
|
|
778
487
|
if (!id && metadataId && sourceLanguageId) {
|
|
779
488
|
setUserHasClicked(!0);
|
|
780
|
-
const transaction = client.transaction(), sourceReference = createReference(
|
|
781
|
-
sourceLanguageId,
|
|
782
|
-
documentId,
|
|
783
|
-
schemaType.name,
|
|
784
|
-
!weakReferences
|
|
785
|
-
), newMetadataDocument = {
|
|
489
|
+
const transaction = client.transaction(), sourceReference = createReference(sourceLanguageId, documentId, schemaType.name, !weakReferences), newMetadataDocument = {
|
|
786
490
|
_id: metadataId,
|
|
787
491
|
_type: METADATA_SCHEMA_NAME,
|
|
788
492
|
schemaTypes: [schemaType.name],
|
|
@@ -795,66 +499,37 @@ function LanguageManage(props) {
|
|
|
795
499
|
});
|
|
796
500
|
} else
|
|
797
501
|
open();
|
|
798
|
-
}, [
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
open
|
|
808
|
-
]);
|
|
809
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
810
|
-
ui.Tooltip,
|
|
811
|
-
{
|
|
812
|
-
animate: !0,
|
|
813
|
-
content: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "Document has no other translations" }) }),
|
|
814
|
-
fallbackPlacements: ["right", "left"],
|
|
815
|
-
placement: "top",
|
|
816
|
-
portal: !0,
|
|
817
|
-
disabled: !!id || canCreate,
|
|
818
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
819
|
-
ui.Button,
|
|
820
|
-
{
|
|
821
|
-
disabled: !id && !canCreate || canCreate && !sourceLanguageId || userHasClicked,
|
|
822
|
-
mode: "ghost",
|
|
823
|
-
text: "Manage Translations",
|
|
824
|
-
icon: icons.CogIcon,
|
|
825
|
-
loading: userHasClicked,
|
|
826
|
-
onClick: handleClick
|
|
827
|
-
}
|
|
828
|
-
) })
|
|
829
|
-
}
|
|
830
|
-
);
|
|
502
|
+
}, $[2] = client, $[3] = documentId, $[4] = id, $[5] = metadataId, $[6] = open, $[7] = openCreated, $[8] = schemaType.name, $[9] = sourceLanguageId, $[10] = weakReferences, $[11] = t1) : t1 = $[11];
|
|
503
|
+
const handleClick = t1, disabled = !id && !canCreate || canCreate && !sourceLanguageId || userHasClicked;
|
|
504
|
+
let t2, t3;
|
|
505
|
+
$[12] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Document has no other translations" }) }), t3 = ["right", "left"], $[12] = t2, $[13] = t3) : (t2 = $[12], t3 = $[13]);
|
|
506
|
+
const t4 = !!id || canCreate;
|
|
507
|
+
let t5;
|
|
508
|
+
$[14] !== disabled || $[15] !== handleClick || $[16] !== userHasClicked ? (t5 = /* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(Button, { disabled, mode: "ghost", text: "Manage Translations", icon: CogIcon, loading: userHasClicked, onClick: handleClick }) }), $[14] = disabled, $[15] = handleClick, $[16] = userHasClicked, $[17] = t5) : t5 = $[17];
|
|
509
|
+
let t6;
|
|
510
|
+
return $[18] !== t4 || $[19] !== t5 ? (t6 = /* @__PURE__ */ jsx(Tooltip, { animate: !0, content: t2, fallbackPlacements: t3, placement: "top", portal: !0, disabled: t4, children: t5 }), $[18] = t4, $[19] = t5, $[20] = t6) : t6 = $[20], t6;
|
|
831
511
|
}
|
|
832
512
|
function removeExcludedPaths(doc, schemaType) {
|
|
833
|
-
if (!
|
|
513
|
+
if (!isDocumentSchemaType(schemaType) || !doc)
|
|
834
514
|
return doc;
|
|
835
|
-
const pathsToExclude = extractPaths(doc, schemaType, []).filter(
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
return new mutator.Mutation({
|
|
842
|
-
mutations: [
|
|
843
|
-
{
|
|
844
|
-
patch: {
|
|
845
|
-
id: doc._id,
|
|
846
|
-
unset: pathsToExclude
|
|
847
|
-
}
|
|
515
|
+
const pathsToExclude = extractPaths(doc, schemaType, []).filter((field) => field.schemaType?.options?.documentInternationalization?.exclude === !0).map((field) => pathToString(field.path));
|
|
516
|
+
return new Mutation({
|
|
517
|
+
mutations: [{
|
|
518
|
+
patch: {
|
|
519
|
+
id: doc._id,
|
|
520
|
+
unset: pathsToExclude
|
|
848
521
|
}
|
|
849
|
-
]
|
|
522
|
+
}]
|
|
850
523
|
}).apply(doc);
|
|
851
524
|
}
|
|
852
525
|
function extractPaths(doc, schemaType, path) {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
const fieldPath = [...path, field.name], fieldSchema = field.type, {
|
|
526
|
+
const result = [];
|
|
527
|
+
for (const field of schemaType.fields) {
|
|
528
|
+
const fieldPath = [...path, field.name], fieldSchema = field.type, {
|
|
529
|
+
value
|
|
530
|
+
} = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
|
|
856
531
|
if (!value)
|
|
857
|
-
|
|
532
|
+
continue;
|
|
858
533
|
const thisFieldWithPath = {
|
|
859
534
|
path: fieldPath,
|
|
860
535
|
name: field.name,
|
|
@@ -863,44 +538,35 @@ function extractPaths(doc, schemaType, path) {
|
|
|
863
538
|
};
|
|
864
539
|
if (fieldSchema.jsonType === "object") {
|
|
865
540
|
const innerFields = extractPaths(doc, fieldSchema, fieldPath);
|
|
866
|
-
|
|
541
|
+
result.push(thisFieldWithPath, ...innerFields);
|
|
867
542
|
} else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some((item) => "fields" in item)) {
|
|
868
|
-
const {
|
|
869
|
-
|
|
870
|
-
|
|
543
|
+
const {
|
|
544
|
+
value: arrayValue
|
|
545
|
+
} = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
|
|
546
|
+
if (result.push(thisFieldWithPath), arrayValue?.length)
|
|
871
547
|
for (const item of arrayValue) {
|
|
872
|
-
|
|
548
|
+
if (!item._key) continue;
|
|
549
|
+
const itemPath = [...fieldPath, {
|
|
550
|
+
_key: item._key
|
|
551
|
+
}];
|
|
873
552
|
let itemSchema = fieldSchema.of.find((t) => t.name === item._type);
|
|
874
|
-
if (item._type || (itemSchema = fieldSchema.of[0]),
|
|
875
|
-
const innerFields = extractPaths(
|
|
876
|
-
doc,
|
|
877
|
-
itemSchema,
|
|
878
|
-
itemPath
|
|
879
|
-
), arrayMember = {
|
|
553
|
+
if (item._type || (itemSchema = fieldSchema.of[0]), itemSchema) {
|
|
554
|
+
const innerFields = extractPaths(doc, itemSchema, itemPath), arrayMember = {
|
|
880
555
|
path: itemPath,
|
|
881
556
|
name: item._key,
|
|
882
557
|
schemaType: itemSchema,
|
|
883
558
|
value: item
|
|
884
559
|
};
|
|
885
|
-
|
|
560
|
+
result.push(arrayMember, ...innerFields);
|
|
886
561
|
}
|
|
887
562
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
563
|
+
} else
|
|
564
|
+
result.push(thisFieldWithPath);
|
|
565
|
+
}
|
|
566
|
+
return result;
|
|
892
567
|
}
|
|
893
|
-
var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
894
|
-
for (var prop in b || (b = {}))
|
|
895
|
-
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
896
|
-
if (__getOwnPropSymbols$1)
|
|
897
|
-
for (var prop of __getOwnPropSymbols$1(b))
|
|
898
|
-
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
899
|
-
return a;
|
|
900
|
-
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
901
568
|
function LanguageOption(props) {
|
|
902
|
-
|
|
903
|
-
const {
|
|
569
|
+
const $ = c(45), {
|
|
904
570
|
language,
|
|
905
571
|
schemaType,
|
|
906
572
|
documentId,
|
|
@@ -909,11 +575,25 @@ function LanguageOption(props) {
|
|
|
909
575
|
sourceLanguageId,
|
|
910
576
|
metadata: metadata2,
|
|
911
577
|
metadataId
|
|
912
|
-
} = props, [userHasClicked, setUserHasClicked] =
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
578
|
+
} = props, [userHasClicked, setUserHasClicked] = useState(!1), disabled = props.disabled || userHasClicked || current || !source || !sourceLanguageId || !metadataId;
|
|
579
|
+
let t0;
|
|
580
|
+
$[0] !== language.id || $[1] !== metadata2 ? (t0 = metadata2?.translations.length ? metadata2.translations.find((t) => t._key === language.id) : void 0, $[0] = language.id, $[1] = metadata2, $[2] = t0) : t0 = $[2];
|
|
581
|
+
const translation = t0, {
|
|
582
|
+
apiVersion,
|
|
583
|
+
languageField,
|
|
584
|
+
weakReferences,
|
|
585
|
+
callback
|
|
586
|
+
} = useDocumentInternationalizationContext();
|
|
587
|
+
let t1;
|
|
588
|
+
$[3] !== apiVersion ? (t1 = {
|
|
589
|
+
apiVersion
|
|
590
|
+
}, $[3] = apiVersion, $[4] = t1) : t1 = $[4];
|
|
591
|
+
const client = useClient(t1), toast = useToast(), open = useOpenInNewPane(translation?.value?._ref, schemaType.name);
|
|
592
|
+
let t2;
|
|
593
|
+
$[5] !== open ? (t2 = () => open(), $[5] = open, $[6] = t2) : t2 = $[6];
|
|
594
|
+
const handleOpen = t2;
|
|
595
|
+
let t3;
|
|
596
|
+
$[7] !== callback || $[8] !== client || $[9] !== documentId || $[10] !== language.id || $[11] !== language.title || $[12] !== languageField || $[13] !== metadata2?._createdAt || $[14] !== metadataId || $[15] !== schemaType || $[16] !== source || $[17] !== sourceLanguageId || $[18] !== toast || $[19] !== weakReferences ? (t3 = async () => {
|
|
917
597
|
if (!source)
|
|
918
598
|
throw new Error("Cannot create translation without source document");
|
|
919
599
|
if (!sourceLanguageId)
|
|
@@ -921,105 +601,91 @@ function LanguageOption(props) {
|
|
|
921
601
|
if (!metadataId)
|
|
922
602
|
throw new Error("Cannot create translation without a metadata ID");
|
|
923
603
|
setUserHasClicked(!0);
|
|
924
|
-
const transaction = client.transaction(), newTranslationDocumentId = uuid
|
|
925
|
-
let newTranslationDocument =
|
|
604
|
+
const transaction = client.transaction(), newTranslationDocumentId = uuid();
|
|
605
|
+
let newTranslationDocument = {
|
|
606
|
+
...source,
|
|
926
607
|
_id: `drafts.${newTranslationDocumentId}`,
|
|
927
|
-
// 2. Update language of the translation
|
|
928
608
|
[languageField]: language.id
|
|
929
|
-
}
|
|
930
|
-
newTranslationDocument = removeExcludedPaths(
|
|
931
|
-
|
|
932
|
-
schemaType
|
|
933
|
-
), transaction.create(newTranslationDocument);
|
|
934
|
-
const sourceReference = createReference(
|
|
935
|
-
sourceLanguageId,
|
|
936
|
-
documentId,
|
|
937
|
-
schemaType.name,
|
|
938
|
-
!weakReferences
|
|
939
|
-
), newTranslationReference = createReference(
|
|
940
|
-
language.id,
|
|
941
|
-
newTranslationDocumentId,
|
|
942
|
-
schemaType.name,
|
|
943
|
-
!weakReferences
|
|
944
|
-
), newMetadataDocument = {
|
|
609
|
+
};
|
|
610
|
+
newTranslationDocument = removeExcludedPaths(newTranslationDocument, schemaType), transaction.create(newTranslationDocument);
|
|
611
|
+
const sourceReference = createReference(sourceLanguageId, documentId, schemaType.name, !weakReferences), newTranslationReference = createReference(language.id, newTranslationDocumentId, schemaType.name, !weakReferences), newMetadataDocument = {
|
|
945
612
|
_id: metadataId,
|
|
946
613
|
_type: METADATA_SCHEMA_NAME,
|
|
947
614
|
schemaTypes: [schemaType.name],
|
|
948
615
|
translations: [sourceReference]
|
|
949
616
|
};
|
|
950
617
|
transaction.createIfNotExists(newMetadataDocument);
|
|
951
|
-
const metadataPatch = client.patch(metadataId).setIfMissing({
|
|
618
|
+
const metadataPatch = client.patch(metadataId).setIfMissing({
|
|
619
|
+
translations: [sourceReference]
|
|
620
|
+
}).insert("after", "translations[-1]", [newTranslationReference]);
|
|
952
621
|
transaction.patch(metadataPatch), transaction.commit().then(() => {
|
|
953
|
-
const metadataExisted = !!
|
|
954
|
-
|
|
955
|
-
client,
|
|
956
|
-
sourceLanguageId,
|
|
957
|
-
sourceDocument: source,
|
|
958
|
-
newDocument: newTranslationDocument,
|
|
959
|
-
destinationLanguageId: language.id,
|
|
960
|
-
metaDocumentId: metadataId
|
|
961
|
-
}).catch((err) => {
|
|
962
|
-
toast.push({
|
|
963
|
-
status: "error",
|
|
964
|
-
title: "Callback",
|
|
965
|
-
description: `Error while running callback - ${err}.`
|
|
966
|
-
});
|
|
967
|
-
}), toast.push({
|
|
622
|
+
const metadataExisted = !!metadata2?._createdAt;
|
|
623
|
+
if (toast.push({
|
|
968
624
|
status: "success",
|
|
969
625
|
title: `Created "${language.title}" translation`,
|
|
970
626
|
description: metadataExisted ? "Updated Translations Metadata" : "Created Translations Metadata"
|
|
971
|
-
})
|
|
627
|
+
}), setUserHasClicked(!1), callback)
|
|
628
|
+
return callback({
|
|
629
|
+
client,
|
|
630
|
+
sourceLanguageId,
|
|
631
|
+
sourceDocument: source,
|
|
632
|
+
newDocument: newTranslationDocument,
|
|
633
|
+
destinationLanguageId: language.id,
|
|
634
|
+
metaDocumentId: metadataId
|
|
635
|
+
});
|
|
972
636
|
}).catch((err) => (console.error(err), setUserHasClicked(!1), toast.push({
|
|
973
637
|
status: "error",
|
|
974
638
|
title: "Error creating translation",
|
|
975
639
|
description: err.message
|
|
976
640
|
})));
|
|
977
|
-
}, [
|
|
978
|
-
|
|
979
|
-
documentId,
|
|
980
|
-
language.id,
|
|
981
|
-
language.title,
|
|
982
|
-
languageField,
|
|
983
|
-
metadata2 == null ? void 0 : metadata2._createdAt,
|
|
984
|
-
metadataId,
|
|
985
|
-
schemaType,
|
|
986
|
-
source,
|
|
987
|
-
sourceLanguageId,
|
|
988
|
-
toast,
|
|
989
|
-
weakReferences,
|
|
990
|
-
callback
|
|
991
|
-
]);
|
|
641
|
+
}, $[7] = callback, $[8] = client, $[9] = documentId, $[10] = language.id, $[11] = language.title, $[12] = languageField, $[13] = metadata2?._createdAt, $[14] = metadataId, $[15] = schemaType, $[16] = source, $[17] = sourceLanguageId, $[18] = toast, $[19] = weakReferences, $[20] = t3) : t3 = $[20];
|
|
642
|
+
const handleCreate = t3;
|
|
992
643
|
let message;
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
);
|
|
644
|
+
current ? message = "Current document" : translation ? message = `Open ${language.title} translation` : translation || (message = `Create new ${language.title} translation`);
|
|
645
|
+
let t4;
|
|
646
|
+
$[21] !== message ? (t4 = /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: message }) }), $[21] = message, $[22] = t4) : t4 = $[22];
|
|
647
|
+
let t5;
|
|
648
|
+
$[23] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = ["right", "left"], $[23] = t5) : t5 = $[23];
|
|
649
|
+
const t6 = translation ? handleOpen : handleCreate, t7 = current && disabled ? "default" : "bleed";
|
|
650
|
+
let t8;
|
|
651
|
+
$[24] !== current || $[25] !== disabled || $[26] !== translation ? (t8 = disabled && !current ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(Text, { size: 2, children: translation ? /* @__PURE__ */ jsx(SplitVerticalIcon, {}) : current ? /* @__PURE__ */ jsx(CheckmarkIcon, {}) : /* @__PURE__ */ jsx(AddIcon, {}) }), $[24] = current, $[25] = disabled, $[26] = translation, $[27] = t8) : t8 = $[27];
|
|
652
|
+
let t9;
|
|
653
|
+
$[28] !== language.title ? (t9 = /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Text, { children: language.title }) }), $[28] = language.title, $[29] = t9) : t9 = $[29];
|
|
654
|
+
const t10 = disabled || current ? "default" : "primary";
|
|
655
|
+
let t11;
|
|
656
|
+
$[30] !== language.id || $[31] !== t10 ? (t11 = /* @__PURE__ */ jsx(Badge, { tone: t10, children: language.id }), $[30] = language.id, $[31] = t10, $[32] = t11) : t11 = $[32];
|
|
657
|
+
let t12;
|
|
658
|
+
$[33] !== t11 || $[34] !== t8 || $[35] !== t9 ? (t12 = /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
|
|
659
|
+
t8,
|
|
660
|
+
t9,
|
|
661
|
+
t11
|
|
662
|
+
] }), $[33] = t11, $[34] = t8, $[35] = t9, $[36] = t12) : t12 = $[36];
|
|
663
|
+
let t13;
|
|
664
|
+
$[37] !== disabled || $[38] !== t12 || $[39] !== t6 || $[40] !== t7 ? (t13 = /* @__PURE__ */ jsx(Button, { onClick: t6, mode: t7, disabled, children: t12 }), $[37] = disabled, $[38] = t12, $[39] = t6, $[40] = t7, $[41] = t13) : t13 = $[41];
|
|
665
|
+
let t14;
|
|
666
|
+
return $[42] !== t13 || $[43] !== t4 ? (t14 = /* @__PURE__ */ jsx(Tooltip, { animate: !0, content: t4, fallbackPlacements: t5, placement: "top", portal: !0, children: t13 }), $[42] = t13, $[43] = t4, $[44] = t14) : t14 = $[44], t14;
|
|
1016
667
|
}
|
|
1017
668
|
function LanguagePatch(props) {
|
|
1018
|
-
const
|
|
669
|
+
const $ = c(21), {
|
|
670
|
+
language,
|
|
671
|
+
source
|
|
672
|
+
} = props, {
|
|
673
|
+
apiVersion,
|
|
674
|
+
languageField
|
|
675
|
+
} = useDocumentInternationalizationContext(), disabled = props.disabled || !source;
|
|
676
|
+
let t0;
|
|
677
|
+
$[0] !== apiVersion ? (t0 = {
|
|
678
|
+
apiVersion
|
|
679
|
+
}, $[0] = apiVersion, $[1] = t0) : t0 = $[1];
|
|
680
|
+
const client = useClient(t0), toast = useToast();
|
|
681
|
+
let t1;
|
|
682
|
+
$[2] !== client || $[3] !== language.id || $[4] !== language.title || $[5] !== languageField || $[6] !== source || $[7] !== toast ? (t1 = () => {
|
|
1019
683
|
if (!source)
|
|
1020
684
|
throw new Error("Cannot patch missing document");
|
|
1021
685
|
const currentId = source._id;
|
|
1022
|
-
client.patch(currentId).set({
|
|
686
|
+
client.patch(currentId).set({
|
|
687
|
+
[languageField]: language.id
|
|
688
|
+
}).commit().then(() => {
|
|
1023
689
|
toast.push({
|
|
1024
690
|
title: `Set document language to ${language.title}`,
|
|
1025
691
|
status: "success"
|
|
@@ -1028,150 +694,138 @@ function LanguagePatch(props) {
|
|
|
1028
694
|
title: `Failed to set document language to ${language.title}`,
|
|
1029
695
|
status: "error"
|
|
1030
696
|
})));
|
|
1031
|
-
}, [
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
697
|
+
}, $[2] = client, $[3] = language.id, $[4] = language.title, $[5] = languageField, $[6] = source, $[7] = toast, $[8] = t1) : t1 = $[8];
|
|
698
|
+
const handleClick = t1;
|
|
699
|
+
let t2;
|
|
700
|
+
$[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(EditIcon, {}) }), $[9] = t2) : t2 = $[9];
|
|
701
|
+
let t3;
|
|
702
|
+
$[10] !== language.title ? (t3 = /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Text, { children: language.title }) }), $[10] = language.title, $[11] = t3) : t3 = $[11];
|
|
703
|
+
let t4;
|
|
704
|
+
$[12] !== language.id ? (t4 = /* @__PURE__ */ jsx(Badge, { children: language.id }), $[12] = language.id, $[13] = t4) : t4 = $[13];
|
|
705
|
+
let t5;
|
|
706
|
+
$[14] !== t3 || $[15] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
|
|
707
|
+
t2,
|
|
708
|
+
t3,
|
|
709
|
+
t4
|
|
710
|
+
] }), $[14] = t3, $[15] = t4, $[16] = t5) : t5 = $[16];
|
|
711
|
+
let t6;
|
|
712
|
+
return $[17] !== disabled || $[18] !== handleClick || $[19] !== t5 ? (t6 = /* @__PURE__ */ jsx(Button, { mode: "bleed", onClick: handleClick, disabled, justify: "flex-start", children: t5 }), $[17] = disabled, $[18] = handleClick, $[19] = t5, $[20] = t6) : t6 = $[20], t6;
|
|
713
|
+
}
|
|
714
|
+
function ConstrainedBox(t0) {
|
|
715
|
+
const $ = c(3), {
|
|
716
|
+
children
|
|
717
|
+
} = t0;
|
|
718
|
+
let t1;
|
|
719
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
720
|
+
maxWidth: 280
|
|
721
|
+
}, $[0] = t1) : t1 = $[0];
|
|
722
|
+
let t2;
|
|
723
|
+
return $[1] !== children ? (t2 = /* @__PURE__ */ jsx(Box, { style: t1, children }), $[1] = children, $[2] = t2) : t2 = $[2], t2;
|
|
1046
724
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
725
|
+
function Warning(t0) {
|
|
726
|
+
const $ = c(2), {
|
|
727
|
+
children
|
|
728
|
+
} = t0;
|
|
729
|
+
let t1;
|
|
730
|
+
return $[0] !== children ? (t1 = /* @__PURE__ */ jsx(Card, { tone: "caution", padding: 3, children: /* @__PURE__ */ jsx(Flex, { justify: "center", children: /* @__PURE__ */ jsx(ConstrainedBox, { children: /* @__PURE__ */ jsx(Text, { size: 1, align: "center", children }) }) }) }), $[0] = children, $[1] = t1) : t1 = $[1], t1;
|
|
1052
731
|
}
|
|
1053
732
|
function DocumentInternationalizationMenu(props) {
|
|
1054
|
-
const
|
|
733
|
+
const $ = c(36), {
|
|
734
|
+
documentId
|
|
735
|
+
} = props, schemaType = props.schemaType, {
|
|
736
|
+
languageField,
|
|
737
|
+
supportedLanguages
|
|
738
|
+
} = useDocumentInternationalizationContext(), [query2, setQuery] = useState("");
|
|
739
|
+
let t0;
|
|
740
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = (event) => {
|
|
1055
741
|
event.currentTarget.value ? setQuery(event.currentTarget.value) : setQuery("");
|
|
1056
|
-
}, []
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
) :
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
742
|
+
}, $[0] = t0) : t0 = $[0];
|
|
743
|
+
const handleQuery = t0, [open, setOpen] = useState(!1);
|
|
744
|
+
let t1;
|
|
745
|
+
$[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setOpen(_temp$2), $[1] = t1) : t1 = $[1];
|
|
746
|
+
const handleClick = t1, buttonRef = useRef(null), popoverRef = useRef(null);
|
|
747
|
+
let t2;
|
|
748
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = () => setOpen(!1), $[2] = t2) : t2 = $[2];
|
|
749
|
+
const handleClickOutside = t2;
|
|
750
|
+
let t3;
|
|
751
|
+
$[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = () => [buttonRef.current, popoverRef.current], $[3] = t3) : t3 = $[3], useClickOutsideEvent(handleClickOutside, t3);
|
|
752
|
+
const {
|
|
753
|
+
data,
|
|
754
|
+
loading,
|
|
755
|
+
error
|
|
756
|
+
} = useTranslationMetadata(documentId), metadata2 = Array.isArray(data) && data.length ? data[0] : null;
|
|
757
|
+
let t4;
|
|
758
|
+
bb0: {
|
|
759
|
+
if (loading) {
|
|
760
|
+
t4 = null;
|
|
761
|
+
break bb0;
|
|
762
|
+
}
|
|
763
|
+
let t52;
|
|
764
|
+
$[4] !== metadata2?._id ? (t52 = metadata2?._id ?? uuid(), $[4] = metadata2?._id, $[5] = t52) : t52 = $[5], t4 = t52;
|
|
765
|
+
}
|
|
766
|
+
const metadataId = t4, {
|
|
767
|
+
draft,
|
|
768
|
+
published
|
|
769
|
+
} = useEditState(documentId, schemaType.name), source = draft || published, documentIsInOneMetadataDocument = Array.isArray(data) && data.length <= 1, rawLanguageValue = source?.[languageField], sourceLanguageId = typeof rawLanguageValue == "string" ? rawLanguageValue : void 0;
|
|
770
|
+
let t5;
|
|
771
|
+
if ($[6] !== sourceLanguageId || $[7] !== supportedLanguages) {
|
|
772
|
+
let t62;
|
|
773
|
+
$[9] !== sourceLanguageId ? (t62 = (l) => l.id === sourceLanguageId, $[9] = sourceLanguageId, $[10] = t62) : t62 = $[10], t5 = supportedLanguages.some(t62), $[6] = sourceLanguageId, $[7] = supportedLanguages, $[8] = t5;
|
|
774
|
+
} else
|
|
775
|
+
t5 = $[8];
|
|
776
|
+
const sourceLanguageIsValid = t5;
|
|
777
|
+
let t6;
|
|
778
|
+
$[11] !== supportedLanguages ? (t6 = supportedLanguages.every(_temp2$1), $[11] = supportedLanguages, $[12] = t6) : t6 = $[12];
|
|
779
|
+
const valid = t6;
|
|
780
|
+
valid || console.warn('Not all languages are valid. It should be an array of objects with an "id" and "title" property. Or a function that returns an array of objects with an "id" and "title" property.', supportedLanguages);
|
|
781
|
+
const allLanguagesAreValid = valid;
|
|
782
|
+
let t7;
|
|
783
|
+
$[13] !== allLanguagesAreValid || $[14] !== data || $[15] !== documentId || $[16] !== documentIsInOneMetadataDocument || $[17] !== error || $[18] !== loading || $[19] !== metadata2 || $[20] !== metadataId || $[21] !== query2 || $[22] !== schemaType || $[23] !== source || $[24] !== sourceLanguageId || $[25] !== sourceLanguageIsValid || $[26] !== supportedLanguages ? (t7 = /* @__PURE__ */ jsx(Box, { padding: 1, children: error ? /* @__PURE__ */ jsx(Card, { tone: "critical", padding: 1, children: /* @__PURE__ */ jsx(Text, { children: "There was an error returning translations metadata" }) }) : /* @__PURE__ */ jsxs(Stack, { space: 1, children: [
|
|
784
|
+
/* @__PURE__ */ jsx(LanguageManage, { id: metadata2?._id, documentId, metadataId, schemaType, sourceLanguageId }),
|
|
785
|
+
supportedLanguages.length > 4 ? /* @__PURE__ */ jsx(TextInput, { onChange: handleQuery, value: query2, placeholder: "Filter languages" }) : null,
|
|
786
|
+
supportedLanguages.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
787
|
+
loading ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
788
|
+
data && documentIsInOneMetadataDocument ? null : /* @__PURE__ */ jsx(Warning, { children: "This document has been found in more than one Translations Metadata documents" }),
|
|
789
|
+
allLanguagesAreValid ? null : /* @__PURE__ */ jsx(Warning, { children: "Not all language objects are valid. See the console." }),
|
|
790
|
+
sourceLanguageId ? null : /* @__PURE__ */ jsxs(Warning, { children: [
|
|
791
|
+
"Choose a language to apply to ",
|
|
792
|
+
/* @__PURE__ */ jsx("strong", { children: "this Document" })
|
|
1096
793
|
] }),
|
|
1097
|
-
sourceLanguageId && !sourceLanguageIsValid ? /* @__PURE__ */
|
|
794
|
+
sourceLanguageId && !sourceLanguageIsValid ? /* @__PURE__ */ jsxs(Warning, { children: [
|
|
1098
795
|
"Select a supported language. Current language value:",
|
|
1099
796
|
" ",
|
|
1100
|
-
/* @__PURE__ */
|
|
797
|
+
/* @__PURE__ */ jsx("code", { children: sourceLanguageId })
|
|
1101
798
|
] }) : null
|
|
1102
799
|
] }),
|
|
1103
|
-
supportedLanguages.filter((language) => query2 ? language.title.toLowerCase().includes(query2.toLowerCase()) : !0).map(
|
|
1104
|
-
(language) => {
|
|
1105
|
-
var _a;
|
|
1106
|
-
return !loading && sourceLanguageId && sourceLanguageIsValid ? (
|
|
1107
|
-
// Button to duplicate this document to a new translation
|
|
1108
|
-
// And either create or update the metadata document
|
|
1109
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1110
|
-
LanguageOption,
|
|
1111
|
-
{
|
|
1112
|
-
language,
|
|
1113
|
-
schemaType,
|
|
1114
|
-
documentId,
|
|
1115
|
-
disabled: loading || !allLanguagesAreValid,
|
|
1116
|
-
current: language.id === sourceLanguageId,
|
|
1117
|
-
metadata: metadata2,
|
|
1118
|
-
metadataId,
|
|
1119
|
-
source,
|
|
1120
|
-
sourceLanguageId
|
|
1121
|
-
},
|
|
1122
|
-
language.id
|
|
1123
|
-
)
|
|
1124
|
-
) : (
|
|
1125
|
-
// Button to set a language field on *this* document
|
|
1126
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1127
|
-
LanguagePatch,
|
|
1128
|
-
{
|
|
1129
|
-
source,
|
|
1130
|
-
language,
|
|
1131
|
-
disabled: (_a = loading || !allLanguagesAreValid || (metadata2 == null ? void 0 : metadata2.translations.filter((t) => {
|
|
1132
|
-
var _a2;
|
|
1133
|
-
return ((_a2 = t == null ? void 0 : t.value) == null ? void 0 : _a2._ref) !== documentId;
|
|
1134
|
-
}).some((t) => t._key === language.id))) != null ? _a : !1
|
|
1135
|
-
},
|
|
1136
|
-
language.id
|
|
1137
|
-
)
|
|
1138
|
-
);
|
|
1139
|
-
}
|
|
1140
|
-
)
|
|
800
|
+
supportedLanguages.filter((language) => query2 ? language.title.toLowerCase().includes(query2.toLowerCase()) : !0).map((language_0) => !loading && sourceLanguageId && sourceLanguageIsValid ? /* @__PURE__ */ jsx(LanguageOption, { language: language_0, schemaType, documentId, disabled: !allLanguagesAreValid, current: language_0.id === sourceLanguageId, metadata: metadata2, metadataId, source, sourceLanguageId }, language_0.id) : /* @__PURE__ */ jsx(LanguagePatch, { source, language: language_0, disabled: (loading || !allLanguagesAreValid || metadata2?.translations.filter((t) => t?.value?._ref !== documentId).some((t_0) => t_0._key === language_0.id)) ?? !1 }, language_0.id))
|
|
1141
801
|
] }) : null
|
|
1142
|
-
] }) }),
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
text: "Translations",
|
|
1158
|
-
mode: "bleed",
|
|
1159
|
-
disabled: !source,
|
|
1160
|
-
tone: !source || loading || !issueWithTranslations ? void 0 : "caution",
|
|
1161
|
-
icon: icons.TranslateIcon,
|
|
1162
|
-
onClick: handleClick,
|
|
1163
|
-
ref: setButton,
|
|
1164
|
-
selected: open
|
|
1165
|
-
}
|
|
1166
|
-
)
|
|
1167
|
-
}
|
|
1168
|
-
);
|
|
802
|
+
] }) }), $[13] = allLanguagesAreValid, $[14] = data, $[15] = documentId, $[16] = documentIsInOneMetadataDocument, $[17] = error, $[18] = loading, $[19] = metadata2, $[20] = metadataId, $[21] = query2, $[22] = schemaType, $[23] = source, $[24] = sourceLanguageId, $[25] = sourceLanguageIsValid, $[26] = supportedLanguages, $[27] = t7) : t7 = $[27];
|
|
803
|
+
const content = t7, issueWithTranslations = !loading && sourceLanguageId && !sourceLanguageIsValid;
|
|
804
|
+
if (!documentId || !schemaType || !schemaType.name)
|
|
805
|
+
return null;
|
|
806
|
+
const t8 = !source, t9 = !source || loading || !issueWithTranslations ? void 0 : "caution";
|
|
807
|
+
let t10;
|
|
808
|
+
$[28] !== open || $[29] !== t8 || $[30] !== t9 ? (t10 = /* @__PURE__ */ jsx(Button, { text: "Translations", mode: "bleed", disabled: t8, tone: t9, icon: TranslateIcon, onClick: handleClick, ref: buttonRef, selected: open }), $[28] = open, $[29] = t8, $[30] = t9, $[31] = t10) : t10 = $[31];
|
|
809
|
+
let t11;
|
|
810
|
+
return $[32] !== content || $[33] !== open || $[34] !== t10 ? (t11 = /* @__PURE__ */ jsx(Popover, { animate: !0, constrainSize: !0, content, open, portal: !0, ref: popoverRef, overflow: "auto", tone: "default", children: t10 }), $[32] = content, $[33] = open, $[34] = t10, $[35] = t11) : t11 = $[35], t11;
|
|
811
|
+
}
|
|
812
|
+
function _temp2$1(l_0) {
|
|
813
|
+
return l_0.id && l_0.title;
|
|
814
|
+
}
|
|
815
|
+
function _temp$2(o) {
|
|
816
|
+
return !o;
|
|
1169
817
|
}
|
|
1170
818
|
const DeleteMetadataAction = (props) => {
|
|
1171
|
-
const {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
819
|
+
const {
|
|
820
|
+
id: documentId,
|
|
821
|
+
published,
|
|
822
|
+
draft
|
|
823
|
+
} = props, doc = draft || published, [isDialogOpen, setDialogOpen] = useState(!1), onClose = useCallback(() => setDialogOpen(!1), []), translations = useMemo(() => doc && Array.isArray(doc[TRANSLATIONS_ARRAY_NAME]) ? (
|
|
824
|
+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
|
|
825
|
+
doc[TRANSLATIONS_ARRAY_NAME]
|
|
826
|
+
) : [], [doc]), toast = useToast(), client = useClient({
|
|
827
|
+
apiVersion: API_VERSION
|
|
828
|
+
}), onProceed = useCallback(() => {
|
|
1175
829
|
const tx = client.transaction();
|
|
1176
830
|
tx.patch(documentId, (patch) => patch.unset([TRANSLATIONS_ARRAY_NAME])), translations.length > 0 && translations.forEach((translation) => {
|
|
1177
831
|
tx.delete(translation.value._ref), tx.delete(`drafts.${translation.value._ref}`);
|
|
@@ -1191,16 +845,16 @@ const DeleteMetadataAction = (props) => {
|
|
|
1191
845
|
return {
|
|
1192
846
|
label: "Delete all translations",
|
|
1193
847
|
disabled: !doc || !translations.length,
|
|
1194
|
-
icon:
|
|
848
|
+
icon: TrashIcon,
|
|
1195
849
|
tone: "critical",
|
|
1196
850
|
onHandle: () => {
|
|
1197
851
|
setDialogOpen(!0);
|
|
1198
852
|
},
|
|
1199
853
|
dialog: isDialogOpen && {
|
|
1200
854
|
type: "confirm",
|
|
1201
|
-
onCancel:
|
|
855
|
+
onCancel: onClose,
|
|
1202
856
|
onConfirm: () => {
|
|
1203
|
-
onProceed(),
|
|
857
|
+
onProceed(), onClose();
|
|
1204
858
|
},
|
|
1205
859
|
tone: "critical",
|
|
1206
860
|
message: translations.length === 1 ? "Delete 1 translation and this document" : `Delete all ${translations.length} translations and this document`
|
|
@@ -1208,92 +862,138 @@ const DeleteMetadataAction = (props) => {
|
|
|
1208
862
|
};
|
|
1209
863
|
};
|
|
1210
864
|
function LanguageBadge(props) {
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
865
|
+
const source = props?.draft || props?.published, {
|
|
866
|
+
languageField,
|
|
867
|
+
supportedLanguages
|
|
868
|
+
} = useDocumentInternationalizationContext(), languageId = source?.[languageField];
|
|
869
|
+
if (!languageId || typeof languageId != "string")
|
|
1214
870
|
return null;
|
|
1215
871
|
const language = Array.isArray(supportedLanguages) ? supportedLanguages.find((l) => l.id === languageId) : null;
|
|
1216
872
|
return {
|
|
1217
|
-
label:
|
|
1218
|
-
title:
|
|
873
|
+
label: language?.id ?? languageId,
|
|
874
|
+
title: language?.title ?? void 0,
|
|
1219
875
|
color: "primary"
|
|
1220
876
|
};
|
|
1221
877
|
}
|
|
1222
878
|
function DocumentCheck(props) {
|
|
1223
|
-
const {
|
|
879
|
+
const $ = c(25), {
|
|
1224
880
|
id,
|
|
1225
881
|
onCheckComplete,
|
|
1226
882
|
addInvalidId,
|
|
1227
883
|
removeInvalidId,
|
|
1228
884
|
addDraftId,
|
|
1229
885
|
removeDraftId
|
|
1230
|
-
} = props, editState =
|
|
1231
|
-
if (react.useEffect(() => {
|
|
1232
|
-
validationHasErrors ? addInvalidId(id) : removeInvalidId(id), editState.draft ? addDraftId(id) : removeDraftId(id), isValidating || onCheckComplete(id);
|
|
1233
|
-
}, [
|
|
1234
|
-
addDraftId,
|
|
1235
|
-
addInvalidId,
|
|
1236
|
-
editState.draft,
|
|
1237
|
-
id,
|
|
886
|
+
} = props, editState = useEditState(id, ""), documentType = editState.draft?._type ?? editState.published?._type ?? "", {
|
|
1238
887
|
isValidating,
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
888
|
+
validation: t0
|
|
889
|
+
} = useValidationStatus(id, documentType, !1);
|
|
890
|
+
let t1;
|
|
891
|
+
$[0] !== t0 ? (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
|
|
892
|
+
const validation = t1, schema = useSchema();
|
|
893
|
+
let t2;
|
|
894
|
+
$[2] !== isValidating || $[3] !== validation ? (t2 = !isValidating && validation.some(_temp$1), $[2] = isValidating, $[3] = validation, $[4] = t2) : t2 = $[4];
|
|
895
|
+
const validationHasErrors = t2;
|
|
896
|
+
let t3, t4;
|
|
897
|
+
if ($[5] !== addDraftId || $[6] !== addInvalidId || $[7] !== editState.draft || $[8] !== id || $[9] !== isValidating || $[10] !== onCheckComplete || $[11] !== removeDraftId || $[12] !== removeInvalidId || $[13] !== validationHasErrors ? (t3 = () => {
|
|
898
|
+
validationHasErrors ? addInvalidId(id) : removeInvalidId(id), editState.draft ? addDraftId(id) : removeDraftId(id), isValidating || onCheckComplete(id);
|
|
899
|
+
}, t4 = [addDraftId, addInvalidId, editState.draft, id, isValidating, onCheckComplete, removeDraftId, removeInvalidId, validationHasErrors], $[5] = addDraftId, $[6] = addInvalidId, $[7] = editState.draft, $[8] = id, $[9] = isValidating, $[10] = onCheckComplete, $[11] = removeDraftId, $[12] = removeInvalidId, $[13] = validationHasErrors, $[14] = t3, $[15] = t4) : (t3 = $[14], t4 = $[15]), useEffect(t3, t4), !editState.draft)
|
|
1244
900
|
return null;
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
layout: "default",
|
|
1256
|
-
value: editState.draft,
|
|
1257
|
-
schemaType
|
|
1258
|
-
}
|
|
1259
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {})
|
|
1260
|
-
}
|
|
1261
|
-
);
|
|
901
|
+
let t5;
|
|
902
|
+
$[16] !== editState.draft._type || $[17] !== schema ? (t5 = schema.get(editState.draft._type), $[16] = editState.draft._type, $[17] = schema, $[18] = t5) : t5 = $[18];
|
|
903
|
+
const schemaType = t5, t6 = validationHasErrors ? "critical" : "positive";
|
|
904
|
+
let t7;
|
|
905
|
+
$[19] !== editState.draft || $[20] !== schemaType ? (t7 = editState.draft && schemaType ? /* @__PURE__ */ jsx(Preview, { layout: "default", value: editState.draft, schemaType }) : /* @__PURE__ */ jsx(Spinner, {}), $[19] = editState.draft, $[20] = schemaType, $[21] = t7) : t7 = $[21];
|
|
906
|
+
let t8;
|
|
907
|
+
return $[22] !== t6 || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsx(Card, { border: !0, padding: 2, tone: t6, children: t7 }), $[22] = t6, $[23] = t7, $[24] = t8) : t8 = $[24], t8;
|
|
908
|
+
}
|
|
909
|
+
function _temp$1(item) {
|
|
910
|
+
return item.level === "error";
|
|
1262
911
|
}
|
|
1263
912
|
function InfoIcon(props) {
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
);
|
|
913
|
+
const $ = c(11), {
|
|
914
|
+
text,
|
|
915
|
+
icon,
|
|
916
|
+
tone,
|
|
917
|
+
children
|
|
918
|
+
} = props, Icon = icon;
|
|
919
|
+
let t0;
|
|
920
|
+
$[0] !== children || $[1] !== text ? (t0 = children ? /* @__PURE__ */ jsx(Fragment, { children }) : /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, children: text }) }), $[0] = children, $[1] = text, $[2] = t0) : t0 = $[2];
|
|
921
|
+
let t1;
|
|
922
|
+
$[3] !== Icon ? (t1 = /* @__PURE__ */ jsx(Icon, {}), $[3] = Icon, $[4] = t1) : t1 = $[4];
|
|
923
|
+
let t2;
|
|
924
|
+
$[5] !== t1 || $[6] !== tone ? (t2 = /* @__PURE__ */ jsx(TextWithTone, { tone, size: 1, children: t1 }), $[5] = t1, $[6] = tone, $[7] = t2) : t2 = $[7];
|
|
925
|
+
let t3;
|
|
926
|
+
return $[8] !== t0 || $[9] !== t2 ? (t3 = /* @__PURE__ */ jsx(Tooltip, { animate: !0, portal: !0, content: t0, children: t2 }), $[8] = t0, $[9] = t2, $[10] = t3) : t3 = $[10], t3;
|
|
1274
927
|
}
|
|
1275
928
|
function Info() {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
]
|
|
929
|
+
const $ = c(4);
|
|
930
|
+
let t0;
|
|
931
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
932
|
+
maxWidth: 250
|
|
933
|
+
}, $[0] = t0) : t0 = $[0];
|
|
934
|
+
let t1;
|
|
935
|
+
$[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Bulk publishing uses the Scheduling API." }) }), $[1] = t1) : t1 = $[1];
|
|
936
|
+
let t2;
|
|
937
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Customized Document Actions in the Studio will not execute. Webhooks will execute." }) }), $[2] = t2) : t2 = $[2];
|
|
938
|
+
let t3;
|
|
939
|
+
return $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(InfoIcon, { icon: InfoOutlineIcon, tone: "primary", children: /* @__PURE__ */ jsxs(Stack, { padding: 3, space: 4, style: t0, children: [
|
|
940
|
+
t1,
|
|
941
|
+
t2,
|
|
942
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Validation is checked before rendering the button below, but the Scheduling API will not check for \u2013 or enforce \u2013 validation." }) })
|
|
943
|
+
] }) }), $[3] = t3) : t3 = $[3], t3;
|
|
1281
944
|
}
|
|
1282
945
|
function BulkPublish(props) {
|
|
1283
|
-
const
|
|
946
|
+
const $ = c(23), {
|
|
947
|
+
translations
|
|
948
|
+
} = props;
|
|
949
|
+
let t0;
|
|
950
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
951
|
+
apiVersion: API_VERSION
|
|
952
|
+
}, $[0] = t0) : t0 = $[0];
|
|
953
|
+
const client = useClient(t0), {
|
|
954
|
+
projectId,
|
|
955
|
+
dataset
|
|
956
|
+
} = useWorkspace(), toast = useToast(), [invalidIds, setInvalidIds] = useState(null);
|
|
957
|
+
let t1;
|
|
958
|
+
$[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[1] = t1) : t1 = $[1];
|
|
959
|
+
const [checkedIds, setCheckedIds] = useState(t1);
|
|
960
|
+
let t2;
|
|
961
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = (id) => {
|
|
1284
962
|
setCheckedIds((ids) => Array.from(/* @__PURE__ */ new Set([...ids, id])));
|
|
1285
|
-
}, []
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
963
|
+
}, $[2] = t2) : t2 = $[2];
|
|
964
|
+
const onCheckComplete = t2, [open, setOpen] = useState(!1);
|
|
965
|
+
let t3;
|
|
966
|
+
$[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = () => setOpen(!0), $[3] = t3) : t3 = $[3];
|
|
967
|
+
const onOpen = t3;
|
|
968
|
+
let t4;
|
|
969
|
+
$[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = () => setOpen(!1), $[4] = t4) : t4 = $[4];
|
|
970
|
+
const onClose = t4;
|
|
971
|
+
let t5;
|
|
972
|
+
$[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = (id_0) => {
|
|
973
|
+
setInvalidIds((ids_0) => ids_0 ? Array.from(/* @__PURE__ */ new Set([...ids_0, id_0])) : [id_0]);
|
|
974
|
+
}, $[5] = t5) : t5 = $[5];
|
|
975
|
+
const addInvalidId = t5;
|
|
976
|
+
let t6;
|
|
977
|
+
$[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = (id_1) => {
|
|
978
|
+
setInvalidIds((ids_1) => ids_1 ? ids_1.filter((i) => i !== id_1) : []);
|
|
979
|
+
}, $[6] = t6) : t6 = $[6];
|
|
980
|
+
const removeInvalidId = t6;
|
|
981
|
+
let t7;
|
|
982
|
+
$[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = [], $[7] = t7) : t7 = $[7];
|
|
983
|
+
const [draftIds, setDraftIds] = useState(t7);
|
|
984
|
+
let t8;
|
|
985
|
+
$[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = (id_2) => {
|
|
986
|
+
setDraftIds((ids_2) => Array.from(/* @__PURE__ */ new Set([...ids_2, id_2])));
|
|
987
|
+
}, $[8] = t8) : t8 = $[8];
|
|
988
|
+
const addDraftId = t8;
|
|
989
|
+
let t9;
|
|
990
|
+
$[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t9 = (id_3) => {
|
|
991
|
+
setDraftIds((ids_3) => ids_3.filter((i_0) => i_0 !== id_3));
|
|
992
|
+
}, $[9] = t9) : t9 = $[9];
|
|
993
|
+
const removeDraftId = t9;
|
|
994
|
+
let t10;
|
|
995
|
+
$[10] !== client || $[11] !== dataset || $[12] !== projectId || $[13] !== toast || $[14] !== translations ? (t10 = () => {
|
|
996
|
+
const body = translations.map(_temp);
|
|
1297
997
|
client.request({
|
|
1298
998
|
uri: `/publish/${projectId}/${dataset}`,
|
|
1299
999
|
method: "POST",
|
|
@@ -1311,328 +1011,298 @@ function BulkPublish(props) {
|
|
|
1311
1011
|
description: "Bulk publish failed"
|
|
1312
1012
|
});
|
|
1313
1013
|
});
|
|
1314
|
-
}, [
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Inline, { space: 3, children: [
|
|
1322
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "bold", size: 1, children: "Bulk publishing" }),
|
|
1323
|
-
/* @__PURE__ */ jsxRuntime.jsx(Info, {})
|
|
1014
|
+
}, $[10] = client, $[11] = dataset, $[12] = projectId, $[13] = toast, $[14] = translations, $[15] = t10) : t10 = $[15];
|
|
1015
|
+
const handleBulkPublish = t10, disabled = checkedIds.length !== translations.length || !!(invalidIds && invalidIds?.length > 0) || !draftIds.length;
|
|
1016
|
+
let t11;
|
|
1017
|
+
return $[16] !== disabled || $[17] !== draftIds || $[18] !== handleBulkPublish || $[19] !== invalidIds || $[20] !== open || $[21] !== translations ? (t11 = translations?.length > 0 ? /* @__PURE__ */ jsx(Card, { padding: 4, border: !0, radius: 2, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
1018
|
+
/* @__PURE__ */ jsxs(Inline, { space: 3, children: [
|
|
1019
|
+
/* @__PURE__ */ jsx(Text, { weight: "bold", size: 1, children: "Bulk publishing" }),
|
|
1020
|
+
/* @__PURE__ */ jsx(Info, {})
|
|
1324
1021
|
] }),
|
|
1325
|
-
/* @__PURE__ */
|
|
1326
|
-
|
|
1327
|
-
{
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
" ",
|
|
1353
|
-
"validation issues that must addressed first"
|
|
1354
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsx(sanity.TextWithTone, { tone: "positive", size: 1, children: "All drafts are valid and can be bulk published" })
|
|
1355
|
-
] }) : null,
|
|
1356
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 1, children: translations.filter((translation) => {
|
|
1357
|
-
var _a;
|
|
1358
|
-
return (_a = translation == null ? void 0 : translation.value) == null ? void 0 : _a._ref;
|
|
1359
|
-
}).map((translation) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1360
|
-
DocumentCheck,
|
|
1361
|
-
{
|
|
1362
|
-
id: translation.value._ref,
|
|
1363
|
-
onCheckComplete,
|
|
1364
|
-
addInvalidId,
|
|
1365
|
-
removeInvalidId,
|
|
1366
|
-
addDraftId,
|
|
1367
|
-
removeDraftId
|
|
1368
|
-
},
|
|
1369
|
-
translation._key
|
|
1370
|
-
)) }),
|
|
1371
|
-
draftIds.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1372
|
-
ui.Button,
|
|
1373
|
-
{
|
|
1374
|
-
mode: "ghost",
|
|
1375
|
-
tone: invalidIds && (invalidIds == null ? void 0 : invalidIds.length) > 0 ? "caution" : "positive",
|
|
1376
|
-
text: draftIds.length === 1 ? "Publish draft document" : `Bulk publish ${draftIds.length} draft documents`,
|
|
1377
|
-
onClick: handleBulkPublish,
|
|
1378
|
-
disabled
|
|
1379
|
-
}
|
|
1380
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "No draft documents to publish" })
|
|
1381
|
-
] })
|
|
1382
|
-
}
|
|
1383
|
-
)
|
|
1384
|
-
] }) }) : null;
|
|
1022
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(Button, { onClick: onOpen, text: "Prepare bulk publishing", mode: "ghost" }) }),
|
|
1023
|
+
open && /* @__PURE__ */ jsx(Dialog, { animate: !0, header: "Bulk publishing", id: "bulk-publish-dialog", onClose, zOffset: 1e3, width: 3, children: /* @__PURE__ */ jsxs(Stack, { space: 4, padding: 4, children: [
|
|
1024
|
+
draftIds.length > 0 ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
1025
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
1026
|
+
"There",
|
|
1027
|
+
" ",
|
|
1028
|
+
draftIds.length === 1 ? "is 1 draft document" : `are ${draftIds.length} draft documents`,
|
|
1029
|
+
"."
|
|
1030
|
+
] }),
|
|
1031
|
+
invalidIds && invalidIds.length > 0 ? /* @__PURE__ */ jsxs(TextWithTone, { tone: "critical", size: 1, children: [
|
|
1032
|
+
invalidIds.length === 1 ? "1 draft document has" : `${invalidIds.length} draft documents have`,
|
|
1033
|
+
" ",
|
|
1034
|
+
"validation issues that must addressed first"
|
|
1035
|
+
] }) : /* @__PURE__ */ jsx(TextWithTone, { tone: "positive", size: 1, children: "All drafts are valid and can be bulk published" })
|
|
1036
|
+
] }) : null,
|
|
1037
|
+
/* @__PURE__ */ jsx(Stack, { space: 1, children: translations.filter(_temp2).map((translation_1) => /* @__PURE__ */ jsx(DocumentCheck, { id: translation_1.value._ref, onCheckComplete, addInvalidId, removeInvalidId, addDraftId, removeDraftId }, translation_1._key)) }),
|
|
1038
|
+
draftIds.length > 0 ? /* @__PURE__ */ jsx(Button, { mode: "ghost", tone: invalidIds && invalidIds?.length > 0 ? "caution" : "positive", text: draftIds.length === 1 ? "Publish draft document" : `Bulk publish ${draftIds.length} draft documents`, onClick: handleBulkPublish, disabled }) : /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "No draft documents to publish" })
|
|
1039
|
+
] }) })
|
|
1040
|
+
] }) }) : null, $[16] = disabled, $[17] = draftIds, $[18] = handleBulkPublish, $[19] = invalidIds, $[20] = open, $[21] = translations, $[22] = t11) : t11 = $[22], t11;
|
|
1041
|
+
}
|
|
1042
|
+
function _temp2(translation_0) {
|
|
1043
|
+
return translation_0?.value?._ref;
|
|
1044
|
+
}
|
|
1045
|
+
function _temp(translation) {
|
|
1046
|
+
return {
|
|
1047
|
+
documentId: translation.value._ref
|
|
1048
|
+
};
|
|
1385
1049
|
}
|
|
1386
1050
|
function ReferencePatcher(props) {
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
);
|
|
1051
|
+
const $ = c(14), {
|
|
1052
|
+
translation,
|
|
1053
|
+
documentType,
|
|
1054
|
+
metadataId
|
|
1055
|
+
} = props, editState = useEditState(translation.value._ref, documentType);
|
|
1056
|
+
let t0;
|
|
1057
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
1058
|
+
apiVersion: API_VERSION
|
|
1059
|
+
}, $[0] = t0) : t0 = $[0];
|
|
1060
|
+
const client = useClient(t0), {
|
|
1061
|
+
onChange
|
|
1062
|
+
} = useDocumentPane();
|
|
1063
|
+
let t1;
|
|
1064
|
+
$[1] !== editState || $[2] !== onChange || $[3] !== translation._key || $[4] !== translation.value._ref || $[5] !== translation.value._strengthenOnPublish || $[6] !== translation.value._weak ? (t1 = () => {
|
|
1065
|
+
if (translation.value._ref && translation.value._weak && translation.value._strengthenOnPublish && !editState.draft && editState.published && editState.ready) {
|
|
1066
|
+
const referencePathBase = ["translations", {
|
|
1067
|
+
_key: translation._key
|
|
1068
|
+
}, "value"];
|
|
1069
|
+
onChange(new PatchEvent([unset([...referencePathBase, "_weak"]), unset([...referencePathBase, "_strengthenOnPublish"])]));
|
|
1407
1070
|
}
|
|
1408
|
-
}, [translation,
|
|
1071
|
+
}, $[1] = editState, $[2] = onChange, $[3] = translation._key, $[4] = translation.value._ref, $[5] = translation.value._strengthenOnPublish, $[6] = translation.value._weak, $[7] = t1) : t1 = $[7];
|
|
1072
|
+
let t2;
|
|
1073
|
+
return $[8] !== client || $[9] !== editState || $[10] !== metadataId || $[11] !== onChange || $[12] !== translation ? (t2 = [translation, editState, metadataId, client, onChange], $[8] = client, $[9] = editState, $[10] = metadataId, $[11] = onChange, $[12] = translation, $[13] = t2) : t2 = $[13], useEffect(t1, t2), null;
|
|
1409
1074
|
}
|
|
1410
1075
|
function OptimisticallyStrengthen(props) {
|
|
1411
|
-
const
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1076
|
+
const $ = c(9), {
|
|
1077
|
+
translations: t0,
|
|
1078
|
+
metadataId
|
|
1079
|
+
} = props;
|
|
1080
|
+
let t1;
|
|
1081
|
+
$[0] !== t0 ? (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
|
|
1082
|
+
const translations = t1;
|
|
1083
|
+
if (!translations.length)
|
|
1084
|
+
return null;
|
|
1085
|
+
let t2;
|
|
1086
|
+
if ($[2] !== metadataId || $[3] !== translations) {
|
|
1087
|
+
let t32;
|
|
1088
|
+
$[5] !== metadataId ? (t32 = (translation) => translation.value._strengthenOnPublish?.type ? /* @__PURE__ */ jsx(ReferencePatcher, { translation, documentType: translation.value._strengthenOnPublish.type, metadataId }, translation._key) : null, $[5] = metadataId, $[6] = t32) : t32 = $[6], t2 = translations.map(t32), $[2] = metadataId, $[3] = translations, $[4] = t2;
|
|
1089
|
+
} else
|
|
1090
|
+
t2 = $[4];
|
|
1091
|
+
let t3;
|
|
1092
|
+
return $[7] !== t2 ? (t3 = /* @__PURE__ */ jsx(Fragment, { children: t2 }), $[7] = t2, $[8] = t3) : t3 = $[8], t3;
|
|
1426
1093
|
}
|
|
1427
|
-
var metadata = (schemaTypes, metadataFields) =>
|
|
1094
|
+
var metadata = (schemaTypes, metadataFields) => defineType({
|
|
1428
1095
|
type: "document",
|
|
1429
1096
|
name: METADATA_SCHEMA_NAME,
|
|
1430
1097
|
title: "Translation metadata",
|
|
1431
|
-
icon:
|
|
1098
|
+
icon: TranslateIcon,
|
|
1432
1099
|
liveEdit: !0,
|
|
1433
|
-
fields: [
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
type: "
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1100
|
+
fields: [defineField({
|
|
1101
|
+
name: TRANSLATIONS_ARRAY_NAME,
|
|
1102
|
+
type: "internationalizedArrayReference"
|
|
1103
|
+
}), defineField({
|
|
1104
|
+
name: "schemaTypes",
|
|
1105
|
+
description: "Optional: Used to filter the reference fields above so all translations share the same types.",
|
|
1106
|
+
type: "array",
|
|
1107
|
+
of: [{
|
|
1108
|
+
type: "string"
|
|
1109
|
+
}],
|
|
1110
|
+
options: {
|
|
1111
|
+
list: schemaTypes
|
|
1112
|
+
},
|
|
1113
|
+
readOnly: ({
|
|
1114
|
+
value
|
|
1115
|
+
}) => !!value
|
|
1116
|
+
}), ...metadataFields],
|
|
1448
1117
|
preview: {
|
|
1449
1118
|
select: {
|
|
1450
1119
|
translations: TRANSLATIONS_ARRAY_NAME,
|
|
1451
1120
|
documentSchemaTypes: "schemaTypes"
|
|
1452
1121
|
},
|
|
1453
1122
|
prepare(selection) {
|
|
1454
|
-
const {
|
|
1455
|
-
|
|
1456
|
-
documentSchemaTypes
|
|
1457
|
-
].filter(Boolean).join(" ");
|
|
1123
|
+
const {
|
|
1124
|
+
translations = [],
|
|
1125
|
+
documentSchemaTypes = []
|
|
1126
|
+
} = selection, title = translations.length === 1 ? "1 Translation" : `${translations.length} Translations`, languageKeys = translations.length ? translations.map((t) => t._key.toUpperCase()).join(", ") : "", subtitle = [languageKeys ? `(${languageKeys})` : null, documentSchemaTypes?.length ? documentSchemaTypes.map((s) => s).join(", ") : ""].filter(Boolean).join(" ");
|
|
1458
1127
|
return {
|
|
1459
1128
|
title,
|
|
1460
1129
|
subtitle
|
|
1461
1130
|
};
|
|
1462
1131
|
}
|
|
1463
1132
|
}
|
|
1464
|
-
})
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
)
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
OptimisticallyStrengthen,
|
|
1510
|
-
{
|
|
1511
|
-
metadataId,
|
|
1512
|
-
translations: weakAndTypedTranslations
|
|
1513
|
-
}
|
|
1514
|
-
) : null,
|
|
1515
|
-
props.renderDefault(props)
|
|
1516
|
-
] });
|
|
1517
|
-
}
|
|
1518
|
-
return props.renderDefault(props);
|
|
1133
|
+
});
|
|
1134
|
+
const documentInternationalization = definePlugin((config) => {
|
|
1135
|
+
const pluginConfig = {
|
|
1136
|
+
...DEFAULT_CONFIG,
|
|
1137
|
+
...config
|
|
1138
|
+
}, {
|
|
1139
|
+
supportedLanguages,
|
|
1140
|
+
schemaTypes,
|
|
1141
|
+
languageField,
|
|
1142
|
+
bulkPublish,
|
|
1143
|
+
metadataFields
|
|
1144
|
+
} = pluginConfig;
|
|
1145
|
+
if (schemaTypes.length === 0)
|
|
1146
|
+
throw new Error("You must specify at least one schema type on which to enable document internationalization. Update the `schemaTypes` option in the documentInternationalization() configuration.");
|
|
1147
|
+
return {
|
|
1148
|
+
name: "@sanity/document-internationalization",
|
|
1149
|
+
studio: {
|
|
1150
|
+
components: {
|
|
1151
|
+
layout: (props) => DocumentInternationalizationProvider({
|
|
1152
|
+
...props,
|
|
1153
|
+
pluginConfig
|
|
1154
|
+
})
|
|
1155
|
+
}
|
|
1156
|
+
},
|
|
1157
|
+
i18n: {
|
|
1158
|
+
bundles: [documentInternationalizationUsEnglishLocaleBundle]
|
|
1159
|
+
},
|
|
1160
|
+
// Adds:
|
|
1161
|
+
// - A bulk-publishing UI component to the form
|
|
1162
|
+
// - Will only work for projects on a compatible plan
|
|
1163
|
+
form: {
|
|
1164
|
+
components: {
|
|
1165
|
+
input: (props) => {
|
|
1166
|
+
if (props.id === "root" && props.schemaType.name === METADATA_SCHEMA_NAME && isSanityDocument(props?.value)) {
|
|
1167
|
+
const metadataId = props?.value?._id, translations = (
|
|
1168
|
+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
|
|
1169
|
+
props?.value?.translations ?? []
|
|
1170
|
+
), weakAndTypedTranslations = translations.filter(({
|
|
1171
|
+
value
|
|
1172
|
+
}) => value?._weak && value._strengthenOnPublish);
|
|
1173
|
+
return /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
|
|
1174
|
+
bulkPublish ? /* @__PURE__ */ jsx(BulkPublish, { translations }) : null,
|
|
1175
|
+
weakAndTypedTranslations.length > 0 ? /* @__PURE__ */ jsx(OptimisticallyStrengthen, { metadataId, translations: weakAndTypedTranslations }) : null,
|
|
1176
|
+
props.renderDefault(props)
|
|
1177
|
+
] });
|
|
1519
1178
|
}
|
|
1179
|
+
return props.renderDefault(props);
|
|
1520
1180
|
}
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
// Adds:
|
|
1184
|
+
// - The `Translations` dropdown to the editing form
|
|
1185
|
+
// - `Badges` to documents with a language value
|
|
1186
|
+
// - The `DeleteMetadataAction` action to the metadata document type
|
|
1187
|
+
document: {
|
|
1188
|
+
unstable_languageFilter: (prev, ctx) => {
|
|
1189
|
+
const {
|
|
1190
|
+
schemaType,
|
|
1191
|
+
documentId
|
|
1192
|
+
} = ctx;
|
|
1193
|
+
return schemaTypes.includes(schemaType) && documentId ? [...prev, (props) => DocumentInternationalizationMenu({
|
|
1194
|
+
...props,
|
|
1195
|
+
documentId
|
|
1196
|
+
})] : prev;
|
|
1521
1197
|
},
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
if (!parent)
|
|
1610
|
-
return null;
|
|
1611
|
-
const language = (Array.isArray(parent) ? parent : [parent]).find((p) => p._key);
|
|
1612
|
-
return language != null && language._key ? document.schemaTypes ? {
|
|
1613
|
-
filter: `_type in $schemaTypes && ${languageField} == $language`,
|
|
1614
|
-
params: {
|
|
1615
|
-
schemaTypes: document.schemaTypes,
|
|
1616
|
-
language: language._key
|
|
1617
|
-
}
|
|
1618
|
-
} : {
|
|
1619
|
-
filter: `${languageField} == $language`,
|
|
1620
|
-
params: { language: language._key }
|
|
1621
|
-
} : null;
|
|
1622
|
-
}
|
|
1198
|
+
badges: (prev, {
|
|
1199
|
+
schemaType
|
|
1200
|
+
}) => schemaTypes.includes(schemaType) ? [(props) => LanguageBadge(props), ...prev] : prev,
|
|
1201
|
+
actions: (prev, {
|
|
1202
|
+
schemaType
|
|
1203
|
+
}) => schemaType === METADATA_SCHEMA_NAME ? [...prev, DeleteMetadataAction] : prev
|
|
1204
|
+
},
|
|
1205
|
+
// Adds:
|
|
1206
|
+
// - The `Translations metadata` document type to the schema
|
|
1207
|
+
schema: {
|
|
1208
|
+
// Create the metadata document type
|
|
1209
|
+
types: [metadata(schemaTypes, metadataFields)],
|
|
1210
|
+
// For every schema type this plugin is enabled on
|
|
1211
|
+
// Create an initial value template to set the language
|
|
1212
|
+
templates: (prev, {
|
|
1213
|
+
schema
|
|
1214
|
+
}) => {
|
|
1215
|
+
if (!Array.isArray(supportedLanguages))
|
|
1216
|
+
return prev;
|
|
1217
|
+
const parameterizedTemplates = schemaTypes.map((schemaType) => ({
|
|
1218
|
+
id: `${schemaType}-parameterized`,
|
|
1219
|
+
title: `${schema?.get(schemaType)?.title ?? schemaType}: with Language`,
|
|
1220
|
+
schemaType,
|
|
1221
|
+
parameters: [{
|
|
1222
|
+
name: "languageId",
|
|
1223
|
+
title: "Language ID",
|
|
1224
|
+
type: "string"
|
|
1225
|
+
}],
|
|
1226
|
+
value: ({
|
|
1227
|
+
languageId
|
|
1228
|
+
}) => ({
|
|
1229
|
+
[languageField]: languageId
|
|
1230
|
+
})
|
|
1231
|
+
})), staticTemplates = schemaTypes.flatMap((schemaType) => supportedLanguages.map((language) => ({
|
|
1232
|
+
id: `${schemaType}-${language.id}`,
|
|
1233
|
+
title: `${language.title} ${schema?.get(schemaType)?.title ?? schemaType}`,
|
|
1234
|
+
schemaType,
|
|
1235
|
+
value: {
|
|
1236
|
+
[languageField]: language.id
|
|
1237
|
+
}
|
|
1238
|
+
})));
|
|
1239
|
+
return [...prev, ...parameterizedTemplates, ...staticTemplates];
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1242
|
+
// Uses:
|
|
1243
|
+
// - `sanity-plugin-internationalized-array` to maintain the translations array
|
|
1244
|
+
plugins: [
|
|
1245
|
+
// Translation metadata stores its references using this plugin
|
|
1246
|
+
// It cuts down on attribute usage and gives UI conveniences to add new translations
|
|
1247
|
+
internationalizedArray({
|
|
1248
|
+
apiVersion: pluginConfig.apiVersion,
|
|
1249
|
+
languages: supportedLanguages,
|
|
1250
|
+
fieldTypes: [defineField({
|
|
1251
|
+
name: "reference",
|
|
1252
|
+
type: "reference",
|
|
1253
|
+
to: schemaTypes.map((type) => ({
|
|
1254
|
+
type
|
|
1255
|
+
})),
|
|
1256
|
+
weak: pluginConfig.weakReferences,
|
|
1257
|
+
// Reference filters don't actually enforce validation!
|
|
1258
|
+
validation: (Rule) => (
|
|
1259
|
+
// @ts-expect-error - fix typings
|
|
1260
|
+
Rule.custom(async (item, context) => {
|
|
1261
|
+
if (!item?.value?._ref || !item?._key)
|
|
1262
|
+
return !0;
|
|
1263
|
+
const valueLanguage = await context.getClient({
|
|
1264
|
+
apiVersion: API_VERSION
|
|
1265
|
+
}).fetch(`*[_id in [$ref, $draftRef]][0].${languageField}`, {
|
|
1266
|
+
ref: item.value._ref,
|
|
1267
|
+
draftRef: `drafts.${item.value._ref}`
|
|
1268
|
+
});
|
|
1269
|
+
return valueLanguage && valueLanguage === item._key ? !0 : "Referenced document does not have the correct language value";
|
|
1270
|
+
})
|
|
1271
|
+
),
|
|
1272
|
+
options: {
|
|
1273
|
+
// @ts-expect-error - Update type once it knows the values of this filter
|
|
1274
|
+
filter: ({
|
|
1275
|
+
parent,
|
|
1276
|
+
document
|
|
1277
|
+
}) => {
|
|
1278
|
+
if (!parent) return null;
|
|
1279
|
+
const language = (Array.isArray(parent) ? parent : [parent]).find((p) => p._key);
|
|
1280
|
+
return language?._key ? document.schemaTypes ? {
|
|
1281
|
+
filter: `_type in $schemaTypes && ${languageField} == $language`,
|
|
1282
|
+
params: {
|
|
1283
|
+
schemaTypes: document.schemaTypes,
|
|
1284
|
+
language: language._key
|
|
1623
1285
|
}
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1286
|
+
} : {
|
|
1287
|
+
filter: `${languageField} == $language`,
|
|
1288
|
+
params: {
|
|
1289
|
+
language: language._key
|
|
1290
|
+
}
|
|
1291
|
+
} : null;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}, {
|
|
1295
|
+
strict: !1
|
|
1296
|
+
})]
|
|
1297
|
+
})
|
|
1298
|
+
]
|
|
1299
|
+
};
|
|
1300
|
+
});
|
|
1301
|
+
export {
|
|
1302
|
+
DeleteTranslationAction,
|
|
1303
|
+
DocumentInternationalizationMenu,
|
|
1304
|
+
DuplicateWithTranslationsAction,
|
|
1305
|
+
documentInternationalization,
|
|
1306
|
+
useDocumentInternationalizationContext
|
|
1307
|
+
};
|
|
1638
1308
|
//# sourceMappingURL=index.js.map
|