gt-sanity 0.0.5 → 0.0.6

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 (48) hide show
  1. package/LICENSE.md +1 -8
  2. package/README.md +5 -5
  3. package/dist/index.d.mts +35 -30
  4. package/dist/index.d.ts +35 -30
  5. package/dist/index.js +234 -123
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +237 -124
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +5 -3
  10. package/src/adapter/core.ts +72 -7
  11. package/src/adapter/createTask.ts +1 -1
  12. package/src/adapter/types.ts +9 -0
  13. package/src/components/LanguageStatus.tsx +2 -0
  14. package/src/components/NewTask.tsx +2 -0
  15. package/src/components/ProgressBar.tsx +2 -0
  16. package/src/components/TaskView.tsx +2 -0
  17. package/src/components/TranslationContext.tsx +5 -0
  18. package/src/components/TranslationView.tsx +34 -2
  19. package/src/components/TranslationsTab.tsx +4 -0
  20. package/src/components/page/TranslationsTool.tsx +876 -0
  21. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +23 -10
  22. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +77 -24
  23. package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -0
  24. package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +2 -0
  25. package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +2 -0
  26. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +51 -8
  27. package/src/configuration/baseDocumentLevelConfig/index.ts +6 -37
  28. package/src/configuration/baseFieldLevelConfig.ts +4 -1
  29. package/src/configuration/utils/checkSerializationVersion.ts +2 -0
  30. package/src/configuration/utils/findDocumentAtRevision.ts +2 -0
  31. package/src/configuration/utils/findLatestDraft.ts +2 -0
  32. package/src/hooks/useClient.ts +3 -1
  33. package/src/hooks/useSecrets.ts +2 -0
  34. package/src/index.ts +70 -32
  35. package/src/translation/checkTranslationStatus.ts +42 -0
  36. package/src/translation/createJobs.ts +16 -0
  37. package/src/translation/downloadTranslations.ts +68 -0
  38. package/src/translation/importDocument.ts +24 -0
  39. package/src/translation/initProject.ts +61 -0
  40. package/src/translation/uploadFiles.ts +32 -0
  41. package/src/types.ts +4 -1
  42. package/src/utils/applyDocuments.ts +72 -0
  43. package/src/utils/serialize.ts +32 -0
  44. package/src/utils/shared.ts +1 -0
  45. package/src/configuration/baseDocumentLevelConfig/helpers/index.ts +0 -5
  46. package/src/configuration/baseDocumentLevelConfig/legacyDocumentLevelPatch.ts +0 -69
  47. package/src/configuration/index.ts +0 -18
  48. 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
+ The some portions of the Software are adapted from https://github.com/sanity-io/sanity-translations-tab. 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,10 +1,10 @@
1
1
  import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
2
2
  import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
3
3
  import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
4
- import { CustomMapping } from 'generaltranslation/types';
5
4
  import { customSerializers } from 'sanity-naive-html-serializer';
6
5
  import { defaultStopTypes } from 'sanity-naive-html-serializer';
7
6
  import { DeserializerRule } from '@sanity/block-tools';
7
+ import { GT } from 'generaltranslation';
8
8
  import { JSX } from 'react';
9
9
  import { Plugin as Plugin_2 } from 'sanity';
10
10
  import { PortableTextTypeComponent } from '@portabletext/to-html';
@@ -70,7 +70,8 @@ export declare const documentLevelPatch: (
70
70
  localeId: string,
71
71
  client: SanityClient,
72
72
  languageField?: string,
73
- mergeWithTargetLocale?: boolean
73
+ mergeWithTargetLocale?: boolean,
74
+ publish?: boolean
74
75
  ) => Promise<void>;
75
76
 
76
77
  export declare type ExportForTranslation = (
@@ -99,6 +100,8 @@ export declare const findLatestDraft: (
99
100
  client: SanityClient
100
101
  ) => Promise<SanityDocument>;
101
102
 
103
+ declare const gt: GT;
104
+
102
105
  export declare const GTAdapter: Adapter;
103
106
 
104
107
  declare type GTFile = {
@@ -111,7 +114,7 @@ declare type GTFile = {
111
114
  *
112
115
  * ```ts
113
116
  * import {defineConfig} from 'sanity'
114
- * import {gtPlugin} from '@generaltranslation/sanity'
117
+ * import {gtPlugin} from 'gt-sanity'
115
118
  *
116
119
  * export default defineConfig({
117
120
  * // ...
@@ -119,26 +122,31 @@ declare type GTFile = {
119
122
  * })
120
123
  * ```
121
124
  */
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
- >;
125
+ export declare const gtPlugin: Plugin_2<GTPluginConfig>;
126
+
127
+ export declare type GTPluginConfig = Omit<
128
+ Parameters<typeof gt.setConfig>[0],
129
+ 'locales'
130
+ > & {
131
+ locales: string[];
132
+ singletons?: string[];
133
+ singletonMapping?: (sourceDocumentId: string, locale: string) => string;
134
+ ignoreFields?: IgnoreFields[];
135
+ languageField?: string;
136
+ translateDocuments?: TranslateDocumentFilter[];
137
+ secretsNamespace?: string;
138
+ };
139
139
 
140
140
  declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
141
141
 
142
+ declare type IgnoreFields = {
143
+ documentId?: string;
144
+ fields?: {
145
+ property: string;
146
+ type?: string;
147
+ }[];
148
+ };
149
+
142
150
  export declare type ImportTranslation = (
143
151
  documentInfo: GTFile,
144
152
  localeId: string,
@@ -152,16 +160,8 @@ export declare type ImportTranslation = (
152
160
  additionalBlockDeserializers?: DeserializerRule[];
153
161
  },
154
162
  languageField?: string,
155
- mergeWithTargetLocale?: boolean
156
- ) => Promise<void>;
157
-
158
- export declare const legacyDocumentLevelConfig: ConfigOptions;
159
-
160
- export declare const legacyDocumentLevelPatch: (
161
- docInfo: GTFile,
162
- translatedFields: SanityDocument,
163
- localeId: string,
164
- client: SanityClient
163
+ mergeWithTargetLocale?: boolean,
164
+ publish?: boolean
165
165
  ) => Promise<void>;
166
166
 
167
167
  export declare type Secrets = {
@@ -176,6 +176,11 @@ export declare type Secrets = {
176
176
 
177
177
  export { SerializedDocument };
178
178
 
179
+ declare type TranslateDocumentFilter = {
180
+ documentId?: string;
181
+ type?: string;
182
+ };
183
+
179
184
  export declare interface TranslationFunctionContext {
180
185
  client: SanityClient;
181
186
  schema: Schema;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { BaseDocumentDeserializer } from 'sanity-naive-html-serializer';
2
2
  import { BaseDocumentMerger } from 'sanity-naive-html-serializer';
3
3
  import { BaseDocumentSerializer } from 'sanity-naive-html-serializer';
4
- import { CustomMapping } from 'generaltranslation/types';
5
4
  import { customSerializers } from 'sanity-naive-html-serializer';
6
5
  import { defaultStopTypes } from 'sanity-naive-html-serializer';
7
6
  import { DeserializerRule } from '@sanity/block-tools';
7
+ import { GT } from 'generaltranslation';
8
8
  import { JSX } from 'react';
9
9
  import { Plugin as Plugin_2 } from 'sanity';
10
10
  import { PortableTextTypeComponent } from '@portabletext/to-html';
@@ -70,7 +70,8 @@ export declare const documentLevelPatch: (
70
70
  localeId: string,
71
71
  client: SanityClient,
72
72
  languageField?: string,
73
- mergeWithTargetLocale?: boolean
73
+ mergeWithTargetLocale?: boolean,
74
+ publish?: boolean
74
75
  ) => Promise<void>;
75
76
 
76
77
  export declare type ExportForTranslation = (
@@ -99,6 +100,8 @@ export declare const findLatestDraft: (
99
100
  client: SanityClient
100
101
  ) => Promise<SanityDocument>;
101
102
 
103
+ declare const gt: GT;
104
+
102
105
  export declare const GTAdapter: Adapter;
103
106
 
104
107
  declare type GTFile = {
@@ -111,7 +114,7 @@ declare type GTFile = {
111
114
  *
112
115
  * ```ts
113
116
  * import {defineConfig} from 'sanity'
114
- * import {gtPlugin} from '@generaltranslation/sanity'
117
+ * import {gtPlugin} from 'gt-sanity'
115
118
  *
116
119
  * export default defineConfig({
117
120
  * // ...
@@ -119,26 +122,31 @@ declare type GTFile = {
119
122
  * })
120
123
  * ```
121
124
  */
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
- >;
125
+ export declare const gtPlugin: Plugin_2<GTPluginConfig>;
126
+
127
+ export declare type GTPluginConfig = Omit<
128
+ Parameters<typeof gt.setConfig>[0],
129
+ 'locales'
130
+ > & {
131
+ locales: string[];
132
+ singletons?: string[];
133
+ singletonMapping?: (sourceDocumentId: string, locale: string) => string;
134
+ ignoreFields?: IgnoreFields[];
135
+ languageField?: string;
136
+ translateDocuments?: TranslateDocumentFilter[];
137
+ secretsNamespace?: string;
138
+ };
139
139
 
140
140
  declare type GTSerializedDocument = Omit<SerializedDocument, 'name'> & GTFile;
141
141
 
142
+ declare type IgnoreFields = {
143
+ documentId?: string;
144
+ fields?: {
145
+ property: string;
146
+ type?: string;
147
+ }[];
148
+ };
149
+
142
150
  export declare type ImportTranslation = (
143
151
  documentInfo: GTFile,
144
152
  localeId: string,
@@ -152,16 +160,8 @@ export declare type ImportTranslation = (
152
160
  additionalBlockDeserializers?: DeserializerRule[];
153
161
  },
154
162
  languageField?: string,
155
- mergeWithTargetLocale?: boolean
156
- ) => Promise<void>;
157
-
158
- export declare const legacyDocumentLevelConfig: ConfigOptions;
159
-
160
- export declare const legacyDocumentLevelPatch: (
161
- docInfo: GTFile,
162
- translatedFields: SanityDocument,
163
- localeId: string,
164
- client: SanityClient
163
+ mergeWithTargetLocale?: boolean,
164
+ publish?: boolean
165
165
  ) => Promise<void>;
166
166
 
167
167
  export declare type Secrets = {
@@ -176,6 +176,11 @@ export declare type Secrets = {
176
176
 
177
177
  export { SerializedDocument };
178
178
 
179
+ declare type TranslateDocumentFilter = {
180
+ documentId?: string;
181
+ type?: string;
182
+ };
183
+
179
184
  export declare interface TranslationFunctionContext {
180
185
  client: SanityClient;
181
186
  schema: Schema;