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.
- package/LICENSE.md +1 -8
- package/README.md +5 -5
- package/dist/index.d.mts +122 -95
- package/dist/index.d.ts +122 -95
- package/dist/index.js +9089 -1119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9099 -1100
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -4
- package/src/adapter/core.ts +111 -9
- package/src/adapter/createTask.ts +1 -1
- package/src/adapter/getLocales.ts +2 -2
- package/src/adapter/types.ts +9 -0
- package/src/components/TranslationsProvider.tsx +942 -0
- package/src/components/page/BatchProgress.tsx +27 -0
- package/src/components/page/ImportAllDialog.tsx +51 -0
- package/src/components/page/ImportMissingDialog.tsx +55 -0
- package/src/components/page/TranslateAllDialog.tsx +55 -0
- package/src/components/page/TranslationsTable.tsx +81 -0
- package/src/components/page/TranslationsTool.tsx +338 -0
- package/src/components/shared/BaseTranslationWrapper.tsx +82 -0
- package/src/components/{LanguageStatus.tsx → shared/LanguageStatus.tsx} +2 -0
- package/src/components/shared/LocaleCheckbox.tsx +47 -0
- package/src/components/{ProgressBar.tsx → shared/ProgressBar.tsx} +2 -0
- package/src/components/shared/SingleDocumentView.tsx +108 -0
- package/src/components/tab/TranslationView.tsx +379 -0
- package/src/components/tab/TranslationsTab.tsx +25 -0
- package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +21 -11
- package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +57 -23
- package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +2 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +2 -0
- package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +31 -8
- package/src/configuration/baseDocumentLevelConfig/index.ts +18 -101
- package/src/configuration/baseFieldLevelConfig.ts +19 -51
- package/src/configuration/utils/checkSerializationVersion.ts +2 -0
- package/src/configuration/utils/findDocumentAtRevision.ts +2 -0
- package/src/configuration/utils/findLatestDraft.ts +2 -0
- package/src/hooks/useClient.ts +3 -1
- package/src/hooks/useSecrets.ts +2 -0
- package/src/index.ts +91 -67
- package/src/sanity-api/findDocuments.ts +44 -0
- package/src/sanity-api/publishDocuments.ts +49 -0
- package/src/sanity-api/resolveRefs.ts +146 -0
- package/src/serialization/BaseDocumentMerger.ts +138 -0
- package/src/serialization/BaseSerializationConfig.ts +220 -0
- package/src/serialization/__tests__/BaseDocumentDeserializer/__snapshots__/documentLevelDeserialization.test.ts.snap +189 -0
- package/src/serialization/__tests__/BaseDocumentDeserializer/__snapshots__/fieldLevelDeserialization.test.ts.snap +107 -0
- package/src/serialization/__tests__/BaseDocumentDeserializer/baseDeserialization.test.ts +397 -0
- package/src/serialization/__tests__/BaseDocumentDeserializer/documentLevelDeserialization.test.ts +107 -0
- package/src/serialization/__tests__/BaseDocumentDeserializer/fieldLevelDeserialization.test.ts +107 -0
- package/src/serialization/__tests__/BaseDocumentMerger/__snapshots__/documentLevelMerge.test.ts.snap +193 -0
- package/src/serialization/__tests__/BaseDocumentMerger/__snapshots__/fieldLevelMerge.test.ts.snap +97 -0
- package/src/serialization/__tests__/BaseDocumentMerger/baseMerge.test.ts +36 -0
- package/src/serialization/__tests__/BaseDocumentMerger/documentLevelMerge.test.ts +96 -0
- package/src/serialization/__tests__/BaseDocumentMerger/fieldLevelMerge.test.ts +142 -0
- package/src/serialization/__tests__/BaseDocumentMerger/utils.ts +52 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/documentInlineMarks.test.ts.snap +39 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/documentLevelSerialization.test.ts.snap +8 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/fieldLevelSerialization.test.ts.snap +8 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/baseSerialization.test.ts +345 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/documentInlineMarks.test.ts +53 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/documentLevelSerialization.test.ts +120 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/fieldLevelSerialization.test.ts +153 -0
- package/src/serialization/__tests__/BaseDocumentSerializer/utils.ts +27 -0
- package/src/serialization/__tests__/README +2 -0
- package/src/serialization/__tests__/__fixtures__/annotationAndInlineBlocks.json +140 -0
- package/src/serialization/__tests__/__fixtures__/customStyles.json +62 -0
- package/src/serialization/__tests__/__fixtures__/documentInlineMarks.json +70 -0
- package/src/serialization/__tests__/__fixtures__/documentLevelArticle.json +185 -0
- package/src/serialization/__tests__/__fixtures__/fieldLevelArticle.json +107 -0
- package/src/serialization/__tests__/__fixtures__/inlineDocumentLevelArticle.json +134 -0
- package/src/serialization/__tests__/__fixtures__/inlineSchema.ts +270 -0
- package/src/serialization/__tests__/__fixtures__/messy-html.html +26 -0
- package/src/serialization/__tests__/__fixtures__/nestedLanguageFields.json +54 -0
- package/src/serialization/__tests__/__fixtures__/schema.ts +310 -0
- package/src/serialization/__tests__/global.setup.ts +40 -0
- package/src/serialization/__tests__/helpers.ts +132 -0
- package/src/serialization/data.ts +82 -0
- package/src/serialization/deserialize/BaseDocumentDeserializer.ts +171 -0
- package/src/serialization/deserialize/helpers.ts +42 -0
- package/src/serialization/helpers.ts +18 -0
- package/src/serialization/index.ts +11 -0
- package/src/serialization/serialize/fieldFilters.ts +124 -0
- package/src/serialization/serialize/index.ts +284 -0
- package/src/serialization/types.ts +41 -0
- package/src/translation/checkTranslationStatus.ts +42 -0
- package/src/translation/createJobs.ts +16 -0
- package/src/translation/downloadTranslations.ts +68 -0
- package/src/translation/importDocument.ts +23 -0
- package/src/translation/initProject.ts +61 -0
- package/src/translation/uploadFiles.ts +32 -0
- package/src/types.ts +7 -20
- package/src/utils/applyDocuments.ts +72 -0
- package/src/utils/batchProcessor.ts +111 -0
- package/src/utils/importUtils.ts +95 -0
- package/src/utils/serialize.ts +52 -0
- package/src/utils/shared.ts +1 -0
- package/src/adapter/index.ts +0 -13
- package/src/components/NewTask.tsx +0 -249
- package/src/components/TaskView.tsx +0 -255
- package/src/components/TranslationContext.tsx +0 -19
- package/src/components/TranslationView.tsx +0 -82
- package/src/components/TranslationsTab.tsx +0 -177
- package/src/configuration/baseDocumentLevelConfig/helpers/index.ts +0 -5
- package/src/configuration/baseDocumentLevelConfig/legacyDocumentLevelPatch.ts +0 -69
- package/src/configuration/index.ts +0 -18
- 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
|
-
|
|
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
|
-
#
|
|
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
|
|
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 '
|
|
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 '
|
|
72
|
-
import { defaultDocumentLevelConfig } from '
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
34
|
+
export declare function attachGTData(
|
|
35
|
+
html: string,
|
|
36
|
+
data: Record<string, any>,
|
|
37
|
+
type: 'markDef'
|
|
38
|
+
): string;
|
|
39
39
|
|
|
40
|
-
export
|
|
40
|
+
export declare const BaseDocumentDeserializer: Deserializer;
|
|
41
41
|
|
|
42
|
-
export
|
|
42
|
+
export declare const BaseDocumentMerger: Merger;
|
|
43
43
|
|
|
44
|
-
declare
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
77
|
+
export declare const customSerializers: Partial<PortableTextHtmlComponents>;
|
|
62
78
|
|
|
63
|
-
export declare const
|
|
79
|
+
export declare const defaultStopTypes: string[];
|
|
64
80
|
|
|
65
|
-
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
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 '
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
34
|
+
export declare function attachGTData(
|
|
35
|
+
html: string,
|
|
36
|
+
data: Record<string, any>,
|
|
37
|
+
type: 'markDef'
|
|
38
|
+
): string;
|
|
39
39
|
|
|
40
|
-
export
|
|
40
|
+
export declare const BaseDocumentDeserializer: Deserializer;
|
|
41
41
|
|
|
42
|
-
export
|
|
42
|
+
export declare const BaseDocumentMerger: Merger;
|
|
43
43
|
|
|
44
|
-
declare
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
77
|
+
export declare const customSerializers: Partial<PortableTextHtmlComponents>;
|
|
62
78
|
|
|
63
|
-
export declare const
|
|
79
|
+
export declare const defaultStopTypes: string[];
|
|
64
80
|
|
|
65
|
-
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
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 '
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
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 = {
|