gt-sanity 0.0.6 → 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 (88) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/index.d.mts +95 -73
  3. package/dist/index.d.ts +95 -73
  4. package/dist/index.js +9066 -1207
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +9083 -1197
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +8 -3
  9. package/src/adapter/core.ts +41 -4
  10. package/src/adapter/getLocales.ts +2 -2
  11. package/src/components/TranslationsProvider.tsx +942 -0
  12. package/src/components/page/BatchProgress.tsx +27 -0
  13. package/src/components/page/ImportAllDialog.tsx +51 -0
  14. package/src/components/page/ImportMissingDialog.tsx +55 -0
  15. package/src/components/page/TranslateAllDialog.tsx +55 -0
  16. package/src/components/page/TranslationsTable.tsx +81 -0
  17. package/src/components/page/TranslationsTool.tsx +299 -837
  18. package/src/components/shared/BaseTranslationWrapper.tsx +82 -0
  19. package/src/components/shared/LocaleCheckbox.tsx +47 -0
  20. package/src/components/shared/SingleDocumentView.tsx +108 -0
  21. package/src/components/tab/TranslationView.tsx +379 -0
  22. package/src/components/tab/TranslationsTab.tsx +25 -0
  23. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +6 -9
  24. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +5 -24
  25. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +3 -23
  26. package/src/configuration/baseDocumentLevelConfig/index.ts +16 -68
  27. package/src/configuration/baseFieldLevelConfig.ts +15 -50
  28. package/src/index.ts +29 -43
  29. package/src/sanity-api/findDocuments.ts +44 -0
  30. package/src/sanity-api/publishDocuments.ts +49 -0
  31. package/src/sanity-api/resolveRefs.ts +146 -0
  32. package/src/serialization/BaseDocumentMerger.ts +138 -0
  33. package/src/serialization/BaseSerializationConfig.ts +220 -0
  34. package/src/serialization/__tests__/BaseDocumentDeserializer/__snapshots__/documentLevelDeserialization.test.ts.snap +189 -0
  35. package/src/serialization/__tests__/BaseDocumentDeserializer/__snapshots__/fieldLevelDeserialization.test.ts.snap +107 -0
  36. package/src/serialization/__tests__/BaseDocumentDeserializer/baseDeserialization.test.ts +397 -0
  37. package/src/serialization/__tests__/BaseDocumentDeserializer/documentLevelDeserialization.test.ts +107 -0
  38. package/src/serialization/__tests__/BaseDocumentDeserializer/fieldLevelDeserialization.test.ts +107 -0
  39. package/src/serialization/__tests__/BaseDocumentMerger/__snapshots__/documentLevelMerge.test.ts.snap +193 -0
  40. package/src/serialization/__tests__/BaseDocumentMerger/__snapshots__/fieldLevelMerge.test.ts.snap +97 -0
  41. package/src/serialization/__tests__/BaseDocumentMerger/baseMerge.test.ts +36 -0
  42. package/src/serialization/__tests__/BaseDocumentMerger/documentLevelMerge.test.ts +96 -0
  43. package/src/serialization/__tests__/BaseDocumentMerger/fieldLevelMerge.test.ts +142 -0
  44. package/src/serialization/__tests__/BaseDocumentMerger/utils.ts +52 -0
  45. package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/documentInlineMarks.test.ts.snap +39 -0
  46. package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/documentLevelSerialization.test.ts.snap +8 -0
  47. package/src/serialization/__tests__/BaseDocumentSerializer/__snapshots__/fieldLevelSerialization.test.ts.snap +8 -0
  48. package/src/serialization/__tests__/BaseDocumentSerializer/baseSerialization.test.ts +345 -0
  49. package/src/serialization/__tests__/BaseDocumentSerializer/documentInlineMarks.test.ts +53 -0
  50. package/src/serialization/__tests__/BaseDocumentSerializer/documentLevelSerialization.test.ts +120 -0
  51. package/src/serialization/__tests__/BaseDocumentSerializer/fieldLevelSerialization.test.ts +153 -0
  52. package/src/serialization/__tests__/BaseDocumentSerializer/utils.ts +27 -0
  53. package/src/serialization/__tests__/README +2 -0
  54. package/src/serialization/__tests__/__fixtures__/annotationAndInlineBlocks.json +140 -0
  55. package/src/serialization/__tests__/__fixtures__/customStyles.json +62 -0
  56. package/src/serialization/__tests__/__fixtures__/documentInlineMarks.json +70 -0
  57. package/src/serialization/__tests__/__fixtures__/documentLevelArticle.json +185 -0
  58. package/src/serialization/__tests__/__fixtures__/fieldLevelArticle.json +107 -0
  59. package/src/serialization/__tests__/__fixtures__/inlineDocumentLevelArticle.json +134 -0
  60. package/src/serialization/__tests__/__fixtures__/inlineSchema.ts +270 -0
  61. package/src/serialization/__tests__/__fixtures__/messy-html.html +26 -0
  62. package/src/serialization/__tests__/__fixtures__/nestedLanguageFields.json +54 -0
  63. package/src/serialization/__tests__/__fixtures__/schema.ts +310 -0
  64. package/src/serialization/__tests__/global.setup.ts +40 -0
  65. package/src/serialization/__tests__/helpers.ts +132 -0
  66. package/src/serialization/data.ts +82 -0
  67. package/src/serialization/deserialize/BaseDocumentDeserializer.ts +171 -0
  68. package/src/serialization/deserialize/helpers.ts +42 -0
  69. package/src/serialization/helpers.ts +18 -0
  70. package/src/serialization/index.ts +11 -0
  71. package/src/serialization/serialize/fieldFilters.ts +124 -0
  72. package/src/serialization/serialize/index.ts +284 -0
  73. package/src/serialization/types.ts +41 -0
  74. package/src/translation/importDocument.ts +4 -5
  75. package/src/translation/uploadFiles.ts +1 -1
  76. package/src/types.ts +3 -19
  77. package/src/utils/batchProcessor.ts +111 -0
  78. package/src/utils/importUtils.ts +95 -0
  79. package/src/utils/serialize.ts +25 -5
  80. package/src/utils/shared.ts +1 -1
  81. package/src/adapter/index.ts +0 -13
  82. package/src/components/NewTask.tsx +0 -251
  83. package/src/components/TaskView.tsx +0 -257
  84. package/src/components/TranslationContext.tsx +0 -24
  85. package/src/components/TranslationView.tsx +0 -114
  86. package/src/components/TranslationsTab.tsx +0 -181
  87. /package/src/components/{LanguageStatus.tsx → shared/LanguageStatus.tsx} +0 -0
  88. /package/src/components/{ProgressBar.tsx → shared/ProgressBar.tsx} +0 -0
@@ -0,0 +1,107 @@
1
+ {
2
+ "_createdAt": "2021-10-10T23:00:13Z",
3
+ "_id": "drafts.2947533e-1ea5-4116-955b-339608d3445d",
4
+ "_rev": "l58oha-n06-1s4-f6i-74g6cuakl",
5
+ "_type": "fieldLevelArticle",
6
+ "_updatedAt": "2021-10-10T23:02:05Z",
7
+ "slug": {
8
+ "_type": "slug",
9
+ "current": "happy-kitchen-hamburger"
10
+ },
11
+ "config": {
12
+ "en": {
13
+ "_type": "objectField",
14
+ "nestedArrayField": [
15
+ {
16
+ "_key": "f49b4d7e3e51",
17
+ "_type": "block",
18
+ "children": [
19
+ {
20
+ "_key": "a6170f21181c",
21
+ "_type": "span",
22
+ "marks": [],
23
+ "text": "This is block text 1 level deep"
24
+ }
25
+ ],
26
+ "markDefs": [],
27
+ "style": "normal"
28
+ }
29
+ ],
30
+ "objectAsField": {
31
+ "_type": "childObjectField",
32
+ "content": [
33
+ {
34
+ "_key": "869168fe3a2a",
35
+ "_type": "block",
36
+ "children": [
37
+ {
38
+ "_key": "10d423df228a",
39
+ "_type": "span",
40
+ "marks": [],
41
+ "text": "This is block text 2 levels deep"
42
+ }
43
+ ],
44
+ "markDefs": [],
45
+ "style": "normal"
46
+ }
47
+ ],
48
+ "title": "This is one level deeper"
49
+ },
50
+ "title": "This is an object nested in a document"
51
+ }
52
+ },
53
+ "content": {
54
+ "en": [
55
+ {
56
+ "_key": "e2a39d768ff8",
57
+ "_type": "block",
58
+ "children": [
59
+ {
60
+ "_key": "216e97c5a5cc",
61
+ "_type": "span",
62
+ "marks": [],
63
+ "text": "This is block text at the top level."
64
+ }
65
+ ],
66
+ "markDefs": [],
67
+ "style": "normal"
68
+ },
69
+ {
70
+ "_key": "271b0c6ee984",
71
+ "_type": "objectField",
72
+ "objectAsField": {
73
+ "_type": "childObjectField",
74
+ "content": [
75
+ {
76
+ "_key": "4f24f6fbfae7",
77
+ "_type": "block",
78
+ "children": [
79
+ {
80
+ "_key": "d68f4288f5b7",
81
+ "_type": "span",
82
+ "marks": [],
83
+ "text": "This is block text in a nested object in an object in top-level block text."
84
+ }
85
+ ],
86
+ "markDefs": [],
87
+ "style": "normal"
88
+ }
89
+ ],
90
+ "title": "This is a nested object in an object in top-level block text."
91
+ },
92
+ "title": "This is an object in top-level block text."
93
+ }
94
+ ]
95
+ },
96
+ "hidden": true,
97
+ "meta": "Do not translate this",
98
+ "snippet": {
99
+ "en": "This is text in my text field"
100
+ },
101
+ "tags": {
102
+ "en": ["tag 1", "tag 2", "tag 3"]
103
+ },
104
+ "title": {
105
+ "en": "My Field-Level Article"
106
+ }
107
+ }
@@ -0,0 +1,134 @@
1
+ {
2
+ "_id": "drafts.d8ffc675-ce86-4f60-9ac8-da164cde3b0a",
3
+ "_rev": "fxcnqj-uew-gr7-v6r-z965tfm69",
4
+ "_type": "documentLevelArticle",
5
+ "_createdAt": "2021-09-01T23:00:13Z",
6
+ "_updatedAt": "2021-09-01T23:02:05Z",
7
+ "tabs": {
8
+ "_type": "object",
9
+ "config": {
10
+ "_type": "objectField",
11
+ "nestedArrayField": [
12
+ {
13
+ "_key": "4a58adc7c507",
14
+ "_type": "block",
15
+ "children": [
16
+ {
17
+ "_key": "4f6bc15ae261",
18
+ "_type": "span",
19
+ "marks": [],
20
+ "text": "This is block text 1 level deep"
21
+ }
22
+ ],
23
+ "markDefs": [],
24
+ "style": "normal"
25
+ }
26
+ ],
27
+ "objectAsField": {
28
+ "_type": "object",
29
+ "content": [
30
+ {
31
+ "_key": "1aa228ac848b",
32
+ "_type": "block",
33
+ "children": [
34
+ {
35
+ "_key": "e2cf67af8e62",
36
+ "_type": "span",
37
+ "marks": [],
38
+ "text": "This is a block text 2 levels deep"
39
+ }
40
+ ],
41
+ "markDefs": [],
42
+ "style": "normal"
43
+ }
44
+ ],
45
+ "title": "This is one level deeper"
46
+ },
47
+ "title": "This is an object nested in a document"
48
+ },
49
+ "content": [
50
+ {
51
+ "_key": "a4d177e92666",
52
+ "_type": "block",
53
+ "children": [
54
+ {
55
+ "_key": "a896ea6fcd59",
56
+ "_type": "span",
57
+ "marks": [],
58
+ "text": "This is block text at the top level."
59
+ }
60
+ ],
61
+ "markDefs": [],
62
+ "style": "normal"
63
+ },
64
+ {
65
+ "_key": "c0313627775e",
66
+ "_type": "objectField",
67
+ "objectAsField": {
68
+ "_type": "childObjectField",
69
+ "content": [
70
+ {
71
+ "_key": "4f24f6fbfae7",
72
+ "_type": "block",
73
+ "children": [
74
+ {
75
+ "_key": "d68f4288f5b7",
76
+ "_type": "span",
77
+ "marks": [],
78
+ "text": "This is block text in a nested object in an object in top-level block text."
79
+ }
80
+ ],
81
+ "markDefs": [],
82
+ "style": "normal"
83
+ }
84
+ ],
85
+ "title": "This is a nested object in an object in top-level block text."
86
+ },
87
+ "title": "This is an object in top-level block text."
88
+ },
89
+ {
90
+ "_key": "9e2ab13c6d63",
91
+ "_type": "block",
92
+ "children": [
93
+ {
94
+ "_key": "17e856dc4766",
95
+ "_type": "span",
96
+ "marks": [],
97
+ "text": "This is h1 text"
98
+ }
99
+ ],
100
+ "markDefs": [],
101
+ "style": "h1"
102
+ },
103
+ {
104
+ "_key": "297142fbaf21",
105
+ "_type": "block",
106
+ "children": [
107
+ {
108
+ "_key": "0b2f9e94a161",
109
+ "_type": "span",
110
+ "marks": [],
111
+ "text": "This is h2 text"
112
+ }
113
+ ],
114
+ "markDefs": [],
115
+ "style": "h2"
116
+ }
117
+ ],
118
+ "hidden": true,
119
+ "meta": "Do not translate this",
120
+ "snippet": "This is text in my text field.",
121
+ "tags": ["tag 1", "tag 2", "tag 3"],
122
+ "title": "My Document-Level Article",
123
+ "arrayWithAnonymousObjects": [
124
+ {
125
+ "_key": "4c146e0ab346",
126
+ "cells": ["Standard", "Americas", "EMEA"]
127
+ },
128
+ {
129
+ "_key": "038f8c197939",
130
+ "cells": ["Friends", "Family", "Other"]
131
+ }
132
+ ]
133
+ }
134
+ }
@@ -0,0 +1,270 @@
1
+ import { Schema } from '@sanity/schema';
2
+
3
+ const arrayField = {
4
+ name: 'arrayField',
5
+ title: 'Array Field',
6
+ type: 'array',
7
+ of: [
8
+ { type: 'block' },
9
+ {
10
+ type: 'object',
11
+ fields: [
12
+ {
13
+ name: 'title',
14
+ title: 'Title',
15
+ type: 'string',
16
+ },
17
+ {
18
+ name: 'objectAsField',
19
+ title: 'Object As Field',
20
+ type: 'object',
21
+ fields: [
22
+ {
23
+ name: 'title',
24
+ title: 'Title',
25
+ type: 'string',
26
+ },
27
+ {
28
+ name: 'content',
29
+ title: 'Content',
30
+ type: 'array',
31
+ of: [{ type: 'block' }],
32
+ },
33
+ ],
34
+ },
35
+ {
36
+ name: 'nestedArrayField',
37
+ title: 'Nested Array Field',
38
+ type: 'array',
39
+ of: [{ type: 'block' }, { type: 'childObjectField' }],
40
+ },
41
+ ],
42
+ },
43
+ ],
44
+ };
45
+
46
+ const childObjectField = {
47
+ name: 'childObjectField',
48
+ title: 'Child Object Field',
49
+ type: 'object',
50
+ fields: [
51
+ {
52
+ name: 'title',
53
+ title: 'Title',
54
+ type: 'string',
55
+ },
56
+ {
57
+ name: 'content',
58
+ title: 'Content',
59
+ type: 'array',
60
+ of: [{ type: 'block' }],
61
+ },
62
+ ],
63
+ };
64
+
65
+ const objectField = {
66
+ name: 'objectField',
67
+ title: 'Object Field',
68
+ type: 'object',
69
+ fields: [
70
+ {
71
+ name: 'title',
72
+ title: 'Title',
73
+ type: 'string',
74
+ },
75
+ {
76
+ name: 'objectAsField',
77
+ title: 'Object As Field',
78
+ type: 'object',
79
+ fields: [
80
+ {
81
+ name: 'title',
82
+ title: 'Title',
83
+ type: 'string',
84
+ },
85
+ {
86
+ name: 'content',
87
+ title: 'Content',
88
+ type: 'array',
89
+ of: [{ type: 'block' }],
90
+ },
91
+ ],
92
+ },
93
+ {
94
+ name: 'nestedArrayField',
95
+ title: 'Nested Array Field',
96
+ type: 'array',
97
+ of: [{ type: 'block' }, { type: 'childObjectField' }],
98
+ },
99
+ ],
100
+ };
101
+
102
+ const documentLevelArticle = {
103
+ name: 'documentLevelArticle',
104
+ title: 'Document Level Article',
105
+ type: 'document',
106
+ fields: [
107
+ {
108
+ name: 'tabs',
109
+ type: 'object',
110
+ fields: [
111
+ {
112
+ name: 'title',
113
+ title: 'Title',
114
+ type: 'string',
115
+ },
116
+ {
117
+ name: 'meta',
118
+ title: 'Meta',
119
+ type: 'string',
120
+ localize: false,
121
+ },
122
+ {
123
+ name: 'snippet',
124
+ title: 'Snippet',
125
+ type: 'text',
126
+ },
127
+ {
128
+ name: 'tags',
129
+ title: 'Tags',
130
+ type: 'array',
131
+ of: [{ type: 'string' }],
132
+ },
133
+ {
134
+ name: 'hidden',
135
+ title: 'Hidden',
136
+ type: 'boolean',
137
+ },
138
+ {
139
+ name: 'config',
140
+ title: 'Config',
141
+ type: 'objectField',
142
+ },
143
+ {
144
+ name: 'content',
145
+ title: 'Content',
146
+ type: 'arrayField',
147
+ },
148
+ ],
149
+ },
150
+ ],
151
+ };
152
+
153
+ function createLocaleFields(locales: string[], fieldType: Record<string, any>) {
154
+ return locales.map((locale) => ({
155
+ ...{ name: locale },
156
+ ...fieldType,
157
+ }));
158
+ }
159
+
160
+ const fieldLevelArticle = {
161
+ name: 'fieldLevelArticle',
162
+ title: 'Field Level Article',
163
+ type: 'document',
164
+ fields: [
165
+ {
166
+ name: 'title',
167
+ title: 'Title',
168
+ type: 'localeString',
169
+ },
170
+ {
171
+ name: 'meta',
172
+ title: 'Meta',
173
+ type: 'string',
174
+ localize: false,
175
+ },
176
+ {
177
+ name: 'snippet',
178
+ title: 'Snippet',
179
+ type: 'object',
180
+ fields: createLocaleFields(['en', 'fr', 'de'], { type: 'text' }),
181
+ },
182
+ {
183
+ name: 'tags',
184
+ title: 'Tags',
185
+ type: 'object',
186
+ fields: createLocaleFields(['en', 'fr', 'de'], {
187
+ type: 'array',
188
+ of: [{ type: 'string' }],
189
+ }),
190
+ },
191
+ {
192
+ name: 'hidden',
193
+ title: 'Hidden',
194
+ type: 'boolean',
195
+ },
196
+ {
197
+ name: 'config',
198
+ title: 'Config',
199
+ type: 'object',
200
+ fields: createLocaleFields(['en', 'fr', 'de'], { type: 'objectField' }),
201
+ },
202
+ {
203
+ name: 'content',
204
+ title: 'Content',
205
+ type: 'object',
206
+ fields: createLocaleFields(['en', 'fr', 'de'], { type: 'arrayField' }),
207
+ },
208
+ {
209
+ name: 'slices',
210
+ title: 'Slices',
211
+ type: 'array',
212
+ of: [
213
+ { type: 'localeBlock' },
214
+ { type: 'reference', to: [{ type: 'marketText' }] },
215
+ ],
216
+ },
217
+ {
218
+ name: 'pageFields',
219
+ title: 'Page Fields',
220
+ type: 'pageFields',
221
+ },
222
+ ],
223
+ };
224
+
225
+ const localeBlock = {
226
+ name: 'localeBlock',
227
+ title: 'Locale Block',
228
+ type: 'object',
229
+ fields: createLocaleFields(['en', 'fr_FR', 'de_DE'], { type: 'arrayField' }),
230
+ };
231
+
232
+ const localeString = {
233
+ name: 'localeString',
234
+ title: 'Locale String',
235
+ type: 'object',
236
+ fields: createLocaleFields(['en', 'fr_FR', 'de_DE'], { type: 'string' }),
237
+ };
238
+
239
+ const pageFields = {
240
+ name: 'pageFields',
241
+ title: 'Page Fields',
242
+ type: 'object',
243
+ fields: [
244
+ {
245
+ title: 'Page Name',
246
+ name: 'name',
247
+ type: 'localeString',
248
+ },
249
+ {
250
+ name: 'slug',
251
+ type: 'string',
252
+ },
253
+ ],
254
+ };
255
+
256
+ const types = [
257
+ arrayField,
258
+ childObjectField,
259
+ objectField,
260
+ documentLevelArticle,
261
+ fieldLevelArticle,
262
+ pageFields,
263
+ localeBlock,
264
+ localeString,
265
+ ];
266
+
267
+ export default new Schema({
268
+ name: 'test',
269
+ types,
270
+ });
@@ -0,0 +1,26 @@
1
+ <html>
2
+ <head>
3
+ <meta name="_id" content="xxx-xxxxxxx-xxxxxx-xxxxx" />
4
+ <meta name="_type" content="article" />
5
+ <meta name="_rev" content="5KevdrlthkOcXnmdCMJjkO" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ </head>
8
+ <body>
9
+ <div class="documentLevelArticle" id="mzeqi4" data-type="object">
10
+ <span class="title">Här är artikel titeln</span>
11
+ <div class="content" data-type="array">
12
+ <p id="e6977d1d9f16">Här är lite content</p>
13
+ <div class="objectField" id="9e505b3b2ab4" data-type="object">
14
+ <div class="nestedArrayField" data-type="array">
15
+ <div class="childObjectField" id="8b2f375c2e7c" data-type="object">
16
+ <span class="title">Det här är en dragspels titeln</span>
17
+ <div class="content" data-type="array">
18
+ <p id="7ac862f38e89">Lite content<br />i vår accordion</p>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,54 @@
1
+ {
2
+ "slices": [
3
+ {
4
+ "_key": "6b9d0b28810f",
5
+ "_type": "localeBlock",
6
+ "en": [
7
+ {
8
+ "_key": "cebb6c538ce0",
9
+ "_type": "block",
10
+ "children": [
11
+ {
12
+ "_key": "48cc6e3b0754",
13
+ "_type": "span",
14
+ "marks": [],
15
+ "text": "This is block text in my slice."
16
+ }
17
+ ],
18
+ "markDefs": [],
19
+ "style": "normal"
20
+ }
21
+ ],
22
+ "fr_FR": [
23
+ {
24
+ "_key": "8bf012dc2eda",
25
+ "_type": "block",
26
+ "children": [
27
+ {
28
+ "_key": "44954c1912e1",
29
+ "_type": "span",
30
+ "marks": [],
31
+ "text": "Ceci est une texte du bloque en mon slice"
32
+ }
33
+ ],
34
+ "markDefs": [],
35
+ "style": "normal"
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "_type": "reference",
41
+ "_key": "13ed4b8013e4",
42
+ "_ref": "66dd1434-23c3-4d94-9e5a-d117775be828"
43
+ }
44
+ ],
45
+ "pageFields": {
46
+ "_type": "pageFields",
47
+ "name": {
48
+ "_type": "localeString",
49
+ "en": "Hello, this is my page name in my page field.",
50
+ "fr_FR": "C'est une field en frances"
51
+ },
52
+ "slug": "current slug"
53
+ }
54
+ }