gt-sanity 0.0.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE.md +1 -8
  2. package/README.md +5 -5
  3. package/dist/index.d.mts +122 -95
  4. package/dist/index.d.ts +122 -95
  5. package/dist/index.js +9089 -1119
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +9099 -1100
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +11 -4
  10. package/src/adapter/core.ts +111 -9
  11. package/src/adapter/createTask.ts +1 -1
  12. package/src/adapter/getLocales.ts +2 -2
  13. package/src/adapter/types.ts +9 -0
  14. package/src/components/TranslationsProvider.tsx +942 -0
  15. package/src/components/page/BatchProgress.tsx +27 -0
  16. package/src/components/page/ImportAllDialog.tsx +51 -0
  17. package/src/components/page/ImportMissingDialog.tsx +55 -0
  18. package/src/components/page/TranslateAllDialog.tsx +55 -0
  19. package/src/components/page/TranslationsTable.tsx +81 -0
  20. package/src/components/page/TranslationsTool.tsx +338 -0
  21. package/src/components/shared/BaseTranslationWrapper.tsx +82 -0
  22. package/src/components/{LanguageStatus.tsx → shared/LanguageStatus.tsx} +2 -0
  23. package/src/components/shared/LocaleCheckbox.tsx +47 -0
  24. package/src/components/{ProgressBar.tsx → shared/ProgressBar.tsx} +2 -0
  25. package/src/components/shared/SingleDocumentView.tsx +108 -0
  26. package/src/components/tab/TranslationView.tsx +379 -0
  27. package/src/components/tab/TranslationsTab.tsx +25 -0
  28. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +21 -11
  29. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +57 -23
  30. package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -0
  31. package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +2 -0
  32. package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +2 -0
  33. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +31 -8
  34. package/src/configuration/baseDocumentLevelConfig/index.ts +18 -101
  35. package/src/configuration/baseFieldLevelConfig.ts +19 -51
  36. package/src/configuration/utils/checkSerializationVersion.ts +2 -0
  37. package/src/configuration/utils/findDocumentAtRevision.ts +2 -0
  38. package/src/configuration/utils/findLatestDraft.ts +2 -0
  39. package/src/hooks/useClient.ts +3 -1
  40. package/src/hooks/useSecrets.ts +2 -0
  41. package/src/index.ts +91 -67
  42. package/src/sanity-api/findDocuments.ts +44 -0
  43. package/src/sanity-api/publishDocuments.ts +49 -0
  44. package/src/sanity-api/resolveRefs.ts +146 -0
  45. package/src/serialization/BaseDocumentMerger.ts +138 -0
  46. package/src/serialization/BaseSerializationConfig.ts +220 -0
  47. package/src/serialization/__tests__/BaseDocumentDeserializer/__snapshots__/documentLevelDeserialization.test.ts.snap +189 -0
  48. package/src/serialization/__tests__/BaseDocumentDeserializer/__snapshots__/fieldLevelDeserialization.test.ts.snap +107 -0
  49. package/src/serialization/__tests__/BaseDocumentDeserializer/baseDeserialization.test.ts +397 -0
  50. package/src/serialization/__tests__/BaseDocumentDeserializer/documentLevelDeserialization.test.ts +107 -0
  51. package/src/serialization/__tests__/BaseDocumentDeserializer/fieldLevelDeserialization.test.ts +107 -0
  52. package/src/serialization/__tests__/BaseDocumentMerger/__snapshots__/documentLevelMerge.test.ts.snap +193 -0
  53. package/src/serialization/__tests__/BaseDocumentMerger/__snapshots__/fieldLevelMerge.test.ts.snap +97 -0
  54. package/src/serialization/__tests__/BaseDocumentMerger/baseMerge.test.ts +36 -0
  55. package/src/serialization/__tests__/BaseDocumentMerger/documentLevelMerge.test.ts +96 -0
  56. package/src/serialization/__tests__/BaseDocumentMerger/fieldLevelMerge.test.ts +142 -0
  57. package/src/serialization/__tests__/BaseDocumentMerger/utils.ts +52 -0
  58. package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/documentInlineMarks.test.ts.snap +39 -0
  59. package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/documentLevelSerialization.test.ts.snap +8 -0
  60. package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/fieldLevelSerialization.test.ts.snap +8 -0
  61. package/src/serialization/__tests__/BaseDocumentSerializer/baseSerialization.test.ts +345 -0
  62. package/src/serialization/__tests__/BaseDocumentSerializer/documentInlineMarks.test.ts +53 -0
  63. package/src/serialization/__tests__/BaseDocumentSerializer/documentLevelSerialization.test.ts +120 -0
  64. package/src/serialization/__tests__/BaseDocumentSerializer/fieldLevelSerialization.test.ts +153 -0
  65. package/src/serialization/__tests__/BaseDocumentSerializer/utils.ts +27 -0
  66. package/src/serialization/__tests__/README +2 -0
  67. package/src/serialization/__tests__/__fixtures__/annotationAndInlineBlocks.json +140 -0
  68. package/src/serialization/__tests__/__fixtures__/customStyles.json +62 -0
  69. package/src/serialization/__tests__/__fixtures__/documentInlineMarks.json +70 -0
  70. package/src/serialization/__tests__/__fixtures__/documentLevelArticle.json +185 -0
  71. package/src/serialization/__tests__/__fixtures__/fieldLevelArticle.json +107 -0
  72. package/src/serialization/__tests__/__fixtures__/inlineDocumentLevelArticle.json +134 -0
  73. package/src/serialization/__tests__/__fixtures__/inlineSchema.ts +270 -0
  74. package/src/serialization/__tests__/__fixtures__/messy-html.html +26 -0
  75. package/src/serialization/__tests__/__fixtures__/nestedLanguageFields.json +54 -0
  76. package/src/serialization/__tests__/__fixtures__/schema.ts +310 -0
  77. package/src/serialization/__tests__/global.setup.ts +40 -0
  78. package/src/serialization/__tests__/helpers.ts +132 -0
  79. package/src/serialization/data.ts +82 -0
  80. package/src/serialization/deserialize/BaseDocumentDeserializer.ts +171 -0
  81. package/src/serialization/deserialize/helpers.ts +42 -0
  82. package/src/serialization/helpers.ts +18 -0
  83. package/src/serialization/index.ts +11 -0
  84. package/src/serialization/serialize/fieldFilters.ts +124 -0
  85. package/src/serialization/serialize/index.ts +284 -0
  86. package/src/serialization/types.ts +41 -0
  87. package/src/translation/checkTranslationStatus.ts +42 -0
  88. package/src/translation/createJobs.ts +16 -0
  89. package/src/translation/downloadTranslations.ts +68 -0
  90. package/src/translation/importDocument.ts +23 -0
  91. package/src/translation/initProject.ts +61 -0
  92. package/src/translation/uploadFiles.ts +32 -0
  93. package/src/types.ts +7 -20
  94. package/src/utils/applyDocuments.ts +72 -0
  95. package/src/utils/batchProcessor.ts +111 -0
  96. package/src/utils/importUtils.ts +95 -0
  97. package/src/utils/serialize.ts +52 -0
  98. package/src/utils/shared.ts +1 -0
  99. package/src/adapter/index.ts +0 -13
  100. package/src/components/NewTask.tsx +0 -249
  101. package/src/components/TaskView.tsx +0 -255
  102. package/src/components/TranslationContext.tsx +0 -19
  103. package/src/components/TranslationView.tsx +0 -82
  104. package/src/components/TranslationsTab.tsx +0 -177
  105. package/src/configuration/baseDocumentLevelConfig/helpers/index.ts +0 -5
  106. package/src/configuration/baseDocumentLevelConfig/legacyDocumentLevelPatch.ts +0 -69
  107. package/src/configuration/index.ts +0 -18
  108. package/src/configuration/utils/index.ts +0 -3
package/LICENSE.md CHANGED
@@ -106,14 +106,7 @@ specific language governing permissions and limitations under the License.
106
106
 
107
107
  ## Additional Code
108
108
 
109
- The following files of the Software are adapted from https://github.com/sanity-io/sanity-translations-tab.
110
- These portions are licensed under the license of the original software, listed below.
111
-
112
- - src/components/\*\*
113
- - src/configuration/\*\*
114
- - src/hooks/\*\*
115
- - src/types.ts
116
- - src/utils/\*\*
109
+ Some portions of the Software are adapted from https://github.com/sanity-io/sanity-translations-tab and https://github.com/sanity-io/sanity-naive-html-serializer. These portions are licensed under the license of the original software, listed below.
117
110
 
118
111
  MIT License
119
112
 
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # @generaltranslation/sanity
1
+ # gt-sanity
2
2
 
3
3
  > This is a **Sanity Studio v3** plugin.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```sh
8
- npm install @generaltranslation/sanity
8
+ npm install gt-sanity
9
9
  ```
10
10
 
11
11
  Then, create a [GT project](https://generaltranslation.com/dashboard) and get a production API key and project ID.
@@ -49,7 +49,7 @@ Add it as a plugin in `sanity.config.ts` (or .js):
49
49
 
50
50
  ```ts
51
51
  import { defineConfig } from 'sanity';
52
- import { gtPlugin } from '@generaltranslation/sanity';
52
+ import { gtPlugin } from 'gt-sanity';
53
53
 
54
54
  export default defineConfig({
55
55
  //...
@@ -68,8 +68,8 @@ Add the Translation View to your document structure:
68
68
  ```ts
69
69
  // ./structure.ts
70
70
  import type { DefaultDocumentNodeResolver } from 'sanity/structure';
71
- import { TranslationsTab } from '@generaltranslation/sanity';
72
- import { defaultDocumentLevelConfig } from '@generaltranslation/sanity';
71
+ import { TranslationsTab } from 'gt-sanity';
72
+ import { defaultDocumentLevelConfig } from 'gt-sanity';
73
73
  export const defaultDocumentNode: DefaultDocumentNodeResolver = (
74
74
  S,
75
75
  { schemaType }
package/dist/index.d.mts CHANGED
@@ -1,17 +1,13 @@
1
- import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
2
- import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
3
- import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
4
- import { CustomMapping } from 'generaltranslation/types';
5
- import { customSerializers } from 'sanity-naive-html-serializer';
6
- import { defaultStopTypes } from 'sanity-naive-html-serializer';
7
- import { DeserializerRule } from '@sanity/block-tools';
8
- import { JSX } from 'react';
1
+ import type { DeserializerRule } from '@portabletext/block-tools';
2
+ import { GT } from 'generaltranslation';
3
+ import { ObjectField } from 'sanity';
9
4
  import { Plugin as Plugin_2 } from 'sanity';
5
+ import { PortableTextHtmlComponents } from '@portabletext/to-html';
10
6
  import { PortableTextTypeComponent } from '@portabletext/to-html';
7
+ import { default as React_2 } from 'react';
11
8
  import { SanityClient } from 'sanity';
12
9
  import { SanityDocument } from 'sanity';
13
10
  import { Schema } from 'sanity';
14
- import { SerializedDocument } from 'sanity-naive-html-serializer';
15
11
  import { TypedObject } from 'sanity';
16
12
 
17
13
  export declare interface Adapter {
@@ -35,71 +31,82 @@ export declare interface Adapter {
35
31
  ) => Promise<any | null>;
36
32
  }
37
33
 
38
- export { BaseDocumentDeserializer };
34
+ export declare function attachGTData(
35
+ html: string,
36
+ data: Record<string, any>,
37
+ type: 'markDef'
38
+ ): string;
39
39
 
40
- export { BaseDocumentMerger };
40
+ export declare const BaseDocumentDeserializer: Deserializer;
41
41
 
42
- export { BaseDocumentSerializer };
42
+ export declare const BaseDocumentMerger: Merger;
43
43
 
44
- declare interface ConfigOptions {
45
- adapter: Adapter;
46
- secretsNamespace: string | null;
47
- exportForTranslation: (
48
- docInfo: GTFile,
49
- context: TranslationFunctionContext
50
- ) => Promise<GTSerializedDocument>;
51
- importTranslation: (
52
- docInfo: GTFile,
53
- localeId: string,
54
- doc: string,
55
- context: TranslationFunctionContext
56
- ) => Promise<void>;
57
- }
58
-
59
- export { customSerializers };
44
+ export declare const BaseDocumentSerializer: (schemas: Schema) => {
45
+ serializeDocument: (
46
+ doc: SanityDocument,
47
+ translationLevel?: TranslationLevel,
48
+ baseLang?: string,
49
+ stopTypes?: string[],
50
+ serializers?: Partial<PortableTextHtmlComponents>
51
+ ) => {
52
+ name: string;
53
+ content: string;
54
+ };
55
+ fieldFilter: (
56
+ obj: Record<string, any>,
57
+ objFields: ObjectField[],
58
+ stopTypes: string[]
59
+ ) => TypedObject;
60
+ languageObjectFieldFilter: (
61
+ obj: Record<string, any>,
62
+ baseLang: string
63
+ ) => Record<string, any>;
64
+ serializeArray: (
65
+ fieldContent: Record<string, any>[],
66
+ fieldName: string,
67
+ stopTypes: string[],
68
+ serializers: Record<string, any>
69
+ ) => string;
70
+ serializeObject: (
71
+ obj: TypedObject,
72
+ stopTypes: string[],
73
+ serializers: Record<string, any>
74
+ ) => string;
75
+ };
60
76
 
61
- export declare const defaultDocumentLevelConfig: ConfigOptions;
77
+ export declare const customSerializers: Partial<PortableTextHtmlComponents>;
62
78
 
63
- export declare const defaultFieldLevelConfig: ConfigOptions;
79
+ export declare const defaultStopTypes: string[];
64
80
 
65
- export { defaultStopTypes };
81
+ declare interface Deserializer {
82
+ deserializeDocument: (
83
+ serializedDoc: string,
84
+ deserializers?: Record<string, any>,
85
+ blockDeserializers?: Array<any>
86
+ ) => Record<string, any>;
87
+ deserializeHTML: (
88
+ html: string,
89
+ deserializers: Record<string, any>,
90
+ blockDeserializers: Array<any>
91
+ ) => Record<string, any> | any[];
92
+ }
66
93
 
67
- export declare const documentLevelPatch: (
68
- docInfo: GTFile,
69
- translatedFields: SanityDocument,
70
- localeId: string,
71
- client: SanityClient,
72
- languageField?: string,
73
- mergeWithTargetLocale?: boolean
74
- ) => Promise<void>;
94
+ export declare function detachGTData(html: string): {
95
+ html: string;
96
+ data?: Record<'markDef', Record<string, any>>;
97
+ };
75
98
 
76
99
  export declare type ExportForTranslation = (
77
100
  documentInfo: GTFile,
78
- context: TranslationFunctionContext,
79
- serializationOptions?: {
80
- additionalStopTypes?: string[];
81
- additionalSerializers?: Record<
82
- string,
83
- PortableTextTypeComponent | undefined
84
- >;
85
- },
86
- languageField?: string
101
+ context: TranslationFunctionContext
87
102
  ) => Promise<GTSerializedDocument>;
88
103
 
89
- export declare const fieldLevelPatch: (
90
- docInfo: GTFile,
91
- translatedFields: SanityDocument,
92
- localeId: string,
93
- client: SanityClient,
94
- mergeWithTargetLocale?: boolean
95
- ) => Promise<void>;
96
-
97
104
  export declare const findLatestDraft: (
98
105
  documentId: string,
99
106
  client: SanityClient
100
107
  ) => Promise<SanityDocument>;
101
108
 
102
- export declare const GTAdapter: Adapter;
109
+ declare const gt: GT;
103
110
 
104
111
  declare type GTFile = {
105
112
  documentId: string;
@@ -111,7 +118,7 @@ declare type GTFile = {
111
118
  *
112
119
  * ```ts
113
120
  * import {defineConfig} from 'sanity'
114
- * import {gtPlugin} from '@generaltranslation/sanity'
121
+ * import {gtPlugin} from 'gt-sanity'
115
122
  *
116
123
  * export default defineConfig({
117
124
  * // ...
@@ -119,50 +126,61 @@ declare type GTFile = {
119
126
  * })
120
127
  * ```
121
128
  */
122
- export declare const gtPlugin: Plugin_2<
123
- Omit<
124
- {
125
- apiKey?: string;
126
- devApiKey?: string;
127
- sourceLocale?: string;
128
- targetLocale?: string;
129
- locales?: string[];
130
- projectId?: string;
131
- baseUrl?: string;
132
- customMapping?: CustomMapping;
133
- },
134
- 'locales'
135
- > & {
136
- locales: string[];
137
- }
138
- >;
129
+ export declare const gtPlugin: Plugin_2<GTPluginConfig>;
130
+
131
+ export declare type GTPluginConfig = Omit<
132
+ Parameters<typeof gt.setConfig>[0],
133
+ 'locales'
134
+ > & {
135
+ locales: string[];
136
+ singletons?: string[];
137
+ singletonMapping?: (sourceDocumentId: string, locale: string) => string;
138
+ ignoreFields?: IgnoreFields[];
139
+ languageField?: string;
140
+ translateDocuments?: TranslateDocumentFilter[];
141
+ secretsNamespace?: string;
142
+ additionalStopTypes?: string[];
143
+ additionalSerializers?: Partial<PortableTextHtmlComponents>;
144
+ additionalDeserializers?: Record<string, any>;
145
+ additionalBlockDeserializers?: any[];
146
+ };
139
147
 
140
148
  declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
141
149
 
150
+ declare type IgnoreFields = {
151
+ documentId?: string;
152
+ fields?: {
153
+ property: string;
154
+ type?: string;
155
+ }[];
156
+ };
157
+
142
158
  export declare type ImportTranslation = (
143
159
  documentInfo: GTFile,
144
160
  localeId: string,
145
161
  document: string,
146
162
  context: TranslationFunctionContext,
147
- serializationOptions?: {
148
- additionalDeserializers?: Record<
149
- string,
150
- (value: HTMLElement) => TypedObject
151
- >;
152
- additionalBlockDeserializers?: DeserializerRule[];
153
- },
154
- languageField?: string,
155
- mergeWithTargetLocale?: boolean
163
+ mergeWithTargetLocale?: boolean,
164
+ publish?: boolean
156
165
  ) => Promise<void>;
157
166
 
158
- export declare const legacyDocumentLevelConfig: ConfigOptions;
159
-
160
- export declare const legacyDocumentLevelPatch: (
161
- docInfo: GTFile,
162
- translatedFields: SanityDocument,
163
- localeId: string,
164
- client: SanityClient
165
- ) => Promise<void>;
167
+ declare interface Merger {
168
+ fieldLevelMerge: (
169
+ translatedFields: Record<string, any>,
170
+ baseDoc: SanityDocument,
171
+ localeId: string,
172
+ baseLang: string
173
+ ) => Record<string, any>;
174
+ documentLevelMerge: (
175
+ translatedFields: Record<string, any>,
176
+ baseDoc: SanityDocument
177
+ ) => Record<string, any>;
178
+ reconcileArray: (origArray: any[], translatedArray: any[]) => any[];
179
+ reconcileObject: (
180
+ origObject: Record<string, any>,
181
+ translatedObject: Record<string, any>
182
+ ) => Record<string, any>;
183
+ }
166
184
 
167
185
  export declare type Secrets = {
168
186
  organization: string;
@@ -174,13 +192,23 @@ export declare type Secrets = {
174
192
  proxy?: string;
175
193
  };
176
194
 
177
- export { SerializedDocument };
195
+ export declare type SerializedDocument = {
196
+ name: string;
197
+ content: string;
198
+ };
199
+
200
+ declare type TranslateDocumentFilter = {
201
+ documentId?: string;
202
+ type?: string;
203
+ };
178
204
 
179
205
  export declare interface TranslationFunctionContext {
180
206
  client: SanityClient;
181
207
  schema: Schema;
182
208
  }
183
209
 
210
+ declare type TranslationLevel = 'document' | 'field';
211
+
184
212
  declare type TranslationLocale = {
185
213
  localeId: string;
186
214
  description: string;
@@ -189,7 +217,7 @@ declare type TranslationLocale = {
189
217
 
190
218
  export declare const TranslationsTab: (
191
219
  props: TranslationTabProps
192
- ) => JSX.Element;
220
+ ) => React_2.JSX.Element;
193
221
 
194
222
  export declare type TranslationsTabConfigOptions = {
195
223
  adapter: Adapter;
@@ -219,7 +247,6 @@ declare type TranslationTabProps = {
219
247
  document: {
220
248
  displayed: SanityDocument;
221
249
  };
222
- options: TranslationsTabConfigOptions;
223
250
  };
224
251
 
225
252
  declare type TranslationTask = {
package/dist/index.d.ts CHANGED
@@ -1,17 +1,13 @@
1
- import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
2
- import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
3
- import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
4
- import { CustomMapping } from 'generaltranslation/types';
5
- import { customSerializers } from 'sanity-naive-html-serializer';
6
- import { defaultStopTypes } from 'sanity-naive-html-serializer';
7
- import { DeserializerRule } from '@sanity/block-tools';
8
- import { JSX } from 'react';
1
+ import type { DeserializerRule } from '@portabletext/block-tools';
2
+ import { GT } from 'generaltranslation';
3
+ import { ObjectField } from 'sanity';
9
4
  import { Plugin as Plugin_2 } from 'sanity';
5
+ import { PortableTextHtmlComponents } from '@portabletext/to-html';
10
6
  import { PortableTextTypeComponent } from '@portabletext/to-html';
7
+ import { default as React_2 } from 'react';
11
8
  import { SanityClient } from 'sanity';
12
9
  import { SanityDocument } from 'sanity';
13
10
  import { Schema } from 'sanity';
14
- import { SerializedDocument } from 'sanity-naive-html-serializer';
15
11
  import { TypedObject } from 'sanity';
16
12
 
17
13
  export declare interface Adapter {
@@ -35,71 +31,82 @@ export declare interface Adapter {
35
31
  ) => Promise<any | null>;
36
32
  }
37
33
 
38
- export { BaseDocumentDeserializer };
34
+ export declare function attachGTData(
35
+ html: string,
36
+ data: Record<string, any>,
37
+ type: 'markDef'
38
+ ): string;
39
39
 
40
- export { BaseDocumentMerger };
40
+ export declare const BaseDocumentDeserializer: Deserializer;
41
41
 
42
- export { BaseDocumentSerializer };
42
+ export declare const BaseDocumentMerger: Merger;
43
43
 
44
- declare interface ConfigOptions {
45
- adapter: Adapter;
46
- secretsNamespace: string | null;
47
- exportForTranslation: (
48
- docInfo: GTFile,
49
- context: TranslationFunctionContext
50
- ) => Promise<GTSerializedDocument>;
51
- importTranslation: (
52
- docInfo: GTFile,
53
- localeId: string,
54
- doc: string,
55
- context: TranslationFunctionContext
56
- ) => Promise<void>;
57
- }
58
-
59
- export { customSerializers };
44
+ export declare const BaseDocumentSerializer: (schemas: Schema) => {
45
+ serializeDocument: (
46
+ doc: SanityDocument,
47
+ translationLevel?: TranslationLevel,
48
+ baseLang?: string,
49
+ stopTypes?: string[],
50
+ serializers?: Partial<PortableTextHtmlComponents>
51
+ ) => {
52
+ name: string;
53
+ content: string;
54
+ };
55
+ fieldFilter: (
56
+ obj: Record<string, any>,
57
+ objFields: ObjectField[],
58
+ stopTypes: string[]
59
+ ) => TypedObject;
60
+ languageObjectFieldFilter: (
61
+ obj: Record<string, any>,
62
+ baseLang: string
63
+ ) => Record<string, any>;
64
+ serializeArray: (
65
+ fieldContent: Record<string, any>[],
66
+ fieldName: string,
67
+ stopTypes: string[],
68
+ serializers: Record<string, any>
69
+ ) => string;
70
+ serializeObject: (
71
+ obj: TypedObject,
72
+ stopTypes: string[],
73
+ serializers: Record<string, any>
74
+ ) => string;
75
+ };
60
76
 
61
- export declare const defaultDocumentLevelConfig: ConfigOptions;
77
+ export declare const customSerializers: Partial<PortableTextHtmlComponents>;
62
78
 
63
- export declare const defaultFieldLevelConfig: ConfigOptions;
79
+ export declare const defaultStopTypes: string[];
64
80
 
65
- export { defaultStopTypes };
81
+ declare interface Deserializer {
82
+ deserializeDocument: (
83
+ serializedDoc: string,
84
+ deserializers?: Record<string, any>,
85
+ blockDeserializers?: Array<any>
86
+ ) => Record<string, any>;
87
+ deserializeHTML: (
88
+ html: string,
89
+ deserializers: Record<string, any>,
90
+ blockDeserializers: Array<any>
91
+ ) => Record<string, any> | any[];
92
+ }
66
93
 
67
- export declare const documentLevelPatch: (
68
- docInfo: GTFile,
69
- translatedFields: SanityDocument,
70
- localeId: string,
71
- client: SanityClient,
72
- languageField?: string,
73
- mergeWithTargetLocale?: boolean
74
- ) => Promise<void>;
94
+ export declare function detachGTData(html: string): {
95
+ html: string;
96
+ data?: Record<'markDef', Record<string, any>>;
97
+ };
75
98
 
76
99
  export declare type ExportForTranslation = (
77
100
  documentInfo: GTFile,
78
- context: TranslationFunctionContext,
79
- serializationOptions?: {
80
- additionalStopTypes?: string[];
81
- additionalSerializers?: Record<
82
- string,
83
- PortableTextTypeComponent | undefined
84
- >;
85
- },
86
- languageField?: string
101
+ context: TranslationFunctionContext
87
102
  ) => Promise<GTSerializedDocument>;
88
103
 
89
- export declare const fieldLevelPatch: (
90
- docInfo: GTFile,
91
- translatedFields: SanityDocument,
92
- localeId: string,
93
- client: SanityClient,
94
- mergeWithTargetLocale?: boolean
95
- ) => Promise<void>;
96
-
97
104
  export declare const findLatestDraft: (
98
105
  documentId: string,
99
106
  client: SanityClient
100
107
  ) => Promise<SanityDocument>;
101
108
 
102
- export declare const GTAdapter: Adapter;
109
+ declare const gt: GT;
103
110
 
104
111
  declare type GTFile = {
105
112
  documentId: string;
@@ -111,7 +118,7 @@ declare type GTFile = {
111
118
  *
112
119
  * ```ts
113
120
  * import {defineConfig} from 'sanity'
114
- * import {gtPlugin} from '@generaltranslation/sanity'
121
+ * import {gtPlugin} from 'gt-sanity'
115
122
  *
116
123
  * export default defineConfig({
117
124
  * // ...
@@ -119,50 +126,61 @@ declare type GTFile = {
119
126
  * })
120
127
  * ```
121
128
  */
122
- export declare const gtPlugin: Plugin_2<
123
- Omit<
124
- {
125
- apiKey?: string;
126
- devApiKey?: string;
127
- sourceLocale?: string;
128
- targetLocale?: string;
129
- locales?: string[];
130
- projectId?: string;
131
- baseUrl?: string;
132
- customMapping?: CustomMapping;
133
- },
134
- 'locales'
135
- > & {
136
- locales: string[];
137
- }
138
- >;
129
+ export declare const gtPlugin: Plugin_2<GTPluginConfig>;
130
+
131
+ export declare type GTPluginConfig = Omit<
132
+ Parameters<typeof gt.setConfig>[0],
133
+ 'locales'
134
+ > & {
135
+ locales: string[];
136
+ singletons?: string[];
137
+ singletonMapping?: (sourceDocumentId: string, locale: string) => string;
138
+ ignoreFields?: IgnoreFields[];
139
+ languageField?: string;
140
+ translateDocuments?: TranslateDocumentFilter[];
141
+ secretsNamespace?: string;
142
+ additionalStopTypes?: string[];
143
+ additionalSerializers?: Partial<PortableTextHtmlComponents>;
144
+ additionalDeserializers?: Record<string, any>;
145
+ additionalBlockDeserializers?: any[];
146
+ };
139
147
 
140
148
  declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
141
149
 
150
+ declare type IgnoreFields = {
151
+ documentId?: string;
152
+ fields?: {
153
+ property: string;
154
+ type?: string;
155
+ }[];
156
+ };
157
+
142
158
  export declare type ImportTranslation = (
143
159
  documentInfo: GTFile,
144
160
  localeId: string,
145
161
  document: string,
146
162
  context: TranslationFunctionContext,
147
- serializationOptions?: {
148
- additionalDeserializers?: Record<
149
- string,
150
- (value: HTMLElement) => TypedObject
151
- >;
152
- additionalBlockDeserializers?: DeserializerRule[];
153
- },
154
- languageField?: string,
155
- mergeWithTargetLocale?: boolean
163
+ mergeWithTargetLocale?: boolean,
164
+ publish?: boolean
156
165
  ) => Promise<void>;
157
166
 
158
- export declare const legacyDocumentLevelConfig: ConfigOptions;
159
-
160
- export declare const legacyDocumentLevelPatch: (
161
- docInfo: GTFile,
162
- translatedFields: SanityDocument,
163
- localeId: string,
164
- client: SanityClient
165
- ) => Promise<void>;
167
+ declare interface Merger {
168
+ fieldLevelMerge: (
169
+ translatedFields: Record<string, any>,
170
+ baseDoc: SanityDocument,
171
+ localeId: string,
172
+ baseLang: string
173
+ ) => Record<string, any>;
174
+ documentLevelMerge: (
175
+ translatedFields: Record<string, any>,
176
+ baseDoc: SanityDocument
177
+ ) => Record<string, any>;
178
+ reconcileArray: (origArray: any[], translatedArray: any[]) => any[];
179
+ reconcileObject: (
180
+ origObject: Record<string, any>,
181
+ translatedObject: Record<string, any>
182
+ ) => Record<string, any>;
183
+ }
166
184
 
167
185
  export declare type Secrets = {
168
186
  organization: string;
@@ -174,13 +192,23 @@ export declare type Secrets = {
174
192
  proxy?: string;
175
193
  };
176
194
 
177
- export { SerializedDocument };
195
+ export declare type SerializedDocument = {
196
+ name: string;
197
+ content: string;
198
+ };
199
+
200
+ declare type TranslateDocumentFilter = {
201
+ documentId?: string;
202
+ type?: string;
203
+ };
178
204
 
179
205
  export declare interface TranslationFunctionContext {
180
206
  client: SanityClient;
181
207
  schema: Schema;
182
208
  }
183
209
 
210
+ declare type TranslationLevel = 'document' | 'field';
211
+
184
212
  declare type TranslationLocale = {
185
213
  localeId: string;
186
214
  description: string;
@@ -189,7 +217,7 @@ declare type TranslationLocale = {
189
217
 
190
218
  export declare const TranslationsTab: (
191
219
  props: TranslationTabProps
192
- ) => JSX.Element;
220
+ ) => React_2.JSX.Element;
193
221
 
194
222
  export declare type TranslationsTabConfigOptions = {
195
223
  adapter: Adapter;
@@ -219,7 +247,6 @@ declare type TranslationTabProps = {
219
247
  document: {
220
248
  displayed: SanityDocument;
221
249
  };
222
- options: TranslationsTabConfigOptions;
223
250
  };
224
251
 
225
252
  declare type TranslationTask = {