@sanity/document-internationalization 6.2.13 → 6.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
2
1
  import { c } from "react/compiler-runtime";
3
2
  import { TrashIcon } from "@sanity/icons/Trash";
4
- import { Flex, Spinner, Text, Card, Stack, Grid, Button, useToast, Tooltip, Box, Badge, useClickOutsideEvent, TextInput, Popover, Inline, Dialog } from "@sanity/ui";
5
- import { useEffect, createContext, use, useContext, useState, useRef } from "react";
6
- import { useSchema, Preview, useClient, useWorkspace, defineLocaleResourceBundle, useDocumentStore, useDocumentOperation, useDocumentPairPermissions, DEFAULT_STUDIO_CLIENT_OPTIONS, useTranslation, useCurrentUser, InsufficientPermissionsMessage, isDocumentSchemaType, pathToString, isVersionId, getVersionFromId, getVersionId, getDraftId, usePerspective, useEditState, useValidationStatus, TextWithTone, PatchEvent, unset, defineType, defineField, definePlugin, isSanityDocument } from "sanity";
3
+ import { Badge, Box, Button, Card, Dialog, Flex, Grid, Inline, Popover, Spinner, Stack, Text, TextInput, Tooltip, useClickOutsideEvent, useToast } from "@sanity/ui";
4
+ import { createContext, use, useContext, useEffect, useRef, useState } from "react";
5
+ import { DEFAULT_STUDIO_CLIENT_OPTIONS, InsufficientPermissionsMessage, PatchEvent, Preview, TextWithTone, defineField, defineLocaleResourceBundle, definePlugin, defineType, getDraftId, getVersionFromId, getVersionId, isDocumentSchemaType, isSanityDocument, isVersionId, pathToString, unset, useClient, useCurrentUser, useDocumentOperation, useDocumentPairPermissions, useDocumentStore, useEditState, usePerspective, useSchema, useTranslation, useValidationStatus, useWorkspace } from "sanity";
7
6
  import { LANGUAGE_FIELD_NAME, internationalizedArray } from "sanity-plugin-internationalized-array";
8
7
  import { Feedback, useListeningQuery } from "sanity-plugin-utils";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { CopyIcon } from "@sanity/icons/Copy";
10
10
  import { uuid } from "@sanity/uuid";
11
- import { firstValueFrom, filter } from "rxjs";
11
+ import { filter, firstValueFrom } from "rxjs";
12
12
  import { useRouter } from "sanity/router";
13
- import { structureLocaleNamespace, usePaneRouter, useDocumentPane } from "sanity/structure";
13
+ import { structureLocaleNamespace, useDocumentPane, usePaneRouter } from "sanity/structure";
14
14
  import { TranslateIcon } from "@sanity/icons/Translate";
15
15
  import { CogIcon } from "@sanity/icons/Cog";
16
16
  import { randomKey } from "@sanity/util/content";
@@ -21,1364 +21,1411 @@ import { Mutation, extractWithPath } from "@sanity/mutator";
21
21
  import { EditIcon } from "@sanity/icons/Edit";
22
22
  import { InfoOutlineIcon } from "@sanity/icons/InfoOutline";
23
23
  function DocumentPreview(props) {
24
- const $ = c(7), schema = useSchema();
25
- let t0;
26
- $[0] !== props.type || $[1] !== schema ? (t0 = schema.get(props.type), $[0] = props.type, $[1] = schema, $[2] = t0) : t0 = $[2];
27
- const schemaType = t0;
28
- if (!schemaType) {
29
- let t12;
30
- 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;
31
- }
32
- let t1;
33
- return $[4] !== props.value || $[5] !== schemaType ? (t1 = /* @__PURE__ */ jsx(Preview, { value: props.value, schemaType }), $[4] = props.value, $[5] = schemaType, $[6] = t1) : t1 = $[6], t1;
24
+ let $ = c(7), schema = useSchema(), t0;
25
+ $[0] !== props.type || $[1] !== schema ? (t0 = schema.get(props.type), $[0] = props.type, $[1] = schema, $[2] = t0) : t0 = $[2];
26
+ let schemaType = t0;
27
+ if (!schemaType) {
28
+ let t1;
29
+ return $[3] === Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(Feedback, {
30
+ tone: "critical",
31
+ title: "Schema type not found"
32
+ }), $[3] = t1) : t1 = $[3], t1;
33
+ }
34
+ let t1;
35
+ return $[4] !== props.value || $[5] !== schemaType ? (t1 = /* @__PURE__ */ jsx(Preview, {
36
+ value: props.value,
37
+ schemaType
38
+ }), $[4] = props.value, $[5] = schemaType, $[6] = t1) : t1 = $[6], t1;
34
39
  }
35
40
  const METADATA_SCHEMA_NAME = "translation.metadata", TRANSLATIONS_ARRAY_NAME = "translations", API_VERSION = "2025-02-19", DEFAULT_CONFIG = {
36
- supportedLanguages: [],
37
- schemaTypes: [],
38
- languageField: "language",
39
- weakReferences: !1,
40
- bulkPublish: !1,
41
- metadataFields: [],
42
- apiVersion: API_VERSION,
43
- allowCreateMetaDoc: !1,
44
- callback: null,
45
- hideLanguageFilter: !1,
46
- metadataOmnisearchVisibility: !0,
47
- addTemplates: !0
41
+ supportedLanguages: [],
42
+ schemaTypes: [],
43
+ languageField: "language",
44
+ weakReferences: !1,
45
+ bulkPublish: !1,
46
+ metadataFields: [],
47
+ apiVersion: API_VERSION,
48
+ allowCreateMetaDoc: !1,
49
+ callback: null,
50
+ hideLanguageFilter: !1,
51
+ metadataOmnisearchVisibility: !0,
52
+ addTemplates: !0
48
53
  };
54
+ /**
55
+ * Splits an array of referring documents into two groups: translation metadata
56
+ * documents (whose `_type` matches the metadata schema name) and all other
57
+ * references. Used by the delete-translation dialog to show which metadata
58
+ * entries will be patched versus which external references may block deletion.
59
+ */
49
60
  function separateReferences(data = []) {
50
- const translations = [], otherReferences = [];
51
- return data && data.length > 0 && data.forEach((doc) => {
52
- doc._type === METADATA_SCHEMA_NAME ? translations.push(doc) : otherReferences.push(doc);
53
- }), {
54
- translations,
55
- otherReferences
56
- };
61
+ let translations = [], otherReferences = [];
62
+ return data && data.length > 0 && data.forEach((doc) => {
63
+ doc._type === METADATA_SCHEMA_NAME ? translations.push(doc) : otherReferences.push(doc);
64
+ }), {
65
+ translations,
66
+ otherReferences
67
+ };
57
68
  }
58
69
  function DeleteTranslationDialog(props) {
59
- const $ = c(33), {
60
- doc,
61
- documentId,
62
- setTranslations
63
- } = props;
64
- let t0;
65
- $[0] !== documentId ? (t0 = {
66
- id: documentId
67
- }, $[0] = documentId, $[1] = t0) : t0 = $[1];
68
- let t1;
69
- $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[2] = t1) : t1 = $[2];
70
- let t2;
71
- $[3] !== t0 ? (t2 = {
72
- params: t0,
73
- initialValue: t1
74
- }, $[3] = t0, $[4] = t2) : t2 = $[4];
75
- const {
76
- data,
77
- loading
78
- } = useListeningQuery("*[references($id)]{_id, _type, translations}", t2);
79
- let t3;
80
- $[5] !== data ? (t3 = separateReferences(data), $[5] = data, $[6] = t3) : t3 = $[6];
81
- const {
82
- translations,
83
- otherReferences
84
- } = t3;
85
- let t4, t5;
86
- if ($[7] !== setTranslations || $[8] !== translations ? (t4 = () => {
87
- setTranslations(translations);
88
- }, t5 = [setTranslations, translations], $[7] = setTranslations, $[8] = translations, $[9] = t4, $[10] = t5) : (t4 = $[9], t5 = $[10]), useEffect(t4, t5), loading) {
89
- let t62;
90
- return $[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t62 = /* @__PURE__ */ jsx(Flex, { padding: 4, align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) }), $[11] = t62) : t62 = $[11], t62;
91
- }
92
- let t6;
93
- $[12] !== translations ? (t6 = 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] = t6) : t6 = $[13];
94
- let t7;
95
- $[14] !== translations ? (t7 = /* @__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] = t7) : t7 = $[15];
96
- let t8;
97
- $[16] !== doc ? (t8 = /* @__PURE__ */ jsx(DocumentPreview, { value: doc, type: doc._type }), $[16] = doc, $[17] = t8) : t8 = $[17];
98
- let t9;
99
- $[18] !== translations ? (t9 = translations && translations.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
100
- /* @__PURE__ */ jsx(Card, { borderTop: !0 }),
101
- /* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
102
- "The reference in",
103
- " ",
104
- translations.length === 1 ? "this translations document" : "these translations documents",
105
- " ",
106
- "must be removed"
107
- ] }),
108
- translations.map(_temp$5)
109
- ] }) : null, $[18] = translations, $[19] = t9) : t9 = $[19];
110
- let t10;
111
- $[20] !== otherReferences ? (t10 = otherReferences && otherReferences.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
112
- /* @__PURE__ */ jsx(Card, { borderTop: !0 }),
113
- /* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
114
- otherReferences.length === 1 ? "There is an additional reference" : "There are additional references",
115
- " ",
116
- "to this document"
117
- ] }),
118
- otherReferences.map(_temp2$3)
119
- ] }) : null, $[20] = otherReferences, $[21] = t10) : t10 = $[21];
120
- let t11;
121
- $[22] !== t10 || $[23] !== t7 || $[24] !== t8 || $[25] !== t9 ? (t11 = /* @__PURE__ */ jsx(Card, { border: !0, padding: 3, children: /* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
122
- t7,
123
- t8,
124
- t9,
125
- t10
126
- ] }) }), $[22] = t10, $[23] = t7, $[24] = t8, $[25] = t9, $[26] = t11) : t11 = $[26];
127
- let t12;
128
- $[27] !== otherReferences.length ? (t12 = 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] = t12) : t12 = $[28];
129
- let t13;
130
- return $[29] !== t11 || $[30] !== t12 || $[31] !== t6 ? (t13 = /* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
131
- t6,
132
- t11,
133
- t12
134
- ] }), $[29] = t11, $[30] = t12, $[31] = t6, $[32] = t13) : t13 = $[32], t13;
70
+ let $ = c(33), { doc, documentId, setTranslations } = props, t0;
71
+ $[0] === documentId ? t0 = $[1] : (t0 = { id: documentId }, $[0] = documentId, $[1] = t0);
72
+ let t1;
73
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[2] = t1) : t1 = $[2];
74
+ let t2;
75
+ $[3] === t0 ? t2 = $[4] : (t2 = {
76
+ params: t0,
77
+ initialValue: t1
78
+ }, $[3] = t0, $[4] = t2);
79
+ let { data, loading } = useListeningQuery("*[references($id)]{_id, _type, translations}", t2), t3;
80
+ $[5] === data ? t3 = $[6] : (t3 = separateReferences(data), $[5] = data, $[6] = t3);
81
+ let { translations, otherReferences } = t3, t4, t5;
82
+ if ($[7] !== setTranslations || $[8] !== translations ? (t4 = () => {
83
+ setTranslations(translations);
84
+ }, t5 = [setTranslations, translations], $[7] = setTranslations, $[8] = translations, $[9] = t4, $[10] = t5) : (t4 = $[9], t5 = $[10]), useEffect(t4, t5), loading) {
85
+ let t6;
86
+ return $[11] === Symbol.for("react.memo_cache_sentinel") ? (t6 = /* @__PURE__ */ jsx(Flex, {
87
+ padding: 4,
88
+ align: "center",
89
+ justify: "center",
90
+ children: /* @__PURE__ */ jsx(Spinner, {})
91
+ }), $[11] = t6) : t6 = $[11], t6;
92
+ }
93
+ let t6;
94
+ $[12] === translations ? t6 = $[13] : (t6 = 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] = t6);
95
+ let t7;
96
+ $[14] === translations ? t7 = $[15] : (t7 = /* @__PURE__ */ jsx(Text, {
97
+ size: 1,
98
+ weight: "semibold",
99
+ 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" })
100
+ }), $[14] = translations, $[15] = t7);
101
+ let t8;
102
+ $[16] === doc ? t8 = $[17] : (t8 = /* @__PURE__ */ jsx(DocumentPreview, {
103
+ value: doc,
104
+ type: doc._type
105
+ }), $[16] = doc, $[17] = t8);
106
+ let t9;
107
+ $[18] === translations ? t9 = $[19] : (t9 = translations && translations.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
108
+ /* @__PURE__ */ jsx(Card, { borderTop: !0 }),
109
+ /* @__PURE__ */ jsxs(Text, {
110
+ size: 1,
111
+ weight: "semibold",
112
+ children: [
113
+ "The reference in",
114
+ " ",
115
+ translations.length === 1 ? "this translations document" : "these translations documents",
116
+ " ",
117
+ "must be removed"
118
+ ]
119
+ }),
120
+ translations.map(_temp$5)
121
+ ] }) : null, $[18] = translations, $[19] = t9);
122
+ let t10;
123
+ $[20] === otherReferences ? t10 = $[21] : (t10 = otherReferences && otherReferences.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
124
+ /* @__PURE__ */ jsx(Card, { borderTop: !0 }),
125
+ /* @__PURE__ */ jsxs(Text, {
126
+ size: 1,
127
+ weight: "semibold",
128
+ children: [
129
+ otherReferences.length === 1 ? "There is an additional reference" : "There are additional references",
130
+ " ",
131
+ "to this document"
132
+ ]
133
+ }),
134
+ otherReferences.map(_temp2$3)
135
+ ] }) : null, $[20] = otherReferences, $[21] = t10);
136
+ let t11;
137
+ $[22] !== t10 || $[23] !== t7 || $[24] !== t8 || $[25] !== t9 ? (t11 = /* @__PURE__ */ jsx(Card, {
138
+ border: !0,
139
+ padding: 3,
140
+ children: /* @__PURE__ */ jsxs(Stack, {
141
+ gap: 4,
142
+ children: [
143
+ t7,
144
+ t8,
145
+ t9,
146
+ t10
147
+ ]
148
+ })
149
+ }), $[22] = t10, $[23] = t7, $[24] = t8, $[25] = t9, $[26] = t11) : t11 = $[26];
150
+ let t12;
151
+ $[27] === otherReferences.length ? t12 = $[28] : (t12 = 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] = t12);
152
+ let t13;
153
+ return $[29] !== t11 || $[30] !== t12 || $[31] !== t6 ? (t13 = /* @__PURE__ */ jsxs(Stack, {
154
+ gap: 4,
155
+ children: [
156
+ t6,
157
+ t11,
158
+ t12
159
+ ]
160
+ }), $[29] = t11, $[30] = t12, $[31] = t6, $[32] = t13) : t13 = $[32], t13;
135
161
  }
136
162
  function _temp2$3(reference) {
137
- return /* @__PURE__ */ jsx(DocumentPreview, { value: reference, type: reference._type }, reference._id);
163
+ return /* @__PURE__ */ jsx(DocumentPreview, {
164
+ value: reference,
165
+ type: reference._type
166
+ }, reference._id);
138
167
  }
139
168
  function _temp$5(translation) {
140
- return /* @__PURE__ */ jsx(DocumentPreview, { value: translation, type: translation._type }, translation._id);
169
+ return /* @__PURE__ */ jsx(DocumentPreview, {
170
+ value: translation,
171
+ type: translation._type
172
+ }, translation._id);
141
173
  }
142
174
  function DeleteTranslationFooter(props) {
143
- const $ = c(8), {
144
- translations,
145
- onClose,
146
- onProceed
147
- } = props;
148
- let t0;
149
- $[0] !== onClose ? (t0 = /* @__PURE__ */ jsx(Button, { text: "Cancel", onClick: onClose, mode: "ghost" }), $[0] = onClose, $[1] = t0) : t0 = $[1];
150
- const t1 = translations && translations.length > 0 ? "Unset translation reference" : "Delete document";
151
- let t2;
152
- $[2] !== onProceed || $[3] !== t1 ? (t2 = /* @__PURE__ */ jsx(Button, { text: t1, onClick: onProceed, tone: "critical" }), $[2] = onProceed, $[3] = t1, $[4] = t2) : t2 = $[4];
153
- let t3;
154
- return $[5] !== t0 || $[6] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Grid, { gridTemplateColumns: 2, gap: 2, children: [
155
- t0,
156
- t2
157
- ] }), $[5] = t0, $[6] = t2, $[7] = t3) : t3 = $[7], t3;
175
+ let $ = c(8), { translations, onClose, onProceed } = props, t0;
176
+ $[0] === onClose ? t0 = $[1] : (t0 = /* @__PURE__ */ jsx(Button, {
177
+ text: "Cancel",
178
+ onClick: onClose,
179
+ mode: "ghost"
180
+ }), $[0] = onClose, $[1] = t0);
181
+ let t1 = translations && translations.length > 0 ? "Unset translation reference" : "Delete document", t2;
182
+ $[2] !== onProceed || $[3] !== t1 ? (t2 = /* @__PURE__ */ jsx(Button, {
183
+ text: t1,
184
+ onClick: onProceed,
185
+ tone: "critical"
186
+ }), $[2] = onProceed, $[3] = t1, $[4] = t2) : t2 = $[4];
187
+ let t3;
188
+ return $[5] !== t0 || $[6] !== t2 ? (t3 = /* @__PURE__ */ jsxs(Grid, {
189
+ gridTemplateColumns: 2,
190
+ gap: 2,
191
+ children: [t0, t2]
192
+ }), $[5] = t0, $[6] = t2, $[7] = t3) : t3 = $[7], t3;
158
193
  }
159
194
  const DocumentInternationalizationContext = createContext(DEFAULT_CONFIG);
160
195
  function useDocumentInternationalizationContext() {
161
- return useContext(DocumentInternationalizationContext);
196
+ return useContext(DocumentInternationalizationContext);
162
197
  }
163
198
  const promiseCache = /* @__PURE__ */ new Map();
164
199
  function createCacheKey(workspaceId) {
165
- return `languages-${workspaceId}`;
200
+ return `languages-${workspaceId}`;
166
201
  }
167
202
  function createOrGetPromise(fn, cacheKey) {
168
- const cached = promiseCache.get(cacheKey);
169
- if (cached)
170
- return cached;
171
- const promise = fn();
172
- return promiseCache.set(cacheKey, promise), promise;
203
+ let cached = promiseCache.get(cacheKey);
204
+ if (cached) return cached;
205
+ let promise = fn();
206
+ return promiseCache.set(cacheKey, promise), promise;
173
207
  }
208
+ /**
209
+ * This Provider wraps the Studio and provides the DocumentInternationalization context to document actions and components.
210
+ */
174
211
  function DocumentInternationalizationProvider(props) {
175
- const $ = c(18), {
176
- pluginConfig
177
- } = props;
178
- let t0;
179
- $[0] !== pluginConfig.apiVersion ? (t0 = {
180
- apiVersion: pluginConfig.apiVersion
181
- }, $[0] = pluginConfig.apiVersion, $[1] = t0) : t0 = $[1];
182
- const client = useClient(t0), workspaceId = useWorkspace().name ?? "";
183
- let t1;
184
- $[2] !== workspaceId ? (t1 = createCacheKey(workspaceId), $[2] = workspaceId, $[3] = t1) : t1 = $[3];
185
- const cacheKey = t1;
186
- let t2;
187
- bb0: {
188
- if (Array.isArray(pluginConfig.supportedLanguages)) {
189
- t2 = null;
190
- break bb0;
191
- }
192
- let t32;
193
- $[4] !== client || $[5] !== pluginConfig ? (t32 = async () => typeof pluginConfig.supportedLanguages == "function" ? pluginConfig.supportedLanguages(client) : pluginConfig.supportedLanguages, $[4] = client, $[5] = pluginConfig, $[6] = t32) : t32 = $[6];
194
- let t42;
195
- $[7] !== cacheKey || $[8] !== t32 ? (t42 = createOrGetPromise(t32, cacheKey), $[7] = cacheKey, $[8] = t32, $[9] = t42) : t42 = $[9], t2 = t42;
196
- }
197
- const languagesPromise = t2, supportedLanguages = languagesPromise ? use(languagesPromise) : pluginConfig.supportedLanguages;
198
- let t3;
199
- $[10] !== pluginConfig || $[11] !== supportedLanguages ? (t3 = {
200
- ...pluginConfig,
201
- supportedLanguages
202
- }, $[10] = pluginConfig, $[11] = supportedLanguages, $[12] = t3) : t3 = $[12];
203
- const contextValue = t3;
204
- let t4;
205
- $[13] !== props ? (t4 = props.renderDefault(props), $[13] = props, $[14] = t4) : t4 = $[14];
206
- let t5;
207
- return $[15] !== contextValue || $[16] !== t4 ? (t5 = /* @__PURE__ */ jsx(DocumentInternationalizationContext.Provider, { value: contextValue, children: t4 }), $[15] = contextValue, $[16] = t4, $[17] = t5) : t5 = $[17], t5;
212
+ let $ = c(18), { pluginConfig } = props, t0;
213
+ $[0] === pluginConfig.apiVersion ? t0 = $[1] : (t0 = { apiVersion: pluginConfig.apiVersion }, $[0] = pluginConfig.apiVersion, $[1] = t0);
214
+ let client = useClient(t0), workspaceId = useWorkspace().name ?? "", t1;
215
+ $[2] === workspaceId ? t1 = $[3] : (t1 = createCacheKey(workspaceId), $[2] = workspaceId, $[3] = t1);
216
+ let cacheKey = t1, t2;
217
+ bb0: {
218
+ if (Array.isArray(pluginConfig.supportedLanguages)) {
219
+ t2 = null;
220
+ break bb0;
221
+ }
222
+ let t3;
223
+ $[4] !== client || $[5] !== pluginConfig ? (t3 = async () => typeof pluginConfig.supportedLanguages == "function" ? pluginConfig.supportedLanguages(client) : pluginConfig.supportedLanguages, $[4] = client, $[5] = pluginConfig, $[6] = t3) : t3 = $[6];
224
+ let t4;
225
+ $[7] !== cacheKey || $[8] !== t3 ? (t4 = createOrGetPromise(t3, cacheKey), $[7] = cacheKey, $[8] = t3, $[9] = t4) : t4 = $[9], t2 = t4;
226
+ }
227
+ let languagesPromise = t2, supportedLanguages = languagesPromise ? use(languagesPromise) : pluginConfig.supportedLanguages, t3;
228
+ $[10] !== pluginConfig || $[11] !== supportedLanguages ? (t3 = {
229
+ ...pluginConfig,
230
+ supportedLanguages
231
+ }, $[10] = pluginConfig, $[11] = supportedLanguages, $[12] = t3) : t3 = $[12];
232
+ let contextValue = t3, t4;
233
+ $[13] === props ? t4 = $[14] : (t4 = props.renderDefault(props), $[13] = props, $[14] = t4);
234
+ let t5;
235
+ return $[15] !== contextValue || $[16] !== t4 ? (t5 = /* @__PURE__ */ jsx(DocumentInternationalizationContext.Provider, {
236
+ value: contextValue,
237
+ children: t4
238
+ }), $[15] = contextValue, $[16] = t4, $[17] = t5) : t5 = $[17], t5;
208
239
  }
240
+ /**
241
+ * Optional Document action that removes a single translation from the metadata document
242
+ * and optionally deletes the translation document. Opens a confirmation dialog
243
+ * showing which metadata entries reference the document and any other references
244
+ * that may exist. When the document has translation references, those references
245
+ * are unset; otherwise the document is deleted directly.
246
+ *
247
+ * To use it, you need to add it to the document actions config
248
+ * ```
249
+ * const translatedSchemaTypes = ['lesson', 'article'];
250
+ * document: {
251
+ * actions: (prev, {schemaType}) => {
252
+ * if (translatedSchemaTypes.includes(schemaType)) {
253
+ * return [...prev, useDeleteTranslationAction]
254
+ * }
255
+ * return prev
256
+ * },
257
+ * },
258
+ * ```
259
+ */
209
260
  const useDeleteTranslationAction = (props) => {
210
- const $ = c(19), {
211
- id: documentId,
212
- published,
213
- draft
214
- } = props, doc = draft || published, {
215
- languageField
216
- } = useDocumentInternationalizationContext(), [isDialogOpen, setDialogOpen] = useState(!1);
217
- let t0;
218
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
219
- const [translations, setTranslations] = useState(t0);
220
- let t1;
221
- $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setDialogOpen(!1), $[1] = t1) : t1 = $[1];
222
- const onClose = t1, rawDocumentLanguage = doc ? doc[languageField] : null, documentLanguage = typeof rawDocumentLanguage == "string" ? rawDocumentLanguage : null, toast = useToast();
223
- let t2;
224
- $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = {
225
- apiVersion: API_VERSION
226
- }, $[2] = t2) : t2 = $[2];
227
- const client = useClient(t2);
228
- let t3;
229
- $[3] !== client || $[4] !== documentId || $[5] !== documentLanguage || $[6] !== toast || $[7] !== translations ? (t3 = () => {
230
- const tx = client.transaction();
231
- let operation = "DELETE";
232
- documentLanguage && translations.length > 0 ? (operation = "UNSET", translations.forEach((translation) => {
233
- tx.patch(translation._id, (patch) => patch.unset([`${TRANSLATIONS_ARRAY_NAME}[${LANGUAGE_FIELD_NAME} == "${documentLanguage}"]`]));
234
- })) : (tx.delete(documentId), tx.delete(`drafts.${documentId}`)), tx.commit().then(() => {
235
- operation === "DELETE" && onClose(), toast.push({
236
- status: "success",
237
- title: operation === "UNSET" ? "Translation reference unset" : "Document deleted",
238
- description: operation === "UNSET" ? "The document can now be deleted" : null
239
- });
240
- }).catch((err) => {
241
- toast.push({
242
- status: "error",
243
- title: operation === "UNSET" ? "Failed to unset translation reference" : "Failed to delete document",
244
- description: err.message
245
- });
246
- });
247
- }, $[3] = client, $[4] = documentId, $[5] = documentLanguage, $[6] = toast, $[7] = translations, $[8] = t3) : t3 = $[8];
248
- const onProceed = t3, t4 = !doc || !documentLanguage;
249
- let t5;
250
- $[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = () => {
251
- setDialogOpen(!0);
252
- }, $[9] = t5) : t5 = $[9];
253
- let t6;
254
- $[10] !== doc || $[11] !== documentId || $[12] !== isDialogOpen || $[13] !== onProceed || $[14] !== translations ? (t6 = isDialogOpen && {
255
- type: "dialog",
256
- onClose,
257
- header: "Delete translation",
258
- content: doc ? /* @__PURE__ */ jsx(DeleteTranslationDialog, { doc, documentId, setTranslations }) : null,
259
- footer: /* @__PURE__ */ jsx(DeleteTranslationFooter, { onClose, onProceed, translations })
260
- }, $[10] = doc, $[11] = documentId, $[12] = isDialogOpen, $[13] = onProceed, $[14] = translations, $[15] = t6) : t6 = $[15];
261
- let t7;
262
- return $[16] !== t4 || $[17] !== t6 ? (t7 = {
263
- label: "Delete translation...",
264
- disabled: t4,
265
- icon: TrashIcon,
266
- tone: "critical",
267
- onHandle: t5,
268
- dialog: t6
269
- }, $[16] = t4, $[17] = t6, $[18] = t7) : t7 = $[18], t7;
261
+ let $ = c(19), { id: documentId, published, draft } = props, doc = draft || published, { languageField } = useDocumentInternationalizationContext(), [isDialogOpen, setDialogOpen] = useState(!1), t0;
262
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
263
+ let [translations, setTranslations] = useState(t0), t1;
264
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setDialogOpen(!1), $[1] = t1) : t1 = $[1];
265
+ let onClose = t1, rawDocumentLanguage = doc ? doc[languageField] : null, documentLanguage = typeof rawDocumentLanguage == "string" ? rawDocumentLanguage : null, toast = useToast(), t2;
266
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t2 = { apiVersion: API_VERSION }, $[2] = t2) : t2 = $[2];
267
+ let client = useClient(t2), t3;
268
+ $[3] !== client || $[4] !== documentId || $[5] !== documentLanguage || $[6] !== toast || $[7] !== translations ? (t3 = () => {
269
+ let tx = client.transaction(), operation = "DELETE";
270
+ documentLanguage && translations.length > 0 ? (operation = "UNSET", translations.forEach((translation) => {
271
+ tx.patch(translation._id, (patch) => patch.unset([`${TRANSLATIONS_ARRAY_NAME}[${LANGUAGE_FIELD_NAME} == "${documentLanguage}"]`]));
272
+ })) : (tx.delete(documentId), tx.delete(`drafts.${documentId}`)), tx.commit().then(() => {
273
+ operation === "DELETE" && onClose(), toast.push({
274
+ status: "success",
275
+ title: operation === "UNSET" ? "Translation reference unset" : "Document deleted",
276
+ description: operation === "UNSET" ? "The document can now be deleted" : null
277
+ });
278
+ }).catch((err) => {
279
+ toast.push({
280
+ status: "error",
281
+ title: operation === "UNSET" ? "Failed to unset translation reference" : "Failed to delete document",
282
+ description: err.message
283
+ });
284
+ });
285
+ }, $[3] = client, $[4] = documentId, $[5] = documentLanguage, $[6] = toast, $[7] = translations, $[8] = t3) : t3 = $[8];
286
+ let onProceed = t3, t4 = !doc || !documentLanguage, t5;
287
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t5 = () => {
288
+ setDialogOpen(!0);
289
+ }, $[9] = t5) : t5 = $[9];
290
+ let t6;
291
+ $[10] !== doc || $[11] !== documentId || $[12] !== isDialogOpen || $[13] !== onProceed || $[14] !== translations ? (t6 = isDialogOpen && {
292
+ type: "dialog",
293
+ onClose,
294
+ header: "Delete translation",
295
+ content: doc ? /* @__PURE__ */ jsx(DeleteTranslationDialog, {
296
+ doc,
297
+ documentId,
298
+ setTranslations
299
+ }) : null,
300
+ footer: /* @__PURE__ */ jsx(DeleteTranslationFooter, {
301
+ onClose,
302
+ onProceed,
303
+ translations
304
+ })
305
+ }, $[10] = doc, $[11] = documentId, $[12] = isDialogOpen, $[13] = onProceed, $[14] = translations, $[15] = t6) : t6 = $[15];
306
+ let t7;
307
+ return $[16] !== t4 || $[17] !== t6 ? (t7 = {
308
+ label: "Delete translation...",
309
+ disabled: t4,
310
+ icon: TrashIcon,
311
+ tone: "critical",
312
+ onHandle: t5,
313
+ dialog: t6
314
+ }, $[16] = t4, $[17] = t6, $[18] = t7) : t7 = $[18], t7;
270
315
  };
271
- useDeleteTranslationAction.action = "deleteTranslation";
272
- useDeleteTranslationAction.displayName = "DeleteTranslationAction";
273
- const DeleteTranslationAction = (props) => useDeleteTranslationAction(props), query = `*[_type == $translationSchema && $id in translations[].value._ref]{
274
- _id,
275
- _createdAt,
276
- translations
277
- }`;
316
+ useDeleteTranslationAction.action = "deleteTranslation", useDeleteTranslationAction.displayName = "DeleteTranslationAction";
317
+ /**
318
+ * @deprecated use useDeleteTranslationAction instead
319
+ * Will be removed in the next major version
320
+ */
321
+ const DeleteTranslationAction = (props) => useDeleteTranslationAction(props);
278
322
  function useTranslationMetadata(id) {
279
- const $ = c(6);
280
- let t0;
281
- $[0] !== id ? (t0 = {
282
- params: {
283
- id,
284
- translationSchema: METADATA_SCHEMA_NAME
285
- }
286
- }, $[0] = id, $[1] = t0) : t0 = $[1];
287
- const {
288
- data,
289
- loading,
290
- error
291
- } = useListeningQuery(query, t0);
292
- let t1;
293
- return $[2] !== data || $[3] !== error || $[4] !== loading ? (t1 = {
294
- data,
295
- loading,
296
- error
297
- }, $[2] = data, $[3] = error, $[4] = loading, $[5] = t1) : t1 = $[5], t1;
323
+ let $ = c(6), t0;
324
+ $[0] === id ? t0 = $[1] : (t0 = { params: {
325
+ id,
326
+ translationSchema: METADATA_SCHEMA_NAME
327
+ } }, $[0] = id, $[1] = t0);
328
+ let { data, loading, error } = useListeningQuery("*[_type == $translationSchema && $id in translations[].value._ref]{\n _id,\n _createdAt,\n translations\n}", t0), t1;
329
+ return $[2] !== data || $[3] !== error || $[4] !== loading ? (t1 = {
330
+ data,
331
+ loading,
332
+ error
333
+ }, $[2] = data, $[3] = error, $[4] = loading, $[5] = t1) : t1 = $[5], t1;
298
334
  }
335
+ /**
336
+ * The locale namespace for the document internationalization plugin.
337
+ *
338
+ * @public
339
+ */
299
340
  const documenti18nLocaleNamespace = "document-internationalization", documentInternationalizationUsEnglishLocaleBundle = defineLocaleResourceBundle({
300
- locale: "en-US",
301
- namespace: documenti18nLocaleNamespace,
302
- resources: () => import("./_chunks-es/resources.js")
341
+ locale: "en-US",
342
+ namespace: documenti18nLocaleNamespace,
343
+ resources: () => import("./resources.js")
303
344
  }), DISABLED_REASON_KEY = {
304
- METADATA_NOT_FOUND: "action.duplicate.disabled.missing-metadata",
305
- MULTIPLE_METADATA: "action.duplicate.disabled.multiple-metadata",
306
- NOTHING_TO_DUPLICATE: "action.duplicate.disabled.nothing-to-duplicate",
307
- NOT_READY: "action.duplicate.disabled.not-ready"
345
+ METADATA_NOT_FOUND: "action.duplicate.disabled.missing-metadata",
346
+ MULTIPLE_METADATA: "action.duplicate.disabled.multiple-metadata",
347
+ NOTHING_TO_DUPLICATE: "action.duplicate.disabled.nothing-to-duplicate",
348
+ NOT_READY: "action.duplicate.disabled.not-ready"
308
349
  }, useDuplicateWithTranslationsAction = (t0) => {
309
- const $ = c(44), {
310
- id,
311
- type,
312
- onComplete
313
- } = t0, documentStore = useDocumentStore(), {
314
- duplicate
315
- } = useDocumentOperation(id, type), {
316
- navigateIntent
317
- } = useRouter(), [isDuplicating, setDuplicating] = useState(!1);
318
- let t1;
319
- $[0] !== id || $[1] !== type ? (t1 = {
320
- id,
321
- type,
322
- permission: "duplicate"
323
- }, $[0] = id, $[1] = type, $[2] = t1) : t1 = $[2];
324
- const [permissions, isPermissionsLoading] = useDocumentPairPermissions(t1), {
325
- data,
326
- loading: isMetadataDocumentLoading
327
- } = 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(), {
328
- t: s
329
- } = useTranslation(structureLocaleNamespace), {
330
- t: d
331
- } = useTranslation(documenti18nLocaleNamespace), currentUser = useCurrentUser();
332
- let t2;
333
- $[3] !== client || $[4] !== documentStore.pair || $[5] !== metadataDocument || $[6] !== navigateIntent || $[7] !== onComplete || $[8] !== toast || $[9] !== type ? (t2 = () => {
334
- setDuplicating(!0), (async function() {
335
- if (!metadataDocument)
336
- return Promise.reject(new Error("Metadata document not found"));
337
- const translationsArray = metadataDocument[TRANSLATIONS_ARRAY_NAME];
338
- if (!translationsArray || translationsArray.length === 0)
339
- return Promise.reject(new Error("No translations found in metadata document"));
340
- const translations = /* @__PURE__ */ new Map();
341
- await Promise.all(translationsArray.map(async (translation) => {
342
- const dupeId = uuid(), locale = translation[LANGUAGE_FIELD_NAME], docId = translation.value?._ref;
343
- if (typeof locale != "string" || locale.trim().length === 0)
344
- return Promise.reject(new Error("Invalid locale for translation"));
345
- if (!docId)
346
- return Promise.reject(new Error("Translation document not found"));
347
- const {
348
- duplicate: duplicateTranslation
349
- } = await firstValueFrom(documentStore.pair.editOperations(docId, type).pipe(filter(_temp$4)));
350
- if (duplicateTranslation.disabled)
351
- return Promise.reject(new Error("Cannot duplicate document"));
352
- const duplicateTranslationSuccess = firstValueFrom(documentStore.pair.operationEvents(docId, type).pipe(filter(_temp2$2)));
353
- duplicateTranslation.execute(dupeId), await duplicateTranslationSuccess, translations.set(locale, dupeId);
354
- }));
355
- const {
356
- duplicate: duplicateMetadata
357
- } = await firstValueFrom(documentStore.pair.editOperations(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter(_temp3)));
358
- if (duplicateMetadata.disabled)
359
- return Promise.reject(new Error("Cannot duplicate document"));
360
- const duplicateMetadataSuccess = firstValueFrom(documentStore.pair.operationEvents(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter(_temp4))), dupeId_0 = uuid();
361
- duplicateMetadata.execute(dupeId_0), await duplicateMetadataSuccess;
362
- const patch = {
363
- set: Object.fromEntries(Array.from(translations.entries()).map(_temp5))
364
- };
365
- await client.transaction().patch(dupeId_0, patch).commit(), navigateIntent("edit", {
366
- id: Array.from(translations.values()).at(0),
367
- type
368
- }), onComplete();
369
- })().catch((error) => {
370
- console.error(error), toast.push({
371
- status: "error",
372
- title: "Error duplicating document",
373
- description: error instanceof Error ? error.message : "Failed to duplicate document"
374
- });
375
- }).finally(() => {
376
- setDuplicating(!1);
377
- });
378
- }, $[3] = client, $[4] = documentStore.pair, $[5] = metadataDocument, $[6] = navigateIntent, $[7] = onComplete, $[8] = toast, $[9] = type, $[10] = t2) : t2 = $[10];
379
- const handle = t2;
380
- permissions?.granted;
381
- let t3;
382
- bb0: {
383
- if (!isPermissionsLoading && !permissions?.granted) {
384
- let t42;
385
- $[11] !== d ? (t42 = d("action.duplicate.label"), $[11] = d, $[12] = t42) : t42 = $[12];
386
- let t52;
387
- $[13] !== currentUser ? (t52 = /* @__PURE__ */ jsx(InsufficientPermissionsMessage, { context: "duplicate-document", currentUser }), $[13] = currentUser, $[14] = t52) : t52 = $[14];
388
- let t62;
389
- $[15] !== t42 || $[16] !== t52 ? (t62 = {
390
- icon: CopyIcon,
391
- disabled: !0,
392
- label: t42,
393
- title: t52
394
- }, $[15] = t42, $[16] = t52, $[17] = t62) : t62 = $[17], t3 = t62;
395
- break bb0;
396
- }
397
- if (!isMetadataDocumentLoading && !metadataDocument) {
398
- let t42;
399
- $[18] !== d ? (t42 = d("action.duplicate.label"), $[18] = d, $[19] = t42) : t42 = $[19];
400
- let t52;
401
- $[20] !== d ? (t52 = d(DISABLED_REASON_KEY.METADATA_NOT_FOUND), $[20] = d, $[21] = t52) : t52 = $[21];
402
- let t62;
403
- $[22] !== t42 || $[23] !== t52 ? (t62 = {
404
- icon: CopyIcon,
405
- disabled: !0,
406
- label: t42,
407
- title: t52
408
- }, $[22] = t42, $[23] = t52, $[24] = t62) : t62 = $[24], t3 = t62;
409
- break bb0;
410
- }
411
- if (!hasOneMetadataDocument) {
412
- let t42;
413
- $[25] !== d ? (t42 = d("action.duplicate.label"), $[25] = d, $[26] = t42) : t42 = $[26];
414
- let t52;
415
- $[27] !== d ? (t52 = d(DISABLED_REASON_KEY.MULTIPLE_METADATA), $[27] = d, $[28] = t52) : t52 = $[28];
416
- let t62;
417
- $[29] !== t42 || $[30] !== t52 ? (t62 = {
418
- icon: CopyIcon,
419
- disabled: !0,
420
- label: t42,
421
- title: t52
422
- }, $[29] = t42, $[30] = t52, $[31] = t62) : t62 = $[31], t3 = t62;
423
- break bb0;
424
- }
425
- const t4 = isDuplicating || !!duplicate.disabled || isPermissionsLoading || isMetadataDocumentLoading;
426
- let t5;
427
- $[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];
428
- let t6;
429
- $[36] !== duplicate.disabled || $[37] !== s ? (t6 = duplicate.disabled ? s(DISABLED_REASON_KEY[duplicate.disabled]) : "", $[36] = duplicate.disabled, $[37] = s, $[38] = t6) : t6 = $[38];
430
- let t7;
431
- $[39] !== handle || $[40] !== t4 || $[41] !== t5 || $[42] !== t6 ? (t7 = {
432
- icon: CopyIcon,
433
- disabled: t4,
434
- label: t5,
435
- title: t6,
436
- onHandle: handle
437
- }, $[39] = handle, $[40] = t4, $[41] = t5, $[42] = t6, $[43] = t7) : t7 = $[43], t3 = t7;
438
- }
439
- return t3;
350
+ let $ = c(44), { id, type, onComplete } = t0, documentStore = useDocumentStore(), { duplicate } = useDocumentOperation(id, type), { navigateIntent } = useRouter(), [isDuplicating, setDuplicating] = useState(!1), t1;
351
+ $[0] !== id || $[1] !== type ? (t1 = {
352
+ id,
353
+ type,
354
+ permission: "duplicate"
355
+ }, $[0] = id, $[1] = type, $[2] = t1) : t1 = $[2];
356
+ let [permissions, isPermissionsLoading] = useDocumentPairPermissions(t1), { data, loading: isMetadataDocumentLoading } = 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(), { t: s } = useTranslation(structureLocaleNamespace), { t: d } = useTranslation(documenti18nLocaleNamespace), currentUser = useCurrentUser(), t2;
357
+ $[3] !== client || $[4] !== documentStore.pair || $[5] !== metadataDocument || $[6] !== navigateIntent || $[7] !== onComplete || $[8] !== toast || $[9] !== type ? (t2 = () => {
358
+ setDuplicating(!0), (async function() {
359
+ if (!metadataDocument) return Promise.reject(/* @__PURE__ */ Error("Metadata document not found"));
360
+ let translationsArray = metadataDocument[TRANSLATIONS_ARRAY_NAME];
361
+ if (!translationsArray || translationsArray.length === 0) return Promise.reject(/* @__PURE__ */ Error("No translations found in metadata document"));
362
+ let translations = /* @__PURE__ */ new Map();
363
+ await Promise.all(translationsArray.map(async (translation) => {
364
+ let dupeId = uuid(), locale = translation[LANGUAGE_FIELD_NAME], docId = translation.value?._ref;
365
+ if (typeof locale != "string" || locale.trim().length === 0) return Promise.reject(/* @__PURE__ */ Error("Invalid locale for translation"));
366
+ if (!docId) return Promise.reject(/* @__PURE__ */ Error("Translation document not found"));
367
+ let { duplicate: duplicateTranslation } = await firstValueFrom(documentStore.pair.editOperations(docId, type).pipe(filter(_temp$4)));
368
+ if (duplicateTranslation.disabled) return Promise.reject(/* @__PURE__ */ Error("Cannot duplicate document"));
369
+ let duplicateTranslationSuccess = firstValueFrom(documentStore.pair.operationEvents(docId, type).pipe(filter(_temp2$2)));
370
+ duplicateTranslation.execute(dupeId), await duplicateTranslationSuccess, translations.set(locale, dupeId);
371
+ }));
372
+ let { duplicate: duplicateMetadata } = await firstValueFrom(documentStore.pair.editOperations(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter(_temp3)));
373
+ if (duplicateMetadata.disabled) return Promise.reject(/* @__PURE__ */ Error("Cannot duplicate document"));
374
+ let duplicateMetadataSuccess = firstValueFrom(documentStore.pair.operationEvents(metadataDocument._id, METADATA_SCHEMA_NAME).pipe(filter(_temp4))), dupeId_0 = uuid();
375
+ duplicateMetadata.execute(dupeId_0), await duplicateMetadataSuccess;
376
+ let patch = { set: Object.fromEntries(Array.from(translations.entries()).map(_temp5)) };
377
+ await client.transaction().patch(dupeId_0, patch).commit(), navigateIntent("edit", {
378
+ id: Array.from(translations.values()).at(0),
379
+ type
380
+ }), onComplete();
381
+ })().catch((error) => {
382
+ console.error(error), toast.push({
383
+ status: "error",
384
+ title: "Error duplicating document",
385
+ description: error instanceof Error ? error.message : "Failed to duplicate document"
386
+ });
387
+ }).finally(() => {
388
+ setDuplicating(!1);
389
+ });
390
+ }, $[3] = client, $[4] = documentStore.pair, $[5] = metadataDocument, $[6] = navigateIntent, $[7] = onComplete, $[8] = toast, $[9] = type, $[10] = t2) : t2 = $[10];
391
+ let handle = t2;
392
+ permissions?.granted;
393
+ let t3;
394
+ bb0: {
395
+ if (!isPermissionsLoading && !permissions?.granted) {
396
+ let t4;
397
+ $[11] === d ? t4 = $[12] : (t4 = d("action.duplicate.label"), $[11] = d, $[12] = t4);
398
+ let t5;
399
+ $[13] === currentUser ? t5 = $[14] : (t5 = /* @__PURE__ */ jsx(InsufficientPermissionsMessage, {
400
+ context: "duplicate-document",
401
+ currentUser
402
+ }), $[13] = currentUser, $[14] = t5);
403
+ let t6;
404
+ $[15] !== t4 || $[16] !== t5 ? (t6 = {
405
+ icon: CopyIcon,
406
+ disabled: !0,
407
+ label: t4,
408
+ title: t5
409
+ }, $[15] = t4, $[16] = t5, $[17] = t6) : t6 = $[17], t3 = t6;
410
+ break bb0;
411
+ }
412
+ if (!isMetadataDocumentLoading && !metadataDocument) {
413
+ let t4;
414
+ $[18] === d ? t4 = $[19] : (t4 = d("action.duplicate.label"), $[18] = d, $[19] = t4);
415
+ let t5;
416
+ $[20] === d ? t5 = $[21] : (t5 = d(DISABLED_REASON_KEY.METADATA_NOT_FOUND), $[20] = d, $[21] = t5);
417
+ let t6;
418
+ $[22] !== t4 || $[23] !== t5 ? (t6 = {
419
+ icon: CopyIcon,
420
+ disabled: !0,
421
+ label: t4,
422
+ title: t5
423
+ }, $[22] = t4, $[23] = t5, $[24] = t6) : t6 = $[24], t3 = t6;
424
+ break bb0;
425
+ }
426
+ if (!hasOneMetadataDocument) {
427
+ let t4;
428
+ $[25] === d ? t4 = $[26] : (t4 = d("action.duplicate.label"), $[25] = d, $[26] = t4);
429
+ let t5;
430
+ $[27] === d ? t5 = $[28] : (t5 = d(DISABLED_REASON_KEY.MULTIPLE_METADATA), $[27] = d, $[28] = t5);
431
+ let t6;
432
+ $[29] !== t4 || $[30] !== t5 ? (t6 = {
433
+ icon: CopyIcon,
434
+ disabled: !0,
435
+ label: t4,
436
+ title: t5
437
+ }, $[29] = t4, $[30] = t5, $[31] = t6) : t6 = $[31], t3 = t6;
438
+ break bb0;
439
+ }
440
+ let t4 = isDuplicating || !!duplicate.disabled || isPermissionsLoading || isMetadataDocumentLoading, t5;
441
+ $[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];
442
+ let t6;
443
+ $[36] !== duplicate.disabled || $[37] !== s ? (t6 = duplicate.disabled ? s(DISABLED_REASON_KEY[duplicate.disabled]) : "", $[36] = duplicate.disabled, $[37] = s, $[38] = t6) : t6 = $[38];
444
+ let t7;
445
+ $[39] !== handle || $[40] !== t4 || $[41] !== t5 || $[42] !== t6 ? (t7 = {
446
+ icon: CopyIcon,
447
+ disabled: t4,
448
+ label: t5,
449
+ title: t6,
450
+ onHandle: handle
451
+ }, $[39] = handle, $[40] = t4, $[41] = t5, $[42] = t6, $[43] = t7) : t7 = $[43], t3 = t7;
452
+ }
453
+ return t3;
440
454
  };
441
- useDuplicateWithTranslationsAction.action = "duplicate";
442
- useDuplicateWithTranslationsAction.displayName = "DuplicateWithTranslationsAction";
455
+ useDuplicateWithTranslationsAction.action = "duplicate", useDuplicateWithTranslationsAction.displayName = "DuplicateWithTranslationsAction";
456
+ /**
457
+ * @deprecated use useDuplicateWithTranslationsAction instead
458
+ * Will be removed in the next major version
459
+ */
443
460
  const DuplicateWithTranslationsAction = (props) => useDuplicateWithTranslationsAction(props);
444
- DuplicateWithTranslationsAction.action = "duplicate";
445
- DuplicateWithTranslationsAction.displayName = "DuplicateWithTranslationsAction";
461
+ DuplicateWithTranslationsAction.action = "duplicate", DuplicateWithTranslationsAction.displayName = "DuplicateWithTranslationsAction";
446
462
  function _temp$4(op) {
447
- return op.duplicate.disabled !== "NOT_READY";
463
+ return op.duplicate.disabled !== "NOT_READY";
448
464
  }
449
465
  function _temp2$2(e) {
450
- return e.op === "duplicate" && e.type === "success";
466
+ return e.op === "duplicate" && e.type === "success";
451
467
  }
452
468
  function _temp3(op_0) {
453
- return op_0.duplicate.disabled !== "NOT_READY";
469
+ return op_0.duplicate.disabled !== "NOT_READY";
454
470
  }
455
471
  function _temp4(e_0) {
456
- return e_0.op === "duplicate" && e_0.type === "success";
472
+ return e_0.op === "duplicate" && e_0.type === "success";
457
473
  }
458
474
  function _temp5(t0) {
459
- const [locale_0, documentId] = t0;
460
- return [`${TRANSLATIONS_ARRAY_NAME}[${LANGUAGE_FIELD_NAME} == "${locale_0}"].value._ref`, documentId];
475
+ let [locale_0, documentId] = t0;
476
+ return [`${TRANSLATIONS_ARRAY_NAME}[${LANGUAGE_FIELD_NAME} == "${locale_0}"].value._ref`, documentId];
461
477
  }
462
478
  function useOpenInNewPane(id, type) {
463
- const $ = c(6), router = useRouter(), {
464
- routerPanesState,
465
- groupIndex
466
- } = usePaneRouter();
467
- let t0;
468
- return $[0] !== groupIndex || $[1] !== id || $[2] !== router || $[3] !== routerPanesState || $[4] !== type ? (t0 = () => {
469
- if (!id || !type)
470
- return;
471
- if (!routerPanesState.length) {
472
- router.navigateIntent("edit", {
473
- id,
474
- type
475
- });
476
- return;
477
- }
478
- const panes = [...routerPanesState];
479
- panes.splice(groupIndex + 1, 0, [{
480
- id,
481
- params: {
482
- type
483
- }
484
- }]);
485
- const href = router.resolvePathFromState({
486
- panes
487
- });
488
- router.navigateUrl({
489
- path: href
490
- });
491
- }, $[0] = groupIndex, $[1] = id, $[2] = router, $[3] = routerPanesState, $[4] = type, $[5] = t0) : t0 = $[5], t0;
479
+ let $ = c(6), router = useRouter(), { routerPanesState, groupIndex } = usePaneRouter(), t0;
480
+ return $[0] !== groupIndex || $[1] !== id || $[2] !== router || $[3] !== routerPanesState || $[4] !== type ? (t0 = () => {
481
+ if (!id || !type) return;
482
+ if (!routerPanesState.length) {
483
+ router.navigateIntent("edit", {
484
+ id,
485
+ type
486
+ });
487
+ return;
488
+ }
489
+ let panes = [...routerPanesState];
490
+ panes.splice(groupIndex + 1, 0, [{
491
+ id,
492
+ params: { type }
493
+ }]);
494
+ let href = router.resolvePathFromState({ panes });
495
+ router.navigateUrl({ path: href });
496
+ }, $[0] = groupIndex, $[1] = id, $[2] = router, $[3] = routerPanesState, $[4] = type, $[5] = t0) : t0 = $[5], t0;
492
497
  }
498
+ /**
499
+ * Creates a translation reference object used in metadata documents to link
500
+ * a language key to a document. References are created as weak by default,
501
+ * with optional strengthen-on-publish metadata so the reference becomes
502
+ * strong once the referenced document is published.
503
+ */
493
504
  function createReference(language, ref, type, strengthenOnPublish = !0) {
494
- return {
495
- [LANGUAGE_FIELD_NAME]: language,
496
- _key: randomKey(),
497
- _type: "internationalizedArrayReferenceValue",
498
- value: {
499
- _type: "reference",
500
- _ref: ref,
501
- _weak: !0,
502
- // If the user has configured weakReferences, we won't want to strengthen them
503
- ...strengthenOnPublish ? {
504
- _strengthenOnPublish: {
505
- type
506
- }
507
- } : {}
508
- }
509
- };
505
+ return {
506
+ [LANGUAGE_FIELD_NAME]: language,
507
+ _key: randomKey(),
508
+ _type: "internationalizedArrayReferenceValue",
509
+ value: {
510
+ _type: "reference",
511
+ _ref: ref,
512
+ _weak: !0,
513
+ ...strengthenOnPublish ? { _strengthenOnPublish: { type } } : {}
514
+ }
515
+ };
510
516
  }
517
+ /**
518
+ * Button component for opening or creating the translation metadata document.
519
+ * When metadata already exists, clicking opens it in a new pane. When no
520
+ * metadata exists and creation is allowed, clicking creates a new metadata
521
+ * document with the source language reference and then opens it.
522
+ */
511
523
  function LanguageManage(props) {
512
- const $ = c(21), {
513
- id,
514
- metadataId,
515
- schemaType,
516
- documentId,
517
- sourceLanguageId
518
- } = props, open = useOpenInNewPane(id, METADATA_SCHEMA_NAME), openCreated = useOpenInNewPane(metadataId, METADATA_SCHEMA_NAME), {
519
- allowCreateMetaDoc,
520
- apiVersion,
521
- weakReferences
522
- } = useDocumentInternationalizationContext();
523
- let t0;
524
- $[0] !== apiVersion ? (t0 = {
525
- apiVersion
526
- }, $[0] = apiVersion, $[1] = t0) : t0 = $[1];
527
- const client = useClient(t0), [userHasClicked, setUserHasClicked] = useState(!1), canCreate = !id && !!metadataId && allowCreateMetaDoc;
528
- let t1;
529
- $[2] !== client || $[3] !== documentId || $[4] !== id || $[5] !== metadataId || $[6] !== open || $[7] !== openCreated || $[8] !== schemaType.name || $[9] !== sourceLanguageId || $[10] !== weakReferences ? (t1 = () => {
530
- if (!id && metadataId && sourceLanguageId) {
531
- setUserHasClicked(!0);
532
- const transaction = client.transaction(), sourceReference = createReference(sourceLanguageId, documentId, schemaType.name, !weakReferences), newMetadataDocument = {
533
- _id: metadataId,
534
- _type: METADATA_SCHEMA_NAME,
535
- schemaTypes: [schemaType.name],
536
- translations: [sourceReference]
537
- };
538
- transaction.createIfNotExists(newMetadataDocument), transaction.commit().then(() => {
539
- setUserHasClicked(!1), openCreated();
540
- }).catch((err) => {
541
- console.error(err), setUserHasClicked(!1);
542
- });
543
- } else
544
- open();
545
- }, $[2] = client, $[3] = documentId, $[4] = id, $[5] = metadataId, $[6] = open, $[7] = openCreated, $[8] = schemaType.name, $[9] = sourceLanguageId, $[10] = weakReferences, $[11] = t1) : t1 = $[11];
546
- const handleClick = t1, disabled = !id && !canCreate || canCreate && !sourceLanguageId || userHasClicked;
547
- let t2, t3;
548
- $[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]);
549
- const t4 = !!id || canCreate;
550
- let t5;
551
- $[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];
552
- let t6;
553
- 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;
524
+ let $ = c(21), { id, metadataId, schemaType, documentId, sourceLanguageId } = props, open = useOpenInNewPane(id, METADATA_SCHEMA_NAME), openCreated = useOpenInNewPane(metadataId, METADATA_SCHEMA_NAME), { allowCreateMetaDoc, apiVersion, weakReferences } = useDocumentInternationalizationContext(), t0;
525
+ $[0] === apiVersion ? t0 = $[1] : (t0 = { apiVersion }, $[0] = apiVersion, $[1] = t0);
526
+ let client = useClient(t0), [userHasClicked, setUserHasClicked] = useState(!1), canCreate = !id && !!metadataId && allowCreateMetaDoc, t1;
527
+ $[2] !== client || $[3] !== documentId || $[4] !== id || $[5] !== metadataId || $[6] !== open || $[7] !== openCreated || $[8] !== schemaType.name || $[9] !== sourceLanguageId || $[10] !== weakReferences ? (t1 = () => {
528
+ if (!id && metadataId && sourceLanguageId) {
529
+ setUserHasClicked(!0);
530
+ let transaction = client.transaction(), sourceReference = createReference(sourceLanguageId, documentId, schemaType.name, !weakReferences), newMetadataDocument = {
531
+ _id: metadataId,
532
+ _type: METADATA_SCHEMA_NAME,
533
+ schemaTypes: [schemaType.name],
534
+ translations: [sourceReference]
535
+ };
536
+ transaction.createIfNotExists(newMetadataDocument), transaction.commit().then(() => {
537
+ setUserHasClicked(!1), openCreated();
538
+ }).catch((err) => {
539
+ console.error(err), setUserHasClicked(!1);
540
+ });
541
+ } else open();
542
+ }, $[2] = client, $[3] = documentId, $[4] = id, $[5] = metadataId, $[6] = open, $[7] = openCreated, $[8] = schemaType.name, $[9] = sourceLanguageId, $[10] = weakReferences, $[11] = t1) : t1 = $[11];
543
+ let handleClick = t1, disabled = !id && !canCreate || canCreate && !sourceLanguageId || userHasClicked, t2, t3;
544
+ $[12] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Box, {
545
+ padding: 2,
546
+ children: /* @__PURE__ */ jsx(Text, {
547
+ muted: !0,
548
+ size: 1,
549
+ children: "Document has no other translations"
550
+ })
551
+ }), t3 = ["right", "left"], $[12] = t2, $[13] = t3) : (t2 = $[12], t3 = $[13]);
552
+ let t4 = !!id || canCreate, t5;
553
+ $[14] !== disabled || $[15] !== handleClick || $[16] !== userHasClicked ? (t5 = /* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(Button, {
554
+ disabled,
555
+ mode: "ghost",
556
+ text: "Manage Translations",
557
+ icon: CogIcon,
558
+ loading: userHasClicked,
559
+ onClick: handleClick
560
+ }) }), $[14] = disabled, $[15] = handleClick, $[16] = userHasClicked, $[17] = t5) : t5 = $[17];
561
+ let t6;
562
+ return $[18] !== t4 || $[19] !== t5 ? (t6 = /* @__PURE__ */ jsx(Tooltip, {
563
+ animate: !0,
564
+ content: t2,
565
+ fallbackPlacements: t3,
566
+ placement: "top",
567
+ portal: !0,
568
+ disabled: t4,
569
+ children: t5
570
+ }), $[18] = t4, $[19] = t5, $[20] = t6) : t6 = $[20], t6;
554
571
  }
572
+ /**
573
+ * Removes fields from a document that are marked with the
574
+ * `documentInternationalization.exclude` schema option. This is used when
575
+ * duplicating a source document to create a translation, so that
576
+ * language-specific or non-translatable fields are stripped from the copy.
577
+ * Returns the document with excluded paths unset, or `null` if the input is null.
578
+ */
555
579
  function removeExcludedPaths(doc, schemaType) {
556
- if (!isDocumentSchemaType(schemaType) || !doc)
557
- return doc;
558
- const pathsToExclude = extractPaths(doc, schemaType, []).filter((field) => field.schemaType?.options?.documentInternationalization?.exclude === !0).map((field) => pathToString(field.path));
559
- return new Mutation({
560
- mutations: [{
561
- patch: {
562
- id: doc._id,
563
- unset: pathsToExclude
564
- }
565
- }]
566
- }).apply(doc);
580
+ if (!isDocumentSchemaType(schemaType) || !doc) return doc;
581
+ let pathsToExclude = extractPaths(doc, schemaType, []).filter((field) => field.schemaType?.options?.documentInternationalization?.exclude === !0).map((field) => pathToString(field.path));
582
+ return new Mutation({ mutations: [{ patch: {
583
+ id: doc._id,
584
+ unset: pathsToExclude
585
+ } }] }).apply(doc);
567
586
  }
568
587
  function extractPaths(doc, schemaType, path) {
569
- const result = [];
570
- for (const field of schemaType.fields) {
571
- const fieldPath = [...path, field.name], fieldSchema = field.type, {
572
- value
573
- } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
574
- if (value == null)
575
- continue;
576
- const thisFieldWithPath = {
577
- path: fieldPath,
578
- name: field.name,
579
- schemaType: fieldSchema,
580
- value
581
- };
582
- if (fieldSchema.jsonType === "object") {
583
- const innerFields = extractPaths(doc, fieldSchema, fieldPath);
584
- result.push(thisFieldWithPath, ...innerFields);
585
- } else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some((item) => "fields" in item)) {
586
- const {
587
- value: arrayValue
588
- } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
589
- if (result.push(thisFieldWithPath), arrayValue?.length)
590
- for (const item of arrayValue) {
591
- if (!item._key) continue;
592
- const itemPath = [...fieldPath, {
593
- _key: item._key
594
- }];
595
- let itemSchema = fieldSchema.of.find((t) => t.name === item._type);
596
- if (item._type || (itemSchema = fieldSchema.of[0]), itemSchema) {
597
- const innerFields = extractPaths(doc, itemSchema, itemPath), arrayMember = {
598
- path: itemPath,
599
- name: item._key,
600
- schemaType: itemSchema,
601
- value: item
602
- };
603
- result.push(arrayMember, ...innerFields);
604
- }
605
- }
606
- } else
607
- result.push(thisFieldWithPath);
608
- }
609
- return result;
588
+ let result = [];
589
+ for (let field of schemaType.fields) {
590
+ let fieldPath = [...path, field.name], fieldSchema = field.type, { value } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
591
+ if (value == null) continue;
592
+ let thisFieldWithPath = {
593
+ path: fieldPath,
594
+ name: field.name,
595
+ schemaType: fieldSchema,
596
+ value
597
+ };
598
+ if (fieldSchema.jsonType === "object") {
599
+ let innerFields = extractPaths(doc, fieldSchema, fieldPath);
600
+ result.push(thisFieldWithPath, ...innerFields);
601
+ } else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some((item) => "fields" in item)) {
602
+ let { value: arrayValue } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
603
+ if (result.push(thisFieldWithPath), arrayValue?.length) for (let item of arrayValue) {
604
+ if (!item._key) continue;
605
+ let itemPath = [...fieldPath, { _key: item._key }], itemSchema = fieldSchema.of.find((t) => t.name === item._type);
606
+ if (item._type || (itemSchema = fieldSchema.of[0]), itemSchema) {
607
+ let innerFields = extractPaths(doc, itemSchema, itemPath), arrayMember = {
608
+ path: itemPath,
609
+ name: item._key,
610
+ schemaType: itemSchema,
611
+ value: item
612
+ };
613
+ result.push(arrayMember, ...innerFields);
614
+ }
615
+ }
616
+ } else result.push(thisFieldWithPath);
617
+ }
618
+ return result;
610
619
  }
620
+ /**
621
+ * Button component representing a single language in the translations menu.
622
+ * Displays the language name, an ID badge, and a contextual icon: checkmark
623
+ * for the current language, split-vertical for existing translations, or add
624
+ * for new translations. Clicking opens an existing translation in a new pane,
625
+ * or creates a new translation document via a Sanity transaction.
626
+ */
611
627
  function LanguageOption(props) {
612
- const $ = c(45), {
613
- language,
614
- schemaType,
615
- documentId,
616
- current,
617
- source,
618
- sourceLanguageId,
619
- metadata: metadata2,
620
- metadataId
621
- } = props, [userHasClicked, setUserHasClicked] = useState(!1), disabled = props.disabled || userHasClicked || current || !source || !sourceLanguageId || !metadataId;
622
- let t0;
623
- $[0] !== language.id || $[1] !== metadata2 ? (t0 = metadata2?.translations.length ? metadata2.translations.find((t) => t[LANGUAGE_FIELD_NAME] === language.id) : void 0, $[0] = language.id, $[1] = metadata2, $[2] = t0) : t0 = $[2];
624
- const translation = t0, {
625
- apiVersion,
626
- languageField,
627
- weakReferences,
628
- callback
629
- } = useDocumentInternationalizationContext();
630
- let t1;
631
- $[3] !== apiVersion ? (t1 = {
632
- apiVersion
633
- }, $[3] = apiVersion, $[4] = t1) : t1 = $[4];
634
- const client = useClient(t1), toast = useToast(), open = useOpenInNewPane(translation?.value?._ref, schemaType.name);
635
- let t2;
636
- $[5] !== open ? (t2 = () => open(), $[5] = open, $[6] = t2) : t2 = $[6];
637
- const handleOpen = t2;
638
- let t3;
639
- $[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 () => {
640
- if (!source)
641
- throw new Error("Cannot create translation without source document");
642
- if (!sourceLanguageId)
643
- throw new Error("Cannot create translation without source language ID");
644
- if (!metadataId)
645
- throw new Error("Cannot create translation without a metadata ID");
646
- setUserHasClicked(!0);
647
- const transaction = client.transaction(), newTranslationDocumentId = uuid(), sourceReleaseId = isVersionId(source._id) ? getVersionFromId(source._id) : void 0;
648
- let newTranslationDocument = {
649
- ...source,
650
- _id: sourceReleaseId ? getVersionId(newTranslationDocumentId, sourceReleaseId) : getDraftId(newTranslationDocumentId),
651
- [languageField]: language.id
652
- };
653
- newTranslationDocument = removeExcludedPaths(newTranslationDocument, schemaType), transaction.create(newTranslationDocument);
654
- const sourceReference = createReference(sourceLanguageId, documentId, schemaType.name, !weakReferences), newTranslationReference = createReference(language.id, newTranslationDocumentId, schemaType.name, !weakReferences), newMetadataDocument = {
655
- _id: metadataId,
656
- _type: METADATA_SCHEMA_NAME,
657
- schemaTypes: [schemaType.name],
658
- translations: [sourceReference]
659
- };
660
- transaction.createIfNotExists(newMetadataDocument);
661
- const metadataPatch = client.patch(metadataId).setIfMissing({
662
- translations: [sourceReference]
663
- }).insert("after", "translations[-1]", [newTranslationReference]);
664
- transaction.patch(metadataPatch), transaction.commit().then(() => {
665
- const metadataExisted = !!metadata2?._createdAt;
666
- if (toast.push({
667
- status: "success",
668
- title: `Created "${language.title}" translation`,
669
- description: metadataExisted ? "Updated Translations Metadata" : "Created Translations Metadata"
670
- }), setUserHasClicked(!1), callback)
671
- return callback({
672
- client,
673
- sourceLanguageId,
674
- sourceDocument: source,
675
- newDocument: newTranslationDocument,
676
- destinationLanguageId: language.id,
677
- metaDocumentId: metadataId
678
- });
679
- }).catch((err) => (console.error(err), setUserHasClicked(!1), toast.push({
680
- status: "error",
681
- title: "Error creating translation",
682
- description: err.message
683
- })));
684
- }, $[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], metadata2?._createdAt;
685
- const handleCreate = t3;
686
- let message;
687
- current ? message = "Current document" : translation ? message = `Open ${language.title} translation` : translation || (message = `Create new ${language.title} translation`);
688
- let t4;
689
- $[21] !== message ? (t4 = /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: message }) }), $[21] = message, $[22] = t4) : t4 = $[22];
690
- let t5;
691
- $[23] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = ["right", "left"], $[23] = t5) : t5 = $[23];
692
- const t6 = translation ? handleOpen : handleCreate, t7 = current && disabled ? "default" : "bleed";
693
- let t8;
694
- $[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];
695
- let t9;
696
- $[28] !== language.title ? (t9 = /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Text, { children: language.title }) }), $[28] = language.title, $[29] = t9) : t9 = $[29];
697
- const t10 = disabled || current ? "default" : "primary";
698
- let t11;
699
- $[30] !== language.id || $[31] !== t10 ? (t11 = /* @__PURE__ */ jsx(Badge, { tone: t10, children: language.id }), $[30] = language.id, $[31] = t10, $[32] = t11) : t11 = $[32];
700
- let t12;
701
- $[33] !== t11 || $[34] !== t8 || $[35] !== t9 ? (t12 = /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
702
- t8,
703
- t9,
704
- t11
705
- ] }), $[33] = t11, $[34] = t8, $[35] = t9, $[36] = t12) : t12 = $[36];
706
- let t13;
707
- $[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];
708
- let t14;
709
- 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;
628
+ let $ = c(45), { language, schemaType, documentId, current, source, sourceLanguageId, metadata, metadataId } = props, [userHasClicked, setUserHasClicked] = useState(!1), disabled = props.disabled || userHasClicked || current || !source || !sourceLanguageId || !metadataId, t0;
629
+ $[0] !== language.id || $[1] !== metadata ? (t0 = metadata?.translations.length ? metadata.translations.find((t) => t[LANGUAGE_FIELD_NAME] === language.id) : void 0, $[0] = language.id, $[1] = metadata, $[2] = t0) : t0 = $[2];
630
+ let translation = t0, { apiVersion, languageField, weakReferences, callback } = useDocumentInternationalizationContext(), t1;
631
+ $[3] === apiVersion ? t1 = $[4] : (t1 = { apiVersion }, $[3] = apiVersion, $[4] = t1);
632
+ let client = useClient(t1), toast = useToast(), open = useOpenInNewPane(translation?.value?._ref, schemaType.name), t2;
633
+ $[5] === open ? t2 = $[6] : (t2 = () => open(), $[5] = open, $[6] = t2);
634
+ let handleOpen = t2, t3;
635
+ $[7] !== callback || $[8] !== client || $[9] !== documentId || $[10] !== language.id || $[11] !== language.title || $[12] !== languageField || $[13] !== metadata?._createdAt || $[14] !== metadataId || $[15] !== schemaType || $[16] !== source || $[17] !== sourceLanguageId || $[18] !== toast || $[19] !== weakReferences ? (t3 = async () => {
636
+ if (!source) throw Error("Cannot create translation without source document");
637
+ if (!sourceLanguageId) throw Error("Cannot create translation without source language ID");
638
+ if (!metadataId) throw Error("Cannot create translation without a metadata ID");
639
+ setUserHasClicked(!0);
640
+ let transaction = client.transaction(), newTranslationDocumentId = uuid(), sourceReleaseId = isVersionId(source._id) ? getVersionFromId(source._id) : void 0, newTranslationDocument = {
641
+ ...source,
642
+ _id: sourceReleaseId ? getVersionId(newTranslationDocumentId, sourceReleaseId) : getDraftId(newTranslationDocumentId),
643
+ [languageField]: language.id
644
+ };
645
+ newTranslationDocument = removeExcludedPaths(newTranslationDocument, schemaType), transaction.create(newTranslationDocument);
646
+ let sourceReference = createReference(sourceLanguageId, documentId, schemaType.name, !weakReferences), newTranslationReference = createReference(language.id, newTranslationDocumentId, schemaType.name, !weakReferences), newMetadataDocument = {
647
+ _id: metadataId,
648
+ _type: METADATA_SCHEMA_NAME,
649
+ schemaTypes: [schemaType.name],
650
+ translations: [sourceReference]
651
+ };
652
+ transaction.createIfNotExists(newMetadataDocument);
653
+ let metadataPatch = client.patch(metadataId).setIfMissing({ translations: [sourceReference] }).insert("after", "translations[-1]", [newTranslationReference]);
654
+ transaction.patch(metadataPatch), transaction.commit().then(() => {
655
+ let metadataExisted = !!metadata?._createdAt;
656
+ if (toast.push({
657
+ status: "success",
658
+ title: `Created "${language.title}" translation`,
659
+ description: metadataExisted ? "Updated Translations Metadata" : "Created Translations Metadata"
660
+ }), setUserHasClicked(!1), callback) return callback({
661
+ client,
662
+ sourceLanguageId,
663
+ sourceDocument: source,
664
+ newDocument: newTranslationDocument,
665
+ destinationLanguageId: language.id,
666
+ metaDocumentId: metadataId
667
+ });
668
+ }).catch((err) => (console.error(err), setUserHasClicked(!1), toast.push({
669
+ status: "error",
670
+ title: "Error creating translation",
671
+ description: err.message
672
+ })));
673
+ }, $[7] = callback, $[8] = client, $[9] = documentId, $[10] = language.id, $[11] = language.title, $[12] = languageField, $[13] = metadata?._createdAt, $[14] = metadataId, $[15] = schemaType, $[16] = source, $[17] = sourceLanguageId, $[18] = toast, $[19] = weakReferences, $[20] = t3) : t3 = $[20], metadata?._createdAt;
674
+ let handleCreate = t3, message;
675
+ current ? message = "Current document" : translation ? message = `Open ${language.title} translation` : translation || (message = `Create new ${language.title} translation`);
676
+ let t4;
677
+ $[21] === message ? t4 = $[22] : (t4 = /* @__PURE__ */ jsx(Box, {
678
+ padding: 2,
679
+ children: /* @__PURE__ */ jsx(Text, {
680
+ muted: !0,
681
+ size: 1,
682
+ children: message
683
+ })
684
+ }), $[21] = message, $[22] = t4);
685
+ let t5;
686
+ $[23] === Symbol.for("react.memo_cache_sentinel") ? (t5 = ["right", "left"], $[23] = t5) : t5 = $[23];
687
+ let t6 = translation ? handleOpen : handleCreate, t7 = current && disabled ? "default" : "bleed", t8;
688
+ $[24] !== current || $[25] !== disabled || $[26] !== translation ? (t8 = disabled && !current ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(Text, {
689
+ size: 2,
690
+ children: jsx(translation ? SplitVerticalIcon : current ? CheckmarkIcon : AddIcon, {})
691
+ }), $[24] = current, $[25] = disabled, $[26] = translation, $[27] = t8) : t8 = $[27];
692
+ let t9;
693
+ $[28] === language.title ? t9 = $[29] : (t9 = /* @__PURE__ */ jsx(Box, {
694
+ flex: 1,
695
+ children: /* @__PURE__ */ jsx(Text, { children: language.title })
696
+ }), $[28] = language.title, $[29] = t9);
697
+ let t10 = disabled || current ? "default" : "primary", t11;
698
+ $[30] !== language.id || $[31] !== t10 ? (t11 = /* @__PURE__ */ jsx(Badge, {
699
+ tone: t10,
700
+ children: language.id
701
+ }), $[30] = language.id, $[31] = t10, $[32] = t11) : t11 = $[32];
702
+ let t12;
703
+ $[33] !== t11 || $[34] !== t8 || $[35] !== t9 ? (t12 = /* @__PURE__ */ jsxs(Flex, {
704
+ gap: 3,
705
+ align: "center",
706
+ children: [
707
+ t8,
708
+ t9,
709
+ t11
710
+ ]
711
+ }), $[33] = t11, $[34] = t8, $[35] = t9, $[36] = t12) : t12 = $[36];
712
+ let t13;
713
+ $[37] !== disabled || $[38] !== t12 || $[39] !== t6 || $[40] !== t7 ? (t13 = /* @__PURE__ */ jsx(Button, {
714
+ onClick: t6,
715
+ mode: t7,
716
+ disabled,
717
+ children: t12
718
+ }), $[37] = disabled, $[38] = t12, $[39] = t6, $[40] = t7, $[41] = t13) : t13 = $[41];
719
+ let t14;
720
+ return $[42] !== t13 || $[43] !== t4 ? (t14 = /* @__PURE__ */ jsx(Tooltip, {
721
+ animate: !0,
722
+ content: t4,
723
+ fallbackPlacements: t5,
724
+ placement: "top",
725
+ portal: !0,
726
+ children: t13
727
+ }), $[42] = t13, $[43] = t4, $[44] = t14) : t14 = $[44], t14;
710
728
  }
729
+ /**
730
+ * Button component that patches the current document's language field to
731
+ * the selected language. Displays the language name and ID badge, and shows
732
+ * a success or error toast after the patch operation completes.
733
+ */
711
734
  function LanguagePatch(props) {
712
- const $ = c(21), {
713
- language,
714
- source
715
- } = props, {
716
- apiVersion,
717
- languageField
718
- } = useDocumentInternationalizationContext(), disabled = props.disabled || !source;
719
- let t0;
720
- $[0] !== apiVersion ? (t0 = {
721
- apiVersion
722
- }, $[0] = apiVersion, $[1] = t0) : t0 = $[1];
723
- const client = useClient(t0), toast = useToast();
724
- let t1;
725
- $[2] !== client || $[3] !== language.id || $[4] !== language.title || $[5] !== languageField || $[6] !== source || $[7] !== toast ? (t1 = () => {
726
- if (!source)
727
- throw new Error("Cannot patch missing document");
728
- const currentId = source._id;
729
- client.patch(currentId).set({
730
- [languageField]: language.id
731
- }).commit().then(() => {
732
- toast.push({
733
- title: `Set document language to ${language.title}`,
734
- status: "success"
735
- });
736
- }).catch((err) => (console.error(err), toast.push({
737
- title: `Failed to set document language to ${language.title}`,
738
- status: "error"
739
- })));
740
- }, $[2] = client, $[3] = language.id, $[4] = language.title, $[5] = languageField, $[6] = source, $[7] = toast, $[8] = t1) : t1 = $[8];
741
- const handleClick = t1;
742
- let t2;
743
- $[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(EditIcon, {}) }), $[9] = t2) : t2 = $[9];
744
- let t3;
745
- $[10] !== language.title ? (t3 = /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Text, { children: language.title }) }), $[10] = language.title, $[11] = t3) : t3 = $[11];
746
- let t4;
747
- $[12] !== language.id ? (t4 = /* @__PURE__ */ jsx(Badge, { children: language.id }), $[12] = language.id, $[13] = t4) : t4 = $[13];
748
- let t5;
749
- $[14] !== t3 || $[15] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", children: [
750
- t2,
751
- t3,
752
- t4
753
- ] }), $[14] = t3, $[15] = t4, $[16] = t5) : t5 = $[16];
754
- let t6;
755
- 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;
735
+ let $ = c(21), { language, source } = props, { apiVersion, languageField } = useDocumentInternationalizationContext(), disabled = props.disabled || !source, t0;
736
+ $[0] === apiVersion ? t0 = $[1] : (t0 = { apiVersion }, $[0] = apiVersion, $[1] = t0);
737
+ let client = useClient(t0), toast = useToast(), t1;
738
+ $[2] !== client || $[3] !== language.id || $[4] !== language.title || $[5] !== languageField || $[6] !== source || $[7] !== toast ? (t1 = () => {
739
+ if (!source) throw Error("Cannot patch missing document");
740
+ let currentId = source._id;
741
+ client.patch(currentId).set({ [languageField]: language.id }).commit().then(() => {
742
+ toast.push({
743
+ title: `Set document language to ${language.title}`,
744
+ status: "success"
745
+ });
746
+ }).catch((err) => (console.error(err), toast.push({
747
+ title: `Failed to set document language to ${language.title}`,
748
+ status: "error"
749
+ })));
750
+ }, $[2] = client, $[3] = language.id, $[4] = language.title, $[5] = languageField, $[6] = source, $[7] = toast, $[8] = t1) : t1 = $[8];
751
+ let handleClick = t1, t2;
752
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Text, {
753
+ size: 2,
754
+ children: /* @__PURE__ */ jsx(EditIcon, {})
755
+ }), $[9] = t2) : t2 = $[9];
756
+ let t3;
757
+ $[10] === language.title ? t3 = $[11] : (t3 = /* @__PURE__ */ jsx(Box, {
758
+ flex: 1,
759
+ children: /* @__PURE__ */ jsx(Text, { children: language.title })
760
+ }), $[10] = language.title, $[11] = t3);
761
+ let t4;
762
+ $[12] === language.id ? t4 = $[13] : (t4 = /* @__PURE__ */ jsx(Badge, { children: language.id }), $[12] = language.id, $[13] = t4);
763
+ let t5;
764
+ $[14] !== t3 || $[15] !== t4 ? (t5 = /* @__PURE__ */ jsxs(Flex, {
765
+ gap: 3,
766
+ align: "center",
767
+ children: [
768
+ t2,
769
+ t3,
770
+ t4
771
+ ]
772
+ }), $[14] = t3, $[15] = t4, $[16] = t5) : t5 = $[16];
773
+ let t6;
774
+ return $[17] !== disabled || $[18] !== handleClick || $[19] !== t5 ? (t6 = /* @__PURE__ */ jsx(Button, {
775
+ mode: "bleed",
776
+ onClick: handleClick,
777
+ disabled,
778
+ justify: "flex-start",
779
+ children: t5
780
+ }), $[17] = disabled, $[18] = handleClick, $[19] = t5, $[20] = t6) : t6 = $[20], t6;
756
781
  }
757
782
  function ConstrainedBox(t0) {
758
- const $ = c(3), {
759
- children
760
- } = t0;
761
- let t1;
762
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = {
763
- maxWidth: 280
764
- }, $[0] = t1) : t1 = $[0];
765
- let t2;
766
- return $[1] !== children ? (t2 = /* @__PURE__ */ jsx(Box, { style: t1, children }), $[1] = children, $[2] = t2) : t2 = $[2], t2;
783
+ let $ = c(3), { children } = t0, t1;
784
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = { maxWidth: 280 }, $[0] = t1) : t1 = $[0];
785
+ let t2;
786
+ return $[1] === children ? t2 = $[2] : (t2 = /* @__PURE__ */ jsx(Box, {
787
+ style: t1,
788
+ children
789
+ }), $[1] = children, $[2] = t2), t2;
767
790
  }
791
+ /**
792
+ * Presentational component that renders a caution-toned card with centered
793
+ * text inside a constrained-width box. Used to display warning messages
794
+ * in the internationalization UI.
795
+ */
768
796
  function Warning(t0) {
769
- const $ = c(2), {
770
- children
771
- } = t0;
772
- let t1;
773
- 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;
797
+ let $ = c(2), { children } = t0, t1;
798
+ return $[0] === children ? t1 = $[1] : (t1 = /* @__PURE__ */ jsx(Card, {
799
+ tone: "caution",
800
+ padding: 3,
801
+ children: /* @__PURE__ */ jsx(Flex, {
802
+ justify: "center",
803
+ children: /* @__PURE__ */ jsx(ConstrainedBox, { children: /* @__PURE__ */ jsx(Text, {
804
+ size: 1,
805
+ align: "center",
806
+ children
807
+ }) })
808
+ })
809
+ }), $[0] = children, $[1] = t1), t1;
774
810
  }
775
811
  function DocumentInternationalizationMenu(props) {
776
- const $ = c(36), {
777
- documentId
778
- } = props, schemaType = props.schemaType, {
779
- languageField,
780
- supportedLanguages
781
- } = useDocumentInternationalizationContext(), [query2, setQuery] = useState("");
782
- let t0;
783
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = (event) => {
784
- event.currentTarget.value ? setQuery(event.currentTarget.value) : setQuery("");
785
- }, $[0] = t0) : t0 = $[0];
786
- const handleQuery = t0, [open, setOpen] = useState(!1);
787
- let t1;
788
- $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setOpen(_temp$3), $[1] = t1) : t1 = $[1];
789
- const handleClick = t1, buttonRef = useRef(null), popoverRef = useRef(null);
790
- let t2;
791
- $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = () => setOpen(!1), $[2] = t2) : t2 = $[2];
792
- const handleClickOutside = t2;
793
- let t3;
794
- $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = () => [buttonRef.current, popoverRef.current], $[3] = t3) : t3 = $[3], useClickOutsideEvent(handleClickOutside, t3);
795
- const {
796
- data,
797
- loading,
798
- error
799
- } = useTranslationMetadata(documentId), metadata2 = Array.isArray(data) && data.length ? data[0] : null;
800
- metadata2?._id;
801
- let t4;
802
- bb0: {
803
- if (loading) {
804
- t4 = null;
805
- break bb0;
806
- }
807
- let t52;
808
- $[4] !== metadata2?._id ? (t52 = metadata2?._id ?? uuid(), $[4] = metadata2?._id, $[5] = t52) : t52 = $[5], t4 = t52;
809
- }
810
- const metadataId = t4, {
811
- selectedReleaseId
812
- } = usePerspective(), {
813
- draft,
814
- published,
815
- version
816
- } = useEditState(documentId, schemaType.name, "default", selectedReleaseId), source = version || draft || published, documentIsInOneMetadataDocument = Array.isArray(data) && data.length <= 1, rawLanguageValue = source?.[languageField], sourceLanguageId = typeof rawLanguageValue == "string" ? rawLanguageValue : void 0;
817
- let t5;
818
- if ($[6] !== sourceLanguageId || $[7] !== supportedLanguages) {
819
- let t62;
820
- $[9] !== sourceLanguageId ? (t62 = (l) => l.id === sourceLanguageId, $[9] = sourceLanguageId, $[10] = t62) : t62 = $[10], t5 = supportedLanguages.some(t62), $[6] = sourceLanguageId, $[7] = supportedLanguages, $[8] = t5;
821
- } else
822
- t5 = $[8];
823
- const sourceLanguageIsValid = t5;
824
- let t6;
825
- $[11] !== supportedLanguages ? (t6 = supportedLanguages.every(_temp2$1), $[11] = supportedLanguages, $[12] = t6) : t6 = $[12];
826
- const valid = t6;
827
- 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);
828
- const allLanguagesAreValid = valid;
829
- let t7;
830
- $[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, { gap: 1, children: [
831
- /* @__PURE__ */ jsx(LanguageManage, { id: metadata2?._id, documentId, metadataId, schemaType, sourceLanguageId }),
832
- supportedLanguages.length > 4 ? /* @__PURE__ */ jsx(TextInput, { onChange: handleQuery, value: query2, placeholder: "Filter languages" }) : null,
833
- supportedLanguages.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
834
- loading ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
835
- data && documentIsInOneMetadataDocument ? null : /* @__PURE__ */ jsx(Warning, { children: "This document has been found in more than one Translations Metadata document" }),
836
- allLanguagesAreValid ? null : /* @__PURE__ */ jsx(Warning, { children: "Not all language objects are valid. See the console." }),
837
- sourceLanguageId ? null : /* @__PURE__ */ jsxs(Warning, { children: [
838
- "Choose a language to apply to ",
839
- /* @__PURE__ */ jsx("strong", { children: "this Document" })
840
- ] }),
841
- sourceLanguageId && !sourceLanguageIsValid ? /* @__PURE__ */ jsxs(Warning, { children: [
842
- "Select a supported language. Current language value:",
843
- " ",
844
- /* @__PURE__ */ jsx("code", { children: sourceLanguageId })
845
- ] }) : null
846
- ] }),
847
- 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[LANGUAGE_FIELD_NAME] === language_0.id)) ?? !1 }, language_0.id))
848
- ] }) : null
849
- ] }) }), $[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];
850
- const content = t7, issueWithTranslations = !loading && sourceLanguageId && !sourceLanguageIsValid;
851
- if (!documentId || !schemaType || !schemaType.name)
852
- return null;
853
- const t8 = !source, t9 = !source || loading || !issueWithTranslations ? void 0 : "caution";
854
- let t10;
855
- $[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];
856
- let t11;
857
- 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;
812
+ let $ = c(36), { documentId } = props, schemaType = props.schemaType, { languageField, supportedLanguages } = useDocumentInternationalizationContext(), [query, setQuery] = useState(""), t0;
813
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = (event) => {
814
+ event.currentTarget.value ? setQuery(event.currentTarget.value) : setQuery("");
815
+ }, $[0] = t0) : t0 = $[0];
816
+ let handleQuery = t0, [open, setOpen] = useState(!1), t1;
817
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setOpen(_temp$3), $[1] = t1) : t1 = $[1];
818
+ let handleClick = t1, buttonRef = useRef(null), popoverRef = useRef(null), t2;
819
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => setOpen(!1), $[2] = t2) : t2 = $[2];
820
+ let handleClickOutside = t2, t3;
821
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t3 = () => [buttonRef.current, popoverRef.current], $[3] = t3) : t3 = $[3], useClickOutsideEvent(handleClickOutside, t3);
822
+ let { data, loading, error } = useTranslationMetadata(documentId), metadata = Array.isArray(data) && data.length ? data[0] : null;
823
+ metadata?._id;
824
+ let t4;
825
+ bb0: {
826
+ if (loading) {
827
+ t4 = null;
828
+ break bb0;
829
+ }
830
+ let t5;
831
+ $[4] === metadata?._id ? t5 = $[5] : (t5 = metadata?._id ?? uuid(), $[4] = metadata?._id, $[5] = t5), t4 = t5;
832
+ }
833
+ let metadataId = t4, { selectedReleaseId } = usePerspective(), { draft, published, version } = useEditState(documentId, schemaType.name, "default", selectedReleaseId), source = version || draft || published, documentIsInOneMetadataDocument = Array.isArray(data) && data.length <= 1, rawLanguageValue = source?.[languageField], sourceLanguageId = typeof rawLanguageValue == "string" ? rawLanguageValue : void 0, t5;
834
+ if ($[6] !== sourceLanguageId || $[7] !== supportedLanguages) {
835
+ let t6;
836
+ $[9] === sourceLanguageId ? t6 = $[10] : (t6 = (l) => l.id === sourceLanguageId, $[9] = sourceLanguageId, $[10] = t6), t5 = supportedLanguages.some(t6), $[6] = sourceLanguageId, $[7] = supportedLanguages, $[8] = t5;
837
+ } else t5 = $[8];
838
+ let sourceLanguageIsValid = t5, t6;
839
+ $[11] === supportedLanguages ? t6 = $[12] : (t6 = supportedLanguages.every(_temp2$1), $[11] = supportedLanguages, $[12] = t6);
840
+ let valid = t6;
841
+ 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);
842
+ let allLanguagesAreValid = valid, t7;
843
+ $[13] !== allLanguagesAreValid || $[14] !== data || $[15] !== documentId || $[16] !== documentIsInOneMetadataDocument || $[17] !== error || $[18] !== loading || $[19] !== metadata || $[20] !== metadataId || $[21] !== query || $[22] !== schemaType || $[23] !== source || $[24] !== sourceLanguageId || $[25] !== sourceLanguageIsValid || $[26] !== supportedLanguages ? (t7 = /* @__PURE__ */ jsx(Box, {
844
+ padding: 1,
845
+ children: error ? /* @__PURE__ */ jsx(Card, {
846
+ tone: "critical",
847
+ padding: 1,
848
+ children: /* @__PURE__ */ jsx(Text, { children: "There was an error returning translations metadata" })
849
+ }) : /* @__PURE__ */ jsxs(Stack, {
850
+ gap: 1,
851
+ children: [
852
+ /* @__PURE__ */ jsx(LanguageManage, {
853
+ id: metadata?._id,
854
+ documentId,
855
+ metadataId,
856
+ schemaType,
857
+ sourceLanguageId
858
+ }),
859
+ supportedLanguages.length > 4 ? /* @__PURE__ */ jsx(TextInput, {
860
+ onChange: handleQuery,
861
+ value: query,
862
+ placeholder: "Filter languages"
863
+ }) : null,
864
+ supportedLanguages.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [loading ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
865
+ data && documentIsInOneMetadataDocument ? null : /* @__PURE__ */ jsx(Warning, { children: "This document has been found in more than one Translations Metadata document" }),
866
+ allLanguagesAreValid ? null : /* @__PURE__ */ jsx(Warning, { children: "Not all language objects are valid. See the console." }),
867
+ sourceLanguageId ? null : /* @__PURE__ */ jsxs(Warning, { children: ["Choose a language to apply to ", /* @__PURE__ */ jsx("strong", { children: "this Document" })] }),
868
+ sourceLanguageId && !sourceLanguageIsValid ? /* @__PURE__ */ jsxs(Warning, { children: [
869
+ "Select a supported language. Current language value:",
870
+ " ",
871
+ /* @__PURE__ */ jsx("code", { children: sourceLanguageId })
872
+ ] }) : null
873
+ ] }), supportedLanguages.filter((language) => query ? language.title.toLowerCase().includes(query.toLowerCase()) : !0).map((language_0) => !loading && sourceLanguageId && sourceLanguageIsValid ? /* @__PURE__ */ jsx(LanguageOption, {
874
+ language: language_0,
875
+ schemaType,
876
+ documentId,
877
+ disabled: !allLanguagesAreValid,
878
+ current: language_0.id === sourceLanguageId,
879
+ metadata,
880
+ metadataId,
881
+ source,
882
+ sourceLanguageId
883
+ }, language_0.id) : /* @__PURE__ */ jsx(LanguagePatch, {
884
+ source,
885
+ language: language_0,
886
+ disabled: (loading || !allLanguagesAreValid || metadata?.translations.filter((t) => t?.value?._ref !== documentId).some((t_0) => t_0[LANGUAGE_FIELD_NAME] === language_0.id)) ?? !1
887
+ }, language_0.id))] }) : null
888
+ ]
889
+ })
890
+ }), $[13] = allLanguagesAreValid, $[14] = data, $[15] = documentId, $[16] = documentIsInOneMetadataDocument, $[17] = error, $[18] = loading, $[19] = metadata, $[20] = metadataId, $[21] = query, $[22] = schemaType, $[23] = source, $[24] = sourceLanguageId, $[25] = sourceLanguageIsValid, $[26] = supportedLanguages, $[27] = t7) : t7 = $[27];
891
+ let content = t7, issueWithTranslations = !loading && sourceLanguageId && !sourceLanguageIsValid;
892
+ if (!documentId || !schemaType || !schemaType.name) return null;
893
+ let t8 = !source, t9 = !source || loading || !issueWithTranslations ? void 0 : "caution", t10;
894
+ $[28] !== open || $[29] !== t8 || $[30] !== t9 ? (t10 = /* @__PURE__ */ jsx(Button, {
895
+ text: "Translations",
896
+ mode: "bleed",
897
+ disabled: t8,
898
+ tone: t9,
899
+ icon: TranslateIcon,
900
+ onClick: handleClick,
901
+ ref: buttonRef,
902
+ selected: open
903
+ }), $[28] = open, $[29] = t8, $[30] = t9, $[31] = t10) : t10 = $[31];
904
+ let t11;
905
+ return $[32] !== content || $[33] !== open || $[34] !== t10 ? (t11 = /* @__PURE__ */ jsx(Popover, {
906
+ animate: !0,
907
+ constrainSize: !0,
908
+ content,
909
+ open,
910
+ portal: !0,
911
+ ref: popoverRef,
912
+ overflow: "auto",
913
+ tone: "default",
914
+ children: t10
915
+ }), $[32] = content, $[33] = open, $[34] = t10, $[35] = t11) : t11 = $[35], t11;
858
916
  }
859
917
  function _temp2$1(l_0) {
860
- return l_0.id && l_0.title;
918
+ return l_0.id && l_0.title;
861
919
  }
862
920
  function _temp$3(o) {
863
- return !o;
921
+ return !o;
864
922
  }
923
+ /**
924
+ * Document action that deletes a translation metadata document along with all
925
+ * its referenced translation documents. Opens a confirmation dialog showing
926
+ * how many translations will be deleted. Executes a single transaction that
927
+ * unsets the translations array, deletes each referenced document (both
928
+ * published and draft), and finally deletes the metadata document itself.
929
+ */
865
930
  const useDeleteMetadataAction = (props) => {
866
- const $ = c(17), {
867
- id: documentId,
868
- published,
869
- draft
870
- } = props, doc = draft || published, [isDialogOpen, setDialogOpen] = useState(!1);
871
- let t0;
872
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = () => setDialogOpen(!1), $[0] = t0) : t0 = $[0];
873
- const onClose = t0;
874
- let t1;
875
- $[1] !== doc ? (t1 = doc && Array.isArray(doc[TRANSLATIONS_ARRAY_NAME]) ? doc[TRANSLATIONS_ARRAY_NAME] : [], $[1] = doc, $[2] = t1) : t1 = $[2];
876
- const translations = t1, toast = useToast();
877
- let t2;
878
- $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = {
879
- apiVersion: API_VERSION
880
- }, $[3] = t2) : t2 = $[3];
881
- const client = useClient(t2);
882
- let t3;
883
- $[4] !== client || $[5] !== documentId || $[6] !== toast || $[7] !== translations ? (t3 = () => {
884
- const tx = client.transaction();
885
- tx.patch(documentId, _temp$2), translations.length > 0 && translations.forEach((translation) => {
886
- tx.delete(translation.value._ref), tx.delete(`drafts.${translation.value._ref}`);
887
- }), tx.delete(documentId), tx.delete(`drafts.${documentId}`), tx.commit().then(() => {
888
- onClose(), toast.push({
889
- status: "success",
890
- title: "Deleted document and translations"
891
- });
892
- }).catch((err) => {
893
- toast.push({
894
- status: "error",
895
- title: "Failed to delete document and translations",
896
- description: err.message
897
- });
898
- });
899
- }, $[4] = client, $[5] = documentId, $[6] = toast, $[7] = translations, $[8] = t3) : t3 = $[8];
900
- const onProceed = t3, t4 = !doc || !translations.length;
901
- let t5;
902
- $[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = () => {
903
- setDialogOpen(!0);
904
- }, $[9] = t5) : t5 = $[9];
905
- let t6;
906
- $[10] !== isDialogOpen || $[11] !== onProceed || $[12] !== translations ? (t6 = isDialogOpen && {
907
- type: "confirm",
908
- onCancel: onClose,
909
- onConfirm: () => {
910
- onProceed(), onClose();
911
- },
912
- tone: "critical",
913
- message: translations.length === 1 ? "Delete 1 translation and this document" : `Delete all ${translations.length} translations and this document`
914
- }, $[10] = isDialogOpen, $[11] = onProceed, $[12] = translations, $[13] = t6) : t6 = $[13];
915
- let t7;
916
- return $[14] !== t4 || $[15] !== t6 ? (t7 = {
917
- label: "Delete all translations",
918
- disabled: t4,
919
- icon: TrashIcon,
920
- tone: "critical",
921
- onHandle: t5,
922
- dialog: t6
923
- }, $[14] = t4, $[15] = t6, $[16] = t7) : t7 = $[16], t7;
931
+ let $ = c(17), { id: documentId, published, draft } = props, doc = draft || published, [isDialogOpen, setDialogOpen] = useState(!1), t0;
932
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = () => setDialogOpen(!1), $[0] = t0) : t0 = $[0];
933
+ let onClose = t0, t1;
934
+ $[1] === doc ? t1 = $[2] : (t1 = doc && Array.isArray(doc[TRANSLATIONS_ARRAY_NAME]) ? doc[TRANSLATIONS_ARRAY_NAME] : [], $[1] = doc, $[2] = t1);
935
+ let translations = t1, toast = useToast(), t2;
936
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = { apiVersion: API_VERSION }, $[3] = t2) : t2 = $[3];
937
+ let client = useClient(t2), t3;
938
+ $[4] !== client || $[5] !== documentId || $[6] !== toast || $[7] !== translations ? (t3 = () => {
939
+ let tx = client.transaction();
940
+ tx.patch(documentId, _temp$2), translations.length > 0 && translations.forEach((translation) => {
941
+ tx.delete(translation.value._ref), tx.delete(`drafts.${translation.value._ref}`);
942
+ }), tx.delete(documentId), tx.delete(`drafts.${documentId}`), tx.commit().then(() => {
943
+ onClose(), toast.push({
944
+ status: "success",
945
+ title: "Deleted document and translations"
946
+ });
947
+ }).catch((err) => {
948
+ toast.push({
949
+ status: "error",
950
+ title: "Failed to delete document and translations",
951
+ description: err.message
952
+ });
953
+ });
954
+ }, $[4] = client, $[5] = documentId, $[6] = toast, $[7] = translations, $[8] = t3) : t3 = $[8];
955
+ let onProceed = t3, t4 = !doc || !translations.length, t5;
956
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t5 = () => {
957
+ setDialogOpen(!0);
958
+ }, $[9] = t5) : t5 = $[9];
959
+ let t6;
960
+ $[10] !== isDialogOpen || $[11] !== onProceed || $[12] !== translations ? (t6 = isDialogOpen && {
961
+ type: "confirm",
962
+ onCancel: onClose,
963
+ onConfirm: () => {
964
+ onProceed(), onClose();
965
+ },
966
+ tone: "critical",
967
+ message: translations.length === 1 ? "Delete 1 translation and this document" : `Delete all ${translations.length} translations and this document`
968
+ }, $[10] = isDialogOpen, $[11] = onProceed, $[12] = translations, $[13] = t6) : t6 = $[13];
969
+ let t7;
970
+ return $[14] !== t4 || $[15] !== t6 ? (t7 = {
971
+ label: "Delete all translations",
972
+ disabled: t4,
973
+ icon: TrashIcon,
974
+ tone: "critical",
975
+ onHandle: t5,
976
+ dialog: t6
977
+ }, $[14] = t4, $[15] = t6, $[16] = t7) : t7 = $[16], t7;
924
978
  };
925
979
  function _temp$2(patch) {
926
- return patch.unset([TRANSLATIONS_ARRAY_NAME]);
980
+ return patch.unset([TRANSLATIONS_ARRAY_NAME]);
927
981
  }
982
+ /**
983
+ * Document badge that displays the language identifier of a document.
984
+ * Reads the configured `languageField` from the version, draft or published
985
+ * document, looks up the matching language in `supportedLanguages` to resolve
986
+ * the title, and returns a badge descriptor with `primary` color. Returns
987
+ * `null` when no document exists or the language field is empty/non-string.
988
+ */
928
989
  function LanguageBadge(props) {
929
- const source = props?.version || props?.draft || props?.published, {
930
- languageField,
931
- supportedLanguages
932
- } = useDocumentInternationalizationContext(), languageId = source?.[languageField];
933
- if (!languageId || typeof languageId != "string")
934
- return null;
935
- const language = Array.isArray(supportedLanguages) ? supportedLanguages.find((l) => l.id === languageId) : null;
936
- return {
937
- label: language?.id ?? languageId,
938
- title: language?.title ?? void 0,
939
- color: "primary"
940
- };
990
+ let source = props?.version || props?.draft || props?.published, { languageField, supportedLanguages } = useDocumentInternationalizationContext(), languageId = source?.[languageField];
991
+ if (!languageId || typeof languageId != "string") return null;
992
+ let language = Array.isArray(supportedLanguages) ? supportedLanguages.find((l) => l.id === languageId) : null;
993
+ return {
994
+ label: language?.id ?? languageId,
995
+ title: language?.title ?? void 0,
996
+ color: "primary"
997
+ };
941
998
  }
942
999
  function DocumentCheck(props) {
943
- const $ = c(25), {
944
- id,
945
- onCheckComplete,
946
- addInvalidId,
947
- removeInvalidId,
948
- addDraftId,
949
- removeDraftId
950
- } = props, editState = useEditState(id, ""), documentType = editState.draft?._type ?? editState.published?._type ?? "", {
951
- isValidating,
952
- validation: t0
953
- } = useValidationStatus(id, documentType, !1);
954
- let t1;
955
- $[0] !== t0 ? (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
956
- const validation = t1, schema = useSchema();
957
- let t2;
958
- $[2] !== isValidating || $[3] !== validation ? (t2 = !isValidating && validation.some(_temp$1), $[2] = isValidating, $[3] = validation, $[4] = t2) : t2 = $[4];
959
- const validationHasErrors = t2;
960
- let t3, t4;
961
- if ($[5] !== addDraftId || $[6] !== addInvalidId || $[7] !== editState.draft || $[8] !== id || $[9] !== isValidating || $[10] !== onCheckComplete || $[11] !== removeDraftId || $[12] !== removeInvalidId || $[13] !== validationHasErrors ? (t3 = () => {
962
- validationHasErrors ? addInvalidId(id) : removeInvalidId(id), editState.draft ? addDraftId(id) : removeDraftId(id), isValidating || onCheckComplete(id);
963
- }, 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)
964
- return null;
965
- let t5;
966
- $[16] !== editState.draft._type || $[17] !== schema ? (t5 = schema.get(editState.draft._type), $[16] = editState.draft._type, $[17] = schema, $[18] = t5) : t5 = $[18];
967
- const schemaType = t5, t6 = validationHasErrors ? "critical" : "positive";
968
- let t7;
969
- $[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];
970
- let t8;
971
- 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;
1000
+ let $ = c(25), { id, onCheckComplete, addInvalidId, removeInvalidId, addDraftId, removeDraftId } = props, editState = useEditState(id, ""), { isValidating, validation: t0 } = useValidationStatus(id, editState.draft?._type ?? editState.published?._type ?? "", !1), t1;
1001
+ $[0] === t0 ? t1 = $[1] : (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1);
1002
+ let validation = t1, schema = useSchema(), t2;
1003
+ $[2] !== isValidating || $[3] !== validation ? (t2 = !isValidating && validation.some(_temp$1), $[2] = isValidating, $[3] = validation, $[4] = t2) : t2 = $[4];
1004
+ let validationHasErrors = t2, t3, t4;
1005
+ if ($[5] !== addDraftId || $[6] !== addInvalidId || $[7] !== editState.draft || $[8] !== id || $[9] !== isValidating || $[10] !== onCheckComplete || $[11] !== removeDraftId || $[12] !== removeInvalidId || $[13] !== validationHasErrors ? (t3 = () => {
1006
+ validationHasErrors ? addInvalidId(id) : removeInvalidId(id), editState.draft ? addDraftId(id) : removeDraftId(id), isValidating || onCheckComplete(id);
1007
+ }, t4 = [
1008
+ addDraftId,
1009
+ addInvalidId,
1010
+ editState.draft,
1011
+ id,
1012
+ isValidating,
1013
+ onCheckComplete,
1014
+ removeDraftId,
1015
+ removeInvalidId,
1016
+ validationHasErrors
1017
+ ], $[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) return null;
1018
+ let t5;
1019
+ $[16] !== editState.draft._type || $[17] !== schema ? (t5 = schema.get(editState.draft._type), $[16] = editState.draft._type, $[17] = schema, $[18] = t5) : t5 = $[18];
1020
+ let schemaType = t5, t6 = validationHasErrors ? "critical" : "positive", t7;
1021
+ $[19] !== editState.draft || $[20] !== schemaType ? (t7 = editState.draft && schemaType ? /* @__PURE__ */ jsx(Preview, {
1022
+ layout: "default",
1023
+ value: editState.draft,
1024
+ schemaType
1025
+ }) : /* @__PURE__ */ jsx(Spinner, {}), $[19] = editState.draft, $[20] = schemaType, $[21] = t7) : t7 = $[21];
1026
+ let t8;
1027
+ return $[22] !== t6 || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsx(Card, {
1028
+ border: !0,
1029
+ padding: 2,
1030
+ tone: t6,
1031
+ children: t7
1032
+ }), $[22] = t6, $[23] = t7, $[24] = t8) : t8 = $[24], t8;
972
1033
  }
973
1034
  function _temp$1(item) {
974
- return item.level === "error";
1035
+ return item.level === "error";
975
1036
  }
976
1037
  function InfoIcon(props) {
977
- const $ = c(11), {
978
- text,
979
- icon,
980
- tone,
981
- children
982
- } = props, Icon = icon;
983
- let t0;
984
- $[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];
985
- let t1;
986
- $[3] !== Icon ? (t1 = /* @__PURE__ */ jsx(Icon, {}), $[3] = Icon, $[4] = t1) : t1 = $[4];
987
- let t2;
988
- $[5] !== t1 || $[6] !== tone ? (t2 = /* @__PURE__ */ jsx(TextWithTone, { tone, size: 1, children: t1 }), $[5] = t1, $[6] = tone, $[7] = t2) : t2 = $[7];
989
- let t3;
990
- 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;
1038
+ let $ = c(11), { text, icon, tone, children } = props, Icon = icon, t0;
1039
+ $[0] !== children || $[1] !== text ? (t0 = children ? /* @__PURE__ */ jsx(Fragment, { children }) : /* @__PURE__ */ jsx(Box, {
1040
+ padding: 2,
1041
+ children: /* @__PURE__ */ jsx(Text, {
1042
+ size: 1,
1043
+ children: text
1044
+ })
1045
+ }), $[0] = children, $[1] = text, $[2] = t0) : t0 = $[2];
1046
+ let t1;
1047
+ $[3] === Icon ? t1 = $[4] : (t1 = /* @__PURE__ */ jsx(Icon, {}), $[3] = Icon, $[4] = t1);
1048
+ let t2;
1049
+ $[5] !== t1 || $[6] !== tone ? (t2 = /* @__PURE__ */ jsx(TextWithTone, {
1050
+ tone,
1051
+ size: 1,
1052
+ children: t1
1053
+ }), $[5] = t1, $[6] = tone, $[7] = t2) : t2 = $[7];
1054
+ let t3;
1055
+ return $[8] !== t0 || $[9] !== t2 ? (t3 = /* @__PURE__ */ jsx(Tooltip, {
1056
+ animate: !0,
1057
+ portal: !0,
1058
+ content: t0,
1059
+ children: t2
1060
+ }), $[8] = t0, $[9] = t2, $[10] = t3) : t3 = $[10], t3;
991
1061
  }
992
1062
  function Info() {
993
- const $ = c(4);
994
- let t0;
995
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
996
- maxWidth: 250
997
- }, $[0] = t0) : t0 = $[0];
998
- let t1;
999
- $[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];
1000
- let t2;
1001
- $[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];
1002
- let t3;
1003
- return $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(InfoIcon, { icon: InfoOutlineIcon, tone: "primary", children: /* @__PURE__ */ jsxs(Stack, { padding: 3, gap: 4, style: t0, children: [
1004
- t1,
1005
- t2,
1006
- /* @__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." }) })
1007
- ] }) }), $[3] = t3) : t3 = $[3], t3;
1063
+ let $ = c(4), t0;
1064
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { maxWidth: 250 }, $[0] = t0) : t0 = $[0];
1065
+ let t1;
1066
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, {
1067
+ size: 1,
1068
+ children: "Bulk publishing uses the Scheduling API."
1069
+ }) }), $[1] = t1) : t1 = $[1];
1070
+ let t2;
1071
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, {
1072
+ size: 1,
1073
+ children: "Customized Document Actions in the Studio will not execute. Webhooks will execute."
1074
+ }) }), $[2] = t2) : t2 = $[2];
1075
+ let t3;
1076
+ return $[3] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(InfoIcon, {
1077
+ icon: InfoOutlineIcon,
1078
+ tone: "primary",
1079
+ children: /* @__PURE__ */ jsxs(Stack, {
1080
+ padding: 3,
1081
+ gap: 4,
1082
+ style: t0,
1083
+ children: [
1084
+ t1,
1085
+ t2,
1086
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, {
1087
+ size: 1,
1088
+ children: "Validation is checked before rendering the button below, but the Scheduling API will not check for – or enforce – validation."
1089
+ }) })
1090
+ ]
1091
+ })
1092
+ }), $[3] = t3) : t3 = $[3], t3;
1008
1093
  }
1009
1094
  function BulkPublish(props) {
1010
- const $ = c(23), {
1011
- translations
1012
- } = props;
1013
- let t0;
1014
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
1015
- apiVersion: API_VERSION
1016
- }, $[0] = t0) : t0 = $[0];
1017
- const client = useClient(t0), {
1018
- projectId,
1019
- dataset
1020
- } = useWorkspace(), toast = useToast(), [invalidIds, setInvalidIds] = useState(null);
1021
- let t1;
1022
- $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[1] = t1) : t1 = $[1];
1023
- const [checkedIds, setCheckedIds] = useState(t1);
1024
- let t2;
1025
- $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = (id) => {
1026
- setCheckedIds((ids) => Array.from(/* @__PURE__ */ new Set([...ids, id])));
1027
- }, $[2] = t2) : t2 = $[2];
1028
- const onCheckComplete = t2, [open, setOpen] = useState(!1);
1029
- let t3;
1030
- $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = () => setOpen(!0), $[3] = t3) : t3 = $[3];
1031
- const onOpen = t3;
1032
- let t4;
1033
- $[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = () => setOpen(!1), $[4] = t4) : t4 = $[4];
1034
- const onClose = t4;
1035
- let t5;
1036
- $[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = (id_0) => {
1037
- setInvalidIds((ids_0) => ids_0 ? Array.from(/* @__PURE__ */ new Set([...ids_0, id_0])) : [id_0]);
1038
- }, $[5] = t5) : t5 = $[5];
1039
- const addInvalidId = t5;
1040
- let t6;
1041
- $[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = (id_1) => {
1042
- setInvalidIds((ids_1) => ids_1 ? ids_1.filter((i) => i !== id_1) : []);
1043
- }, $[6] = t6) : t6 = $[6];
1044
- const removeInvalidId = t6;
1045
- let t7;
1046
- $[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = [], $[7] = t7) : t7 = $[7];
1047
- const [draftIds, setDraftIds] = useState(t7);
1048
- let t8;
1049
- $[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = (id_2) => {
1050
- setDraftIds((ids_2) => Array.from(/* @__PURE__ */ new Set([...ids_2, id_2])));
1051
- }, $[8] = t8) : t8 = $[8];
1052
- const addDraftId = t8;
1053
- let t9;
1054
- $[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t9 = (id_3) => {
1055
- setDraftIds((ids_3) => ids_3.filter((i_0) => i_0 !== id_3));
1056
- }, $[9] = t9) : t9 = $[9];
1057
- const removeDraftId = t9;
1058
- let t10;
1059
- $[10] !== client || $[11] !== dataset || $[12] !== projectId || $[13] !== toast || $[14] !== translations ? (t10 = () => {
1060
- const body = translations.map(_temp);
1061
- client.request({
1062
- uri: `/publish/${projectId}/${dataset}`,
1063
- method: "POST",
1064
- body
1065
- }).then(() => {
1066
- toast.push({
1067
- status: "success",
1068
- title: "Success",
1069
- description: "Bulk publish complete"
1070
- });
1071
- }).catch((err) => {
1072
- console.error(err), toast.push({
1073
- status: "error",
1074
- title: "Error",
1075
- description: "Bulk publish failed"
1076
- });
1077
- });
1078
- }, $[10] = client, $[11] = dataset, $[12] = projectId, $[13] = toast, $[14] = translations, $[15] = t10) : t10 = $[15];
1079
- const handleBulkPublish = t10, disabled = checkedIds.length !== translations.length || !!(invalidIds && invalidIds?.length > 0) || !draftIds.length;
1080
- let t11;
1081
- 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, { gap: 3, children: [
1082
- /* @__PURE__ */ jsxs(Inline, { gap: 3, children: [
1083
- /* @__PURE__ */ jsx(Text, { weight: "bold", size: 1, children: "Bulk publishing" }),
1084
- /* @__PURE__ */ jsx(Info, {})
1085
- ] }),
1086
- /* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(Button, { onClick: onOpen, text: "Prepare bulk publishing", mode: "ghost" }) }),
1087
- open && /* @__PURE__ */ jsx(Dialog, { animate: !0, header: "Bulk publishing", id: "bulk-publish-dialog", onClose, zOffset: 1e3, width: 3, children: /* @__PURE__ */ jsxs(Stack, { gap: 4, padding: 4, children: [
1088
- draftIds.length > 0 ? /* @__PURE__ */ jsxs(Stack, { gap: 2, children: [
1089
- /* @__PURE__ */ jsxs(Text, { size: 1, children: [
1090
- "There",
1091
- " ",
1092
- draftIds.length === 1 ? "is 1 draft document" : `are ${draftIds.length} draft documents`,
1093
- "."
1094
- ] }),
1095
- invalidIds && invalidIds.length > 0 ? /* @__PURE__ */ jsxs(TextWithTone, { tone: "critical", size: 1, children: [
1096
- invalidIds.length === 1 ? "1 draft document has" : `${invalidIds.length} draft documents have`,
1097
- " ",
1098
- "validation issues that must be addressed first"
1099
- ] }) : /* @__PURE__ */ jsx(TextWithTone, { tone: "positive", size: 1, children: "All drafts are valid and can be bulk published" })
1100
- ] }) : null,
1101
- /* @__PURE__ */ jsx(Stack, { gap: 1, children: translations.filter(_temp2).map((translation_1) => /* @__PURE__ */ jsx(DocumentCheck, { id: translation_1.value._ref, onCheckComplete, addInvalidId, removeInvalidId, addDraftId, removeDraftId }, translation_1._key)) }),
1102
- 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" })
1103
- ] }) })
1104
- ] }) }) : null, $[16] = disabled, $[17] = draftIds, $[18] = handleBulkPublish, $[19] = invalidIds, $[20] = open, $[21] = translations, $[22] = t11) : t11 = $[22], t11;
1095
+ let $ = c(23), { translations } = props, t0;
1096
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: API_VERSION }, $[0] = t0) : t0 = $[0];
1097
+ let client = useClient(t0), { projectId, dataset } = useWorkspace(), toast = useToast(), [invalidIds, setInvalidIds] = useState(null), t1;
1098
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[1] = t1) : t1 = $[1];
1099
+ let [checkedIds, setCheckedIds] = useState(t1), t2;
1100
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t2 = (id) => {
1101
+ setCheckedIds((ids) => Array.from(/* @__PURE__ */ new Set([...ids, id])));
1102
+ }, $[2] = t2) : t2 = $[2];
1103
+ let onCheckComplete = t2, [open, setOpen] = useState(!1), t3;
1104
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t3 = () => setOpen(!0), $[3] = t3) : t3 = $[3];
1105
+ let onOpen = t3, t4;
1106
+ $[4] === Symbol.for("react.memo_cache_sentinel") ? (t4 = () => setOpen(!1), $[4] = t4) : t4 = $[4];
1107
+ let onClose = t4, t5;
1108
+ $[5] === Symbol.for("react.memo_cache_sentinel") ? (t5 = (id_0) => {
1109
+ setInvalidIds((ids_0) => ids_0 ? Array.from(/* @__PURE__ */ new Set([...ids_0, id_0])) : [id_0]);
1110
+ }, $[5] = t5) : t5 = $[5];
1111
+ let addInvalidId = t5, t6;
1112
+ $[6] === Symbol.for("react.memo_cache_sentinel") ? (t6 = (id_1) => {
1113
+ setInvalidIds((ids_1) => ids_1 ? ids_1.filter((i) => i !== id_1) : []);
1114
+ }, $[6] = t6) : t6 = $[6];
1115
+ let removeInvalidId = t6, t7;
1116
+ $[7] === Symbol.for("react.memo_cache_sentinel") ? (t7 = [], $[7] = t7) : t7 = $[7];
1117
+ let [draftIds, setDraftIds] = useState(t7), t8;
1118
+ $[8] === Symbol.for("react.memo_cache_sentinel") ? (t8 = (id_2) => {
1119
+ setDraftIds((ids_2) => Array.from(/* @__PURE__ */ new Set([...ids_2, id_2])));
1120
+ }, $[8] = t8) : t8 = $[8];
1121
+ let addDraftId = t8, t9;
1122
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t9 = (id_3) => {
1123
+ setDraftIds((ids_3) => ids_3.filter((i_0) => i_0 !== id_3));
1124
+ }, $[9] = t9) : t9 = $[9];
1125
+ let removeDraftId = t9, t10;
1126
+ $[10] !== client || $[11] !== dataset || $[12] !== projectId || $[13] !== toast || $[14] !== translations ? (t10 = () => {
1127
+ let body = translations.map(_temp);
1128
+ client.request({
1129
+ uri: `/publish/${projectId}/${dataset}`,
1130
+ method: "POST",
1131
+ body
1132
+ }).then(() => {
1133
+ toast.push({
1134
+ status: "success",
1135
+ title: "Success",
1136
+ description: "Bulk publish complete"
1137
+ });
1138
+ }).catch((err) => {
1139
+ console.error(err), toast.push({
1140
+ status: "error",
1141
+ title: "Error",
1142
+ description: "Bulk publish failed"
1143
+ });
1144
+ });
1145
+ }, $[10] = client, $[11] = dataset, $[12] = projectId, $[13] = toast, $[14] = translations, $[15] = t10) : t10 = $[15];
1146
+ let handleBulkPublish = t10, disabled = checkedIds.length !== translations.length || !!(invalidIds && invalidIds?.length > 0) || !draftIds.length, t11;
1147
+ return $[16] !== disabled || $[17] !== draftIds || $[18] !== handleBulkPublish || $[19] !== invalidIds || $[20] !== open || $[21] !== translations ? (t11 = translations?.length > 0 ? /* @__PURE__ */ jsx(Card, {
1148
+ padding: 4,
1149
+ border: !0,
1150
+ radius: 2,
1151
+ children: /* @__PURE__ */ jsxs(Stack, {
1152
+ gap: 3,
1153
+ children: [
1154
+ /* @__PURE__ */ jsxs(Inline, {
1155
+ gap: 3,
1156
+ children: [/* @__PURE__ */ jsx(Text, {
1157
+ weight: "bold",
1158
+ size: 1,
1159
+ children: "Bulk publishing"
1160
+ }), /* @__PURE__ */ jsx(Info, {})]
1161
+ }),
1162
+ /* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(Button, {
1163
+ onClick: onOpen,
1164
+ text: "Prepare bulk publishing",
1165
+ mode: "ghost"
1166
+ }) }),
1167
+ open && /* @__PURE__ */ jsx(Dialog, {
1168
+ animate: !0,
1169
+ header: "Bulk publishing",
1170
+ id: "bulk-publish-dialog",
1171
+ onClose,
1172
+ zOffset: 1e3,
1173
+ width: 3,
1174
+ children: /* @__PURE__ */ jsxs(Stack, {
1175
+ gap: 4,
1176
+ padding: 4,
1177
+ children: [
1178
+ draftIds.length > 0 ? /* @__PURE__ */ jsxs(Stack, {
1179
+ gap: 2,
1180
+ children: [/* @__PURE__ */ jsxs(Text, {
1181
+ size: 1,
1182
+ children: [
1183
+ "There",
1184
+ " ",
1185
+ draftIds.length === 1 ? "is 1 draft document" : `are ${draftIds.length} draft documents`,
1186
+ "."
1187
+ ]
1188
+ }), invalidIds && invalidIds.length > 0 ? /* @__PURE__ */ jsxs(TextWithTone, {
1189
+ tone: "critical",
1190
+ size: 1,
1191
+ children: [
1192
+ invalidIds.length === 1 ? "1 draft document has" : `${invalidIds.length} draft documents have`,
1193
+ " ",
1194
+ "validation issues that must be addressed first"
1195
+ ]
1196
+ }) : /* @__PURE__ */ jsx(TextWithTone, {
1197
+ tone: "positive",
1198
+ size: 1,
1199
+ children: "All drafts are valid and can be bulk published"
1200
+ })]
1201
+ }) : null,
1202
+ /* @__PURE__ */ jsx(Stack, {
1203
+ gap: 1,
1204
+ children: translations.filter(_temp2).map((translation_1) => /* @__PURE__ */ jsx(DocumentCheck, {
1205
+ id: translation_1.value._ref,
1206
+ onCheckComplete,
1207
+ addInvalidId,
1208
+ removeInvalidId,
1209
+ addDraftId,
1210
+ removeDraftId
1211
+ }, translation_1._key))
1212
+ }),
1213
+ draftIds.length > 0 ? /* @__PURE__ */ jsx(Button, {
1214
+ mode: "ghost",
1215
+ tone: invalidIds && invalidIds?.length > 0 ? "caution" : "positive",
1216
+ text: draftIds.length === 1 ? "Publish draft document" : `Bulk publish ${draftIds.length} draft documents`,
1217
+ onClick: handleBulkPublish,
1218
+ disabled
1219
+ }) : /* @__PURE__ */ jsx(Text, {
1220
+ muted: !0,
1221
+ size: 1,
1222
+ children: "No draft documents to publish"
1223
+ })
1224
+ ]
1225
+ })
1226
+ })
1227
+ ]
1228
+ })
1229
+ }) : null, $[16] = disabled, $[17] = draftIds, $[18] = handleBulkPublish, $[19] = invalidIds, $[20] = open, $[21] = translations, $[22] = t11) : t11 = $[22], t11;
1105
1230
  }
1106
1231
  function _temp2(translation_0) {
1107
- return translation_0?.value?._ref;
1232
+ return translation_0?.value?._ref;
1108
1233
  }
1109
1234
  function _temp(translation) {
1110
- return {
1111
- documentId: translation.value._ref
1112
- };
1235
+ return { documentId: translation.value._ref };
1113
1236
  }
1114
1237
  function ReferencePatcher(props) {
1115
- const $ = c(14), {
1116
- translation,
1117
- documentType,
1118
- metadataId
1119
- } = props, editState = useEditState(translation.value._ref, documentType);
1120
- let t0;
1121
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
1122
- apiVersion: API_VERSION
1123
- }, $[0] = t0) : t0 = $[0];
1124
- const client = useClient(t0), {
1125
- onChange
1126
- } = useDocumentPane();
1127
- let t1;
1128
- $[1] !== editState || $[2] !== onChange || $[3] !== translation._key || $[4] !== translation.value._ref || $[5] !== translation.value._strengthenOnPublish || $[6] !== translation.value._weak ? (t1 = () => {
1129
- if (translation.value._ref && translation.value._weak && translation.value._strengthenOnPublish && !editState.draft && editState.published && editState.ready) {
1130
- const referencePathBase = ["translations", {
1131
- _key: translation._key
1132
- }, "value"];
1133
- onChange(new PatchEvent([unset([...referencePathBase, "_weak"]), unset([...referencePathBase, "_strengthenOnPublish"])]));
1134
- }
1135
- }, $[1] = editState, $[2] = onChange, $[3] = translation._key, $[4] = translation.value._ref, $[5] = translation.value._strengthenOnPublish, $[6] = translation.value._weak, $[7] = t1) : t1 = $[7];
1136
- let t2;
1137
- 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;
1238
+ let $ = c(14), { translation, documentType, metadataId } = props, editState = useEditState(translation.value._ref, documentType), t0;
1239
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: API_VERSION }, $[0] = t0) : t0 = $[0];
1240
+ let client = useClient(t0), { onChange } = useDocumentPane(), t1;
1241
+ $[1] !== editState || $[2] !== onChange || $[3] !== translation._key || $[4] !== translation.value._ref || $[5] !== translation.value._strengthenOnPublish || $[6] !== translation.value._weak ? (t1 = () => {
1242
+ if (translation.value._ref && translation.value._weak && translation.value._strengthenOnPublish && !editState.draft && editState.published && editState.ready) {
1243
+ let referencePathBase = [
1244
+ "translations",
1245
+ { _key: translation._key },
1246
+ "value"
1247
+ ];
1248
+ onChange(new PatchEvent([unset([...referencePathBase, "_weak"]), unset([...referencePathBase, "_strengthenOnPublish"])]));
1249
+ }
1250
+ }, $[1] = editState, $[2] = onChange, $[3] = translation._key, $[4] = translation.value._ref, $[5] = translation.value._strengthenOnPublish, $[6] = translation.value._weak, $[7] = t1) : t1 = $[7];
1251
+ let t2;
1252
+ return $[8] !== client || $[9] !== editState || $[10] !== metadataId || $[11] !== onChange || $[12] !== translation ? (t2 = [
1253
+ translation,
1254
+ editState,
1255
+ metadataId,
1256
+ client,
1257
+ onChange
1258
+ ], $[8] = client, $[9] = editState, $[10] = metadataId, $[11] = onChange, $[12] = translation, $[13] = t2) : t2 = $[13], useEffect(t1, t2), null;
1138
1259
  }
1139
1260
  function OptimisticallyStrengthen(props) {
1140
- const $ = c(9), {
1141
- translations: t0,
1142
- metadataId
1143
- } = props;
1144
- let t1;
1145
- $[0] !== t0 ? (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
1146
- const translations = t1;
1147
- if (!translations.length)
1148
- return null;
1149
- let t2;
1150
- if ($[2] !== metadataId || $[3] !== translations) {
1151
- let t32;
1152
- $[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;
1153
- } else
1154
- t2 = $[4];
1155
- let t3;
1156
- return $[7] !== t2 ? (t3 = /* @__PURE__ */ jsx(Fragment, { children: t2 }), $[7] = t2, $[8] = t3) : t3 = $[8], t3;
1261
+ let $ = c(9), { translations: t0, metadataId } = props, t1;
1262
+ $[0] === t0 ? t1 = $[1] : (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1);
1263
+ let translations = t1;
1264
+ if (!translations.length) return null;
1265
+ let t2;
1266
+ if ($[2] !== metadataId || $[3] !== translations) {
1267
+ let t3;
1268
+ $[5] === metadataId ? t3 = $[6] : (t3 = (translation) => translation.value._strengthenOnPublish?.type ? /* @__PURE__ */ jsx(ReferencePatcher, {
1269
+ translation,
1270
+ documentType: translation.value._strengthenOnPublish.type,
1271
+ metadataId
1272
+ }, translation._key) : null, $[5] = metadataId, $[6] = t3), t2 = translations.map(t3), $[2] = metadataId, $[3] = translations, $[4] = t2;
1273
+ } else t2 = $[4];
1274
+ let t3;
1275
+ return $[7] === t2 ? t3 = $[8] : (t3 = /* @__PURE__ */ jsx(Fragment, { children: t2 }), $[7] = t2, $[8] = t3), t3;
1157
1276
  }
1158
- var metadata = (schemaTypes, metadataFields, omnisearchVisibility = !0) => defineType({
1159
- type: "document",
1160
- name: METADATA_SCHEMA_NAME,
1161
- title: "Translation metadata",
1162
- icon: TranslateIcon,
1163
- liveEdit: !0,
1164
- __experimental_omnisearch_visibility: omnisearchVisibility,
1165
- fields: [defineField({
1166
- name: TRANSLATIONS_ARRAY_NAME,
1167
- type: "internationalizedArrayReference"
1168
- }), defineField({
1169
- name: "schemaTypes",
1170
- description: "Optional: Used to filter the reference fields above so all translations share the same types.",
1171
- type: "array",
1172
- of: [{
1173
- type: "string"
1174
- }],
1175
- options: {
1176
- list: schemaTypes
1177
- },
1178
- readOnly: ({
1179
- value
1180
- }) => !!value
1181
- }), ...metadataFields],
1182
- preview: {
1183
- select: {
1184
- translations: TRANSLATIONS_ARRAY_NAME,
1185
- documentSchemaTypes: "schemaTypes"
1186
- },
1187
- prepare(selection) {
1188
- const {
1189
- translations = [],
1190
- documentSchemaTypes = []
1191
- } = selection, title = translations.length === 1 ? "1 Translation" : `${translations.length} Translations`, languageKeys = translations.length ? translations.map((t) => t[LANGUAGE_FIELD_NAME].toUpperCase()).join(", ") : "", subtitle = [languageKeys ? `(${languageKeys})` : null, documentSchemaTypes?.length ? documentSchemaTypes.map((s) => s).join(", ") : ""].filter(Boolean).join(" ");
1192
- return {
1193
- title,
1194
- subtitle
1195
- };
1196
- }
1197
- }
1277
+ /**
1278
+ * Creates the `translation.metadata` document schema definition. This schema
1279
+ * type stores the array of translation references linking all language versions
1280
+ * of a document together, along with the allowed schema types and any custom
1281
+ * metadata fields provided by the plugin consumer. The document uses `liveEdit`
1282
+ * so changes are published immediately without drafts.
1283
+ */
1284
+ var metadata_default = (schemaTypes, metadataFields, omnisearchVisibility = !0) => defineType({
1285
+ type: "document",
1286
+ name: METADATA_SCHEMA_NAME,
1287
+ title: "Translation metadata",
1288
+ icon: TranslateIcon,
1289
+ liveEdit: !0,
1290
+ __experimental_omnisearch_visibility: omnisearchVisibility,
1291
+ fields: [
1292
+ defineField({
1293
+ name: TRANSLATIONS_ARRAY_NAME,
1294
+ type: "internationalizedArrayReference"
1295
+ }),
1296
+ defineField({
1297
+ name: "schemaTypes",
1298
+ description: "Optional: Used to filter the reference fields above so all translations share the same types.",
1299
+ type: "array",
1300
+ of: [{ type: "string" }],
1301
+ options: { list: schemaTypes },
1302
+ readOnly: ({ value }) => !!value
1303
+ }),
1304
+ ...metadataFields
1305
+ ],
1306
+ preview: {
1307
+ select: {
1308
+ translations: TRANSLATIONS_ARRAY_NAME,
1309
+ documentSchemaTypes: "schemaTypes"
1310
+ },
1311
+ prepare(selection) {
1312
+ let { translations = [], documentSchemaTypes = [] } = selection, title = translations.length === 1 ? "1 Translation" : `${translations.length} Translations`, languageKeys = translations.length ? translations.map((t) => t[LANGUAGE_FIELD_NAME].toUpperCase()).join(", ") : "";
1313
+ return {
1314
+ title,
1315
+ subtitle: [languageKeys ? `(${languageKeys})` : null, documentSchemaTypes?.length ? documentSchemaTypes.map((s) => s).join(", ") : ""].filter(Boolean).join(" ")
1316
+ };
1317
+ }
1318
+ }
1198
1319
  });
1199
1320
  const documentInternationalization = definePlugin((config) => {
1200
- const pluginConfig = {
1201
- ...DEFAULT_CONFIG,
1202
- ...config
1203
- }, {
1204
- supportedLanguages,
1205
- schemaTypes,
1206
- languageField,
1207
- bulkPublish,
1208
- metadataFields,
1209
- hideLanguageFilter,
1210
- metadataOmnisearchVisibility,
1211
- metadataInternationalization,
1212
- addTemplates
1213
- } = pluginConfig;
1214
- if (schemaTypes.length === 0)
1215
- 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.");
1216
- return {
1217
- name: "@sanity/document-internationalization",
1218
- studio: {
1219
- components: {
1220
- layout: (props) => /* @__PURE__ */ jsx(DocumentInternationalizationProvider, { ...props, pluginConfig })
1221
- }
1222
- },
1223
- i18n: {
1224
- bundles: [documentInternationalizationUsEnglishLocaleBundle]
1225
- },
1226
- // Adds:
1227
- // - A bulk-publishing UI component to the form
1228
- // - Will only work for projects on a compatible plan
1229
- form: {
1230
- components: {
1231
- input: (props) => {
1232
- if (props.id === "root" && props.schemaType.name === METADATA_SCHEMA_NAME && isSanityDocument(props?.value)) {
1233
- const metadataId = props?.value?._id, translations = (
1234
- // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
1235
- props?.value?.translations ?? []
1236
- ), weakAndTypedTranslations = translations.filter(({
1237
- value
1238
- }) => value?._weak && value._strengthenOnPublish);
1239
- return /* @__PURE__ */ jsxs(Stack, { gap: 5, children: [
1240
- bulkPublish ? /* @__PURE__ */ jsx(BulkPublish, { translations }) : null,
1241
- weakAndTypedTranslations.length > 0 ? /* @__PURE__ */ jsx(OptimisticallyStrengthen, { metadataId, translations: weakAndTypedTranslations }) : null,
1242
- props.renderDefault(props)
1243
- ] });
1244
- }
1245
- return props.renderDefault(props);
1246
- }
1247
- }
1248
- },
1249
- // Adds:
1250
- // - The `Translations` dropdown to the editing form
1251
- // - `Badges` to documents with a language value
1252
- // - The `DeleteMetadataAction` action to the metadata document type
1253
- document: {
1254
- unstable_languageFilter: (prev, ctx) => {
1255
- const {
1256
- schemaType,
1257
- documentId
1258
- } = ctx;
1259
- if (typeof hideLanguageFilter == "function") {
1260
- if (hideLanguageFilter(ctx)) return prev;
1261
- } else if (Array.isArray(hideLanguageFilter)) {
1262
- if (hideLanguageFilter.includes(schemaType)) return prev;
1263
- } else if (hideLanguageFilter)
1264
- return prev;
1265
- return schemaTypes.includes(schemaType) && documentId ? [...prev, (props) => DocumentInternationalizationMenu({
1266
- ...props,
1267
- documentId
1268
- })] : prev;
1269
- },
1270
- badges: (prev, {
1271
- schemaType
1272
- }) => schemaTypes.includes(schemaType) ? [(props) => LanguageBadge(props), ...prev] : prev,
1273
- actions: (prev, {
1274
- schemaType
1275
- }) => schemaType === METADATA_SCHEMA_NAME ? [...prev, useDeleteMetadataAction] : prev
1276
- },
1277
- // Adds:
1278
- // - The `Translations metadata` document type to the schema
1279
- schema: {
1280
- // Create the metadata document type
1281
- types: [metadata(schemaTypes, metadataFields, metadataOmnisearchVisibility)],
1282
- // For every schema type this plugin is enabled on
1283
- // Create an initial value template to set the language
1284
- templates: (prev, {
1285
- schema
1286
- }) => {
1287
- if (!addTemplates || !Array.isArray(supportedLanguages))
1288
- return prev;
1289
- const parameterizedTemplates = schemaTypes.map((schemaType) => ({
1290
- id: `${schemaType}-parameterized`,
1291
- title: `${schema?.get(schemaType)?.title ?? schemaType}: with Language`,
1292
- schemaType,
1293
- parameters: [{
1294
- name: "languageId",
1295
- title: "Language ID",
1296
- type: "string"
1297
- }],
1298
- value: ({
1299
- languageId
1300
- }) => ({
1301
- [languageField]: languageId
1302
- })
1303
- })), staticTemplates = schemaTypes.flatMap((schemaType) => supportedLanguages.map((language) => ({
1304
- id: `${schemaType}-${language.id}`,
1305
- title: `${language.title} ${schema?.get(schemaType)?.title ?? schemaType}`,
1306
- schemaType,
1307
- value: {
1308
- [languageField]: language.id
1309
- }
1310
- })));
1311
- return [...prev, ...parameterizedTemplates, ...staticTemplates];
1312
- }
1313
- },
1314
- // Uses:
1315
- // - `sanity-plugin-internationalized-array` to maintain the translations array
1316
- plugins: [
1317
- // Translation metadata stores its references using this plugin
1318
- // It cuts down on attribute usage and gives UI conveniences to add new translations
1319
- internationalizedArray({
1320
- ...metadataInternationalization,
1321
- apiVersion: pluginConfig.apiVersion,
1322
- languages: supportedLanguages,
1323
- includeForDocumentType: (documentType) => documentType === METADATA_SCHEMA_NAME,
1324
- fieldTypes: [defineField({
1325
- name: "reference",
1326
- type: "reference",
1327
- to: schemaTypes.map((type) => ({
1328
- type
1329
- })),
1330
- weak: pluginConfig.weakReferences,
1331
- // Reference filters don't actually enforce validation!
1332
- validation: (Rule) => (
1333
- // @ts-expect-error - fix typings
1334
- Rule.custom(async (item, context) => {
1335
- if (!item?.value?._ref || !item?.[LANGUAGE_FIELD_NAME])
1336
- return !0;
1337
- const valueLanguage = await context.getClient({
1338
- apiVersion: API_VERSION
1339
- }).fetch(`*[_id in [$ref, $draftRef]][0].${languageField}`, {
1340
- ref: item.value._ref,
1341
- draftRef: `drafts.${item.value._ref}`
1342
- });
1343
- return valueLanguage && valueLanguage === item[LANGUAGE_FIELD_NAME] ? !0 : "Referenced document does not have the correct language value";
1344
- })
1345
- ),
1346
- options: {
1347
- // @ts-expect-error - Update type once it knows the values of this filter
1348
- filter: ({
1349
- parent,
1350
- document
1351
- }) => {
1352
- if (!parent) return null;
1353
- const language = (Array.isArray(parent) ? parent : [parent]).find((p) => p[LANGUAGE_FIELD_NAME]);
1354
- return language?.[LANGUAGE_FIELD_NAME] ? document.schemaTypes ? {
1355
- filter: `_type in $schemaTypes && ${languageField} == $language`,
1356
- params: {
1357
- schemaTypes: document.schemaTypes,
1358
- language: language[LANGUAGE_FIELD_NAME]
1359
- }
1360
- } : {
1361
- filter: `${languageField} == $language`,
1362
- params: {
1363
- language: language[LANGUAGE_FIELD_NAME]
1364
- }
1365
- } : null;
1366
- }
1367
- }
1368
- }, {
1369
- strict: !1
1370
- })]
1371
- })
1372
- ]
1373
- };
1321
+ let pluginConfig = {
1322
+ ...DEFAULT_CONFIG,
1323
+ ...config
1324
+ }, { supportedLanguages, schemaTypes, languageField, bulkPublish, metadataFields, hideLanguageFilter, metadataOmnisearchVisibility, metadataInternationalization, addTemplates } = pluginConfig;
1325
+ if (schemaTypes.length === 0) throw Error("You must specify at least one schema type on which to enable document internationalization. Update the `schemaTypes` option in the documentInternationalization() configuration.");
1326
+ return {
1327
+ name: "@sanity/document-internationalization",
1328
+ studio: { components: { layout: (props) => /* @__PURE__ */ jsx(DocumentInternationalizationProvider, {
1329
+ ...props,
1330
+ pluginConfig
1331
+ }) } },
1332
+ i18n: { bundles: [documentInternationalizationUsEnglishLocaleBundle] },
1333
+ form: { components: { input: (props) => {
1334
+ if (props.id === "root" && props.schemaType.name === METADATA_SCHEMA_NAME && isSanityDocument(props?.value)) {
1335
+ let metadataId = props?.value?._id, translations = props?.value?.translations ?? [], weakAndTypedTranslations = translations.filter(({ value }) => value?._weak && value._strengthenOnPublish);
1336
+ return /* @__PURE__ */ jsxs(Stack, {
1337
+ gap: 5,
1338
+ children: [
1339
+ bulkPublish ? /* @__PURE__ */ jsx(BulkPublish, { translations }) : null,
1340
+ weakAndTypedTranslations.length > 0 ? /* @__PURE__ */ jsx(OptimisticallyStrengthen, {
1341
+ metadataId,
1342
+ translations: weakAndTypedTranslations
1343
+ }) : null,
1344
+ props.renderDefault(props)
1345
+ ]
1346
+ });
1347
+ }
1348
+ return props.renderDefault(props);
1349
+ } } },
1350
+ document: {
1351
+ unstable_languageFilter: (prev, ctx) => {
1352
+ let { schemaType, documentId } = ctx;
1353
+ if (typeof hideLanguageFilter == "function") {
1354
+ if (hideLanguageFilter(ctx)) return prev;
1355
+ } else if (Array.isArray(hideLanguageFilter)) {
1356
+ if (hideLanguageFilter.includes(schemaType)) return prev;
1357
+ } else if (hideLanguageFilter) return prev;
1358
+ return schemaTypes.includes(schemaType) && documentId ? [...prev, (props) => DocumentInternationalizationMenu({
1359
+ ...props,
1360
+ documentId
1361
+ })] : prev;
1362
+ },
1363
+ badges: (prev, { schemaType }) => schemaTypes.includes(schemaType) ? [(props) => LanguageBadge(props), ...prev] : prev,
1364
+ actions: (prev, { schemaType }) => schemaType === METADATA_SCHEMA_NAME ? [...prev, useDeleteMetadataAction] : prev
1365
+ },
1366
+ schema: {
1367
+ types: [metadata_default(schemaTypes, metadataFields, metadataOmnisearchVisibility)],
1368
+ templates: (prev, { schema }) => {
1369
+ if (!addTemplates || !Array.isArray(supportedLanguages)) return prev;
1370
+ let parameterizedTemplates = schemaTypes.map((schemaType) => ({
1371
+ id: `${schemaType}-parameterized`,
1372
+ title: `${schema?.get(schemaType)?.title ?? schemaType}: with Language`,
1373
+ schemaType,
1374
+ parameters: [{
1375
+ name: "languageId",
1376
+ title: "Language ID",
1377
+ type: "string"
1378
+ }],
1379
+ value: ({ languageId }) => ({ [languageField]: languageId })
1380
+ })), staticTemplates = schemaTypes.flatMap((schemaType) => supportedLanguages.map((language) => ({
1381
+ id: `${schemaType}-${language.id}`,
1382
+ title: `${language.title} ${schema?.get(schemaType)?.title ?? schemaType}`,
1383
+ schemaType,
1384
+ value: { [languageField]: language.id }
1385
+ })));
1386
+ return [
1387
+ ...prev,
1388
+ ...parameterizedTemplates,
1389
+ ...staticTemplates
1390
+ ];
1391
+ }
1392
+ },
1393
+ plugins: [internationalizedArray({
1394
+ ...metadataInternationalization,
1395
+ apiVersion: pluginConfig.apiVersion,
1396
+ languages: supportedLanguages,
1397
+ includeForDocumentType: (documentType) => documentType === METADATA_SCHEMA_NAME,
1398
+ fieldTypes: [defineField({
1399
+ name: "reference",
1400
+ type: "reference",
1401
+ to: schemaTypes.map((type) => ({ type })),
1402
+ weak: pluginConfig.weakReferences,
1403
+ validation: (Rule) => Rule.custom(async (item, context) => {
1404
+ if (!item?.value?._ref || !item?.[LANGUAGE_FIELD_NAME]) return !0;
1405
+ let valueLanguage = await context.getClient({ apiVersion: API_VERSION }).fetch(`*[_id in [$ref, $draftRef]][0].${languageField}`, {
1406
+ ref: item.value._ref,
1407
+ draftRef: `drafts.${item.value._ref}`
1408
+ });
1409
+ return valueLanguage && valueLanguage === item[LANGUAGE_FIELD_NAME] ? !0 : "Referenced document does not have the correct language value";
1410
+ }),
1411
+ options: { filter: ({ parent, document }) => {
1412
+ if (!parent) return null;
1413
+ let language = (Array.isArray(parent) ? parent : [parent]).find((p) => p[LANGUAGE_FIELD_NAME]);
1414
+ return language?.[LANGUAGE_FIELD_NAME] ? document.schemaTypes ? {
1415
+ filter: `_type in $schemaTypes && ${languageField} == $language`,
1416
+ params: {
1417
+ schemaTypes: document.schemaTypes,
1418
+ language: language[LANGUAGE_FIELD_NAME]
1419
+ }
1420
+ } : {
1421
+ filter: `${languageField} == $language`,
1422
+ params: { language: language[LANGUAGE_FIELD_NAME] }
1423
+ } : null;
1424
+ } }
1425
+ }, { strict: !1 })]
1426
+ })]
1427
+ };
1374
1428
  });
1375
- export {
1376
- DeleteTranslationAction,
1377
- DocumentInternationalizationMenu,
1378
- DuplicateWithTranslationsAction,
1379
- documentInternationalization,
1380
- useDeleteTranslationAction,
1381
- useDocumentInternationalizationContext,
1382
- useDuplicateWithTranslationsAction
1383
- };
1384
- //# sourceMappingURL=index.js.map
1429
+ export { DeleteTranslationAction, DocumentInternationalizationMenu, DuplicateWithTranslationsAction, documentInternationalization, useDeleteTranslationAction, useDocumentInternationalizationContext, useDuplicateWithTranslationsAction };
1430
+
1431
+ //# sourceMappingURL=index.js.map