gt-sanity 2.0.7 → 2.0.9

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.
Files changed (38) hide show
  1. package/README.md +3 -0
  2. package/dist/index.d.mts +13 -14
  3. package/dist/index.d.ts +13 -14
  4. package/dist/index.js +309 -101
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +310 -102
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +2 -2
  9. package/src/adapter/core.ts +10 -0
  10. package/src/adapter/types.ts +6 -5
  11. package/src/components/TranslationsProvider.tsx +86 -28
  12. package/src/components/page/TranslationsTable.tsx +12 -4
  13. package/src/components/shared/LanguageStatus.tsx +3 -2
  14. package/src/components/shared/SingleDocumentView.tsx +12 -4
  15. package/src/components/tab/TranslationView.tsx +35 -6
  16. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.test.ts +76 -0
  17. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +27 -2
  18. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +12 -5
  19. package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -1
  20. package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +7 -4
  21. package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +2 -1
  22. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.test.ts +52 -0
  23. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +20 -2
  24. package/src/configuration/utils/findLatestDraft.ts +3 -1
  25. package/src/index.ts +4 -0
  26. package/src/sanity-api/findDocuments.ts +11 -5
  27. package/src/sanity-api/publishDocuments.ts +2 -1
  28. package/src/sanity-api/resolveRefs.ts +5 -4
  29. package/src/translation/checkTranslationStatus.ts +25 -6
  30. package/src/utils/__tests__/batchProcessor.test.ts +44 -0
  31. package/src/utils/__tests__/documentIds.test.ts +42 -0
  32. package/src/utils/__tests__/forEachMatchingField.test.ts +71 -1
  33. package/src/utils/__tests__/importUtils.test.ts +66 -0
  34. package/src/utils/applyDocuments.ts +56 -5
  35. package/src/utils/batchProcessor.ts +40 -1
  36. package/src/utils/documentIds.ts +49 -0
  37. package/src/utils/importUtils.ts +15 -7
  38. package/src/utils/serialize.ts +10 -6
package/README.md CHANGED
@@ -32,6 +32,9 @@ export default defineConfig({
32
32
  gtPlugin({
33
33
  sourceLocale: 'en',
34
34
  locales: ['es', 'fr'],
35
+ // Initialize translated document slugs with a unique locale suffix,
36
+ // e.g. "hello-world" -> "hello-world-es".
37
+ dedupeFields: [{ fields: [{ property: '$.slug' }] }],
35
38
  }),
36
39
  ],
37
40
  });
package/dist/index.d.mts CHANGED
@@ -86,6 +86,8 @@ export declare const BaseDocumentSerializer: (schemas: Schema) => {
86
86
 
87
87
  export declare const customSerializers: Partial<PortableTextHtmlComponents>;
88
88
 
89
+ declare type DedupeFields = FieldMatcher;
90
+
89
91
  export declare const defaultStopTypes: string[];
90
92
 
91
93
  declare interface Deserializer {
@@ -117,6 +119,14 @@ export declare type ExportForTranslation = (
117
119
  context: TranslationFunctionContext
118
120
  ) => Promise<GTSerializedDocument>;
119
121
 
122
+ declare type FieldMatcher = {
123
+ documentId?: string;
124
+ fields?: {
125
+ property: string;
126
+ type?: string;
127
+ }[];
128
+ };
129
+
120
130
  export declare const findLatestDraft: (
121
131
  documentId: string,
122
132
  client: SanityClient
@@ -153,6 +163,7 @@ export declare type GTPluginConfig = Omit<
153
163
  singletons?: string[];
154
164
  singletonMapping?: (sourceDocumentId: string, locale: string) => string;
155
165
  ignoreFields?: IgnoreFields[];
166
+ dedupeFields?: DedupeFields[];
156
167
  skipFields?: SkipFields[];
157
168
  languageField?: string;
158
169
  translateDocuments?: TranslateDocumentFilter[] | string[];
@@ -166,13 +177,7 @@ export declare type GTPluginConfig = Omit<
166
177
 
167
178
  declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
168
179
 
169
- declare type IgnoreFields = {
170
- documentId?: string;
171
- fields?: {
172
- property: string;
173
- type?: string;
174
- }[];
175
- };
180
+ declare type IgnoreFields = FieldMatcher;
176
181
 
177
182
  export declare type ImportTranslation = (
178
183
  documentInfo: GTFile,
@@ -220,13 +225,7 @@ export declare type SerializedDocument = {
220
225
  content: string;
221
226
  };
222
227
 
223
- declare type SkipFields = {
224
- documentId?: string;
225
- fields?: {
226
- property: string;
227
- type?: string;
228
- }[];
229
- };
228
+ declare type SkipFields = FieldMatcher;
230
229
 
231
230
  export declare const translateAction: DocumentActionComponent;
232
231
 
package/dist/index.d.ts CHANGED
@@ -86,6 +86,8 @@ export declare const BaseDocumentSerializer: (schemas: Schema) => {
86
86
 
87
87
  export declare const customSerializers: Partial<PortableTextHtmlComponents>;
88
88
 
89
+ declare type DedupeFields = FieldMatcher;
90
+
89
91
  export declare const defaultStopTypes: string[];
90
92
 
91
93
  declare interface Deserializer {
@@ -117,6 +119,14 @@ export declare type ExportForTranslation = (
117
119
  context: TranslationFunctionContext
118
120
  ) => Promise<GTSerializedDocument>;
119
121
 
122
+ declare type FieldMatcher = {
123
+ documentId?: string;
124
+ fields?: {
125
+ property: string;
126
+ type?: string;
127
+ }[];
128
+ };
129
+
120
130
  export declare const findLatestDraft: (
121
131
  documentId: string,
122
132
  client: SanityClient
@@ -153,6 +163,7 @@ export declare type GTPluginConfig = Omit<
153
163
  singletons?: string[];
154
164
  singletonMapping?: (sourceDocumentId: string, locale: string) => string;
155
165
  ignoreFields?: IgnoreFields[];
166
+ dedupeFields?: DedupeFields[];
156
167
  skipFields?: SkipFields[];
157
168
  languageField?: string;
158
169
  translateDocuments?: TranslateDocumentFilter[] | string[];
@@ -166,13 +177,7 @@ export declare type GTPluginConfig = Omit<
166
177
 
167
178
  declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
168
179
 
169
- declare type IgnoreFields = {
170
- documentId?: string;
171
- fields?: {
172
- property: string;
173
- type?: string;
174
- }[];
175
- };
180
+ declare type IgnoreFields = FieldMatcher;
176
181
 
177
182
  export declare type ImportTranslation = (
178
183
  documentInfo: GTFile,
@@ -220,13 +225,7 @@ export declare type SerializedDocument = {
220
225
  content: string;
221
226
  };
222
227
 
223
- declare type SkipFields = {
224
- documentId?: string;
225
- fields?: {
226
- property: string;
227
- type?: string;
228
- }[];
229
- };
228
+ declare type SkipFields = FieldMatcher;
230
229
 
231
230
  export declare const translateAction: DocumentActionComponent;
232
231