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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-sanity",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "General Translation integration with Sanity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"lint": "eslint .",
|
|
51
51
|
"lint:fix": "eslint . --fix",
|
|
52
52
|
"prepublishOnly": "npm run build",
|
|
53
|
+
"test": "vitest run",
|
|
53
54
|
"watch": "pkg-utils watch --strict"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
@@ -57,19 +58,25 @@
|
|
|
57
58
|
"@sanity/block-tools": "^3.70.0",
|
|
58
59
|
"@sanity/icons": "^3.7.4",
|
|
59
60
|
"@sanity/incompatible-plugin": "^1.0.5",
|
|
61
|
+
"@sanity/mutator": "^3.98.1",
|
|
62
|
+
"@sanity/schema": "^3.98.1",
|
|
60
63
|
"@sanity/ui": "^2.16.4",
|
|
61
64
|
"@sanity/util": "^3.98.1",
|
|
62
|
-
"generaltranslation": "^7.6.
|
|
63
|
-
"
|
|
65
|
+
"generaltranslation": "^7.6.3",
|
|
66
|
+
"jsonpath-plus": "^10.3.0",
|
|
67
|
+
"jsonpointer": "^5.0.1",
|
|
68
|
+
"lodash.merge": "^4.6.2"
|
|
64
69
|
},
|
|
65
70
|
"devDependencies": {
|
|
66
|
-
"lightningcss": "^1.30.1",
|
|
67
71
|
"@sanity/pkg-utils": "^8.1.6",
|
|
68
72
|
"@sanity/plugin-kit": "^4.0.19",
|
|
73
|
+
"@types/lodash.merge": "^4.6.9",
|
|
69
74
|
"@types/react": "^19.1.12",
|
|
75
|
+
"jsdom": "^26.1.0",
|
|
70
76
|
"@typescript-eslint/eslint-plugin": "^8.43.0",
|
|
71
77
|
"@typescript-eslint/parser": "^8.43.0",
|
|
72
78
|
"eslint-config-sanity": "^7.1.4",
|
|
79
|
+
"just-clone": "^6.2.0",
|
|
73
80
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
74
81
|
"react": "^19.1.1",
|
|
75
82
|
"react-dom": "^19.1.1",
|
package/src/adapter/core.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { GT } from 'generaltranslation';
|
|
2
2
|
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
3
3
|
import type { Secrets } from '../types';
|
|
4
|
-
|
|
4
|
+
import type { TranslateDocumentFilter, IgnoreFields } from './types';
|
|
5
|
+
import { SECRETS_NAMESPACE } from '../utils/shared';
|
|
6
|
+
import type { PortableTextHtmlComponents } from '@portabletext/to-html';
|
|
5
7
|
export const gt = new GT();
|
|
6
8
|
|
|
7
9
|
export function overrideConfig(secrets: Secrets | null) {
|
|
@@ -12,33 +14,133 @@ export function overrideConfig(secrets: Secrets | null) {
|
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export class GTConfig {
|
|
17
|
+
secretsNamespace: string;
|
|
18
|
+
languageField: string;
|
|
15
19
|
sourceLocale: string;
|
|
16
20
|
locales: string[];
|
|
21
|
+
singletons: string[];
|
|
22
|
+
singletonMapping: (sourceDocumentId: string, locale: string) => string;
|
|
23
|
+
ignoreFields: IgnoreFields[];
|
|
24
|
+
translateDocuments: TranslateDocumentFilter[];
|
|
25
|
+
additionalStopTypes: string[];
|
|
26
|
+
additionalSerializers: Partial<PortableTextHtmlComponents>;
|
|
27
|
+
additionalDeserializers: Record<string, any>;
|
|
28
|
+
additionalBlockDeserializers: any[];
|
|
29
|
+
|
|
17
30
|
private static instance: GTConfig;
|
|
18
|
-
constructor(
|
|
31
|
+
constructor(
|
|
32
|
+
secretsNamespace: string,
|
|
33
|
+
languageField: string,
|
|
34
|
+
sourceLocale: string,
|
|
35
|
+
locales: string[],
|
|
36
|
+
singletons: string[],
|
|
37
|
+
singletonMapping: (sourceDocumentId: string, locale: string) => string,
|
|
38
|
+
ignoreFields: IgnoreFields[],
|
|
39
|
+
translateDocuments: TranslateDocumentFilter[],
|
|
40
|
+
additionalStopTypes: string[] = [],
|
|
41
|
+
additionalSerializers: Partial<PortableTextHtmlComponents> = {},
|
|
42
|
+
additionalDeserializers: Partial<PortableTextHtmlComponents> = {},
|
|
43
|
+
additionalBlockDeserializers: any[] = []
|
|
44
|
+
) {
|
|
45
|
+
this.secretsNamespace = secretsNamespace;
|
|
46
|
+
this.languageField = languageField;
|
|
19
47
|
this.sourceLocale = sourceLocale;
|
|
20
48
|
this.locales = locales;
|
|
49
|
+
this.singletons = singletons;
|
|
50
|
+
this.singletonMapping = singletonMapping;
|
|
51
|
+
this.ignoreFields = ignoreFields;
|
|
52
|
+
this.translateDocuments = translateDocuments;
|
|
53
|
+
this.additionalStopTypes = additionalStopTypes;
|
|
54
|
+
this.additionalSerializers = additionalSerializers;
|
|
55
|
+
this.additionalDeserializers = additionalDeserializers;
|
|
56
|
+
this.additionalBlockDeserializers = additionalBlockDeserializers;
|
|
21
57
|
}
|
|
22
58
|
|
|
23
59
|
static getInstance() {
|
|
24
60
|
if (!this.instance) {
|
|
25
|
-
this.instance = new GTConfig(
|
|
61
|
+
this.instance = new GTConfig(
|
|
62
|
+
SECRETS_NAMESPACE,
|
|
63
|
+
'language',
|
|
64
|
+
gt.sourceLocale || libraryDefaultLocale,
|
|
65
|
+
[],
|
|
66
|
+
[],
|
|
67
|
+
() => '',
|
|
68
|
+
[],
|
|
69
|
+
[],
|
|
70
|
+
[],
|
|
71
|
+
{},
|
|
72
|
+
{},
|
|
73
|
+
[]
|
|
74
|
+
);
|
|
26
75
|
}
|
|
27
76
|
return this.instance;
|
|
28
77
|
}
|
|
29
78
|
|
|
30
|
-
|
|
79
|
+
init(
|
|
80
|
+
secretsNamespace: string,
|
|
81
|
+
languageField: string,
|
|
82
|
+
sourceLocale: string,
|
|
83
|
+
locales: string[],
|
|
84
|
+
singletons: string[],
|
|
85
|
+
singletonMapping: (sourceDocumentId: string, locale: string) => string,
|
|
86
|
+
ignoreFields: IgnoreFields[],
|
|
87
|
+
translateDocuments: TranslateDocumentFilter[],
|
|
88
|
+
additionalStopTypes: string[] = [],
|
|
89
|
+
additionalSerializers: Partial<PortableTextHtmlComponents> = {},
|
|
90
|
+
additionalDeserializers: Partial<PortableTextHtmlComponents> = {},
|
|
91
|
+
additionalBlockDeserializers: any[] = []
|
|
92
|
+
) {
|
|
93
|
+
this.secretsNamespace = secretsNamespace;
|
|
94
|
+
this.languageField = languageField;
|
|
31
95
|
this.sourceLocale = sourceLocale;
|
|
96
|
+
this.locales = locales;
|
|
97
|
+
this.singletons = singletons;
|
|
98
|
+
this.singletonMapping = singletonMapping;
|
|
99
|
+
this.ignoreFields = ignoreFields;
|
|
100
|
+
this.translateDocuments = translateDocuments;
|
|
101
|
+
this.additionalStopTypes = additionalStopTypes;
|
|
102
|
+
this.additionalSerializers = additionalSerializers;
|
|
103
|
+
this.additionalDeserializers = additionalDeserializers;
|
|
104
|
+
this.additionalBlockDeserializers = additionalBlockDeserializers;
|
|
32
105
|
}
|
|
33
|
-
|
|
34
|
-
|
|
106
|
+
|
|
107
|
+
getSecretsNamespace() {
|
|
108
|
+
return this.secretsNamespace;
|
|
35
109
|
}
|
|
36
110
|
|
|
37
|
-
|
|
38
|
-
this.
|
|
111
|
+
getLanguageField() {
|
|
112
|
+
return this.languageField;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getSourceLocale() {
|
|
116
|
+
return this.sourceLocale;
|
|
39
117
|
}
|
|
40
118
|
getLocales() {
|
|
41
119
|
return this.locales;
|
|
42
120
|
}
|
|
121
|
+
getSingletons() {
|
|
122
|
+
return this.singletons;
|
|
123
|
+
}
|
|
124
|
+
getSingletonMapping() {
|
|
125
|
+
return this.singletonMapping;
|
|
126
|
+
}
|
|
127
|
+
getIgnoreFields() {
|
|
128
|
+
return this.ignoreFields;
|
|
129
|
+
}
|
|
130
|
+
getTranslateDocuments() {
|
|
131
|
+
return this.translateDocuments;
|
|
132
|
+
}
|
|
133
|
+
getAdditionalStopTypes() {
|
|
134
|
+
return this.additionalStopTypes;
|
|
135
|
+
}
|
|
136
|
+
getAdditionalSerializers() {
|
|
137
|
+
return this.additionalSerializers;
|
|
138
|
+
}
|
|
139
|
+
getAdditionalDeserializers() {
|
|
140
|
+
return this.additionalDeserializers;
|
|
141
|
+
}
|
|
142
|
+
getAdditionalBlockDeserializers() {
|
|
143
|
+
return this.additionalBlockDeserializers;
|
|
144
|
+
}
|
|
43
145
|
}
|
|
44
|
-
export const
|
|
146
|
+
export const pluginConfig = GTConfig.getInstance();
|
|
@@ -13,7 +13,7 @@ export const createTask: Adapter['createTask'] = async (
|
|
|
13
13
|
workflowUid?: string,
|
|
14
14
|
callbackUrl?: string
|
|
15
15
|
) => {
|
|
16
|
-
const fileName = `sanity
|
|
16
|
+
const fileName = `sanity/${documentInfo.documentId}`;
|
|
17
17
|
overrideConfig(secrets);
|
|
18
18
|
const uploadResult = await gt.uploadSourceFiles(
|
|
19
19
|
[
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Adapter, Secrets } from '../types';
|
|
2
|
-
import { gt,
|
|
2
|
+
import { gt, pluginConfig } from './core';
|
|
3
3
|
|
|
4
4
|
// note: this function is used to get the available locales for a project
|
|
5
5
|
export const getLocales: Adapter['getLocales'] = async (
|
|
6
6
|
secrets: Secrets | null
|
|
7
7
|
) => {
|
|
8
|
-
return
|
|
8
|
+
return pluginConfig.getLocales().map((locale: string) => ({
|
|
9
9
|
localeId: locale,
|
|
10
10
|
description: gt.getLocaleProperties(locale).name,
|
|
11
11
|
enabled: true,
|