gt-sanity 0.0.6 → 1.0.1

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 +6233 -1162
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +6292 -1193
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +9 -4
  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,27 @@
1
+ import React from 'react';
2
+ import { Flex, Text, Spinner } from '@sanity/ui';
3
+
4
+ interface BatchProgressProps {
5
+ isActive: boolean;
6
+ current: number;
7
+ total: number;
8
+ operationName: string;
9
+ }
10
+
11
+ export const BatchProgress: React.FC<BatchProgressProps> = ({
12
+ isActive,
13
+ current,
14
+ total,
15
+ operationName,
16
+ }) => {
17
+ if (!isActive) return null;
18
+
19
+ return (
20
+ <Flex justify='center' align='center' gap={3}>
21
+ <Spinner size={1} />
22
+ <Text size={1}>
23
+ {operationName} {current} of {total}...
24
+ </Text>
25
+ </Flex>
26
+ );
27
+ };
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { Box, Button, Dialog, Flex, Stack, Text } from '@sanity/ui';
3
+ import { useTranslations } from '../TranslationsProvider';
4
+
5
+ interface ImportAllDialogProps {
6
+ isOpen: boolean;
7
+ onClose: () => void;
8
+ }
9
+
10
+ export const ImportAllDialog: React.FC<ImportAllDialogProps> = ({
11
+ isOpen,
12
+ onClose,
13
+ }) => {
14
+ const { documents, handleImportAll } = useTranslations();
15
+
16
+ const handleConfirm = async () => {
17
+ onClose();
18
+ await handleImportAll();
19
+ };
20
+
21
+ if (!isOpen) return null;
22
+
23
+ return (
24
+ <Dialog
25
+ header='Confirm Import'
26
+ id='import-all-dialog'
27
+ onClose={onClose}
28
+ footer={
29
+ <Box padding={3}>
30
+ <Flex gap={2}>
31
+ <Button text='Cancel' mode='ghost' onClick={onClose} />
32
+ <Button text='Import All' tone='critical' onClick={handleConfirm} />
33
+ </Flex>
34
+ </Box>
35
+ }
36
+ >
37
+ <Box padding={4}>
38
+ <Stack space={3}>
39
+ <Text>
40
+ Are you sure you want to import translations for all{' '}
41
+ {documents.length} documents?
42
+ </Text>
43
+ <Text size={1} muted>
44
+ This will download and apply translated content to your documents.
45
+ Note that this will overwrite any existing translations!
46
+ </Text>
47
+ </Stack>
48
+ </Box>
49
+ </Dialog>
50
+ );
51
+ };
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { Box, Button, Dialog, Flex, Stack, Text } from '@sanity/ui';
3
+ import { useTranslations } from '../TranslationsProvider';
4
+
5
+ interface ImportMissingDialogProps {
6
+ isOpen: boolean;
7
+ onClose: () => void;
8
+ }
9
+
10
+ export const ImportMissingDialog: React.FC<ImportMissingDialogProps> = ({
11
+ isOpen,
12
+ onClose,
13
+ }) => {
14
+ const { handleImportMissing } = useTranslations();
15
+
16
+ const handleConfirm = async () => {
17
+ onClose();
18
+ await handleImportMissing();
19
+ };
20
+
21
+ if (!isOpen) return null;
22
+
23
+ return (
24
+ <Dialog
25
+ header='Confirm Import Missing'
26
+ id='import-missing-dialog'
27
+ onClose={onClose}
28
+ footer={
29
+ <Box padding={3}>
30
+ <Flex gap={2}>
31
+ <Button text='Cancel' mode='ghost' onClick={onClose} />
32
+ <Button
33
+ text='Import Missing'
34
+ tone='primary'
35
+ onClick={handleConfirm}
36
+ />
37
+ </Flex>
38
+ </Box>
39
+ }
40
+ >
41
+ <Box padding={4}>
42
+ <Stack space={3}>
43
+ <Text>
44
+ Import only the missing translations (translations that are ready
45
+ but haven't been imported to Sanity yet)?
46
+ </Text>
47
+ <Text size={1} muted>
48
+ This will check existing translation metadata and only import
49
+ translations that don't already exist in your dataset.
50
+ </Text>
51
+ </Stack>
52
+ </Box>
53
+ </Dialog>
54
+ );
55
+ };
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { Box, Button, Dialog, Flex, Stack, Text } from '@sanity/ui';
3
+ import { useTranslations } from '../TranslationsProvider';
4
+
5
+ interface TranslateAllDialogProps {
6
+ isOpen: boolean;
7
+ onClose: () => void;
8
+ }
9
+
10
+ export const TranslateAllDialog: React.FC<TranslateAllDialogProps> = ({
11
+ isOpen,
12
+ onClose,
13
+ }) => {
14
+ const { documents, handleTranslateAll } = useTranslations();
15
+
16
+ const handleConfirm = async () => {
17
+ onClose();
18
+ await handleTranslateAll();
19
+ };
20
+
21
+ if (!isOpen) return null;
22
+
23
+ return (
24
+ <Dialog
25
+ header='Confirm Translation'
26
+ id='translate-all-dialog'
27
+ onClose={onClose}
28
+ footer={
29
+ <Box padding={3}>
30
+ <Flex gap={2}>
31
+ <Button text='Cancel' mode='ghost' onClick={onClose} />
32
+ <Button
33
+ text='Translate All'
34
+ tone='critical'
35
+ onClick={handleConfirm}
36
+ />
37
+ </Flex>
38
+ </Box>
39
+ }
40
+ >
41
+ <Box padding={4}>
42
+ <Stack space={3}>
43
+ <Text>
44
+ Are you sure you want to create translations for all{' '}
45
+ {documents.length} documents?
46
+ </Text>
47
+ <Text size={1} muted>
48
+ This will submit all documents to General Translation for
49
+ processing.
50
+ </Text>
51
+ </Stack>
52
+ </Box>
53
+ </Dialog>
54
+ );
55
+ };
@@ -0,0 +1,81 @@
1
+ import React from 'react';
2
+ import { Box, Card, Stack, Text, Flex, Spinner } from '@sanity/ui';
3
+ import { LanguageStatus } from '../shared/LanguageStatus';
4
+ import { useTranslations } from '../TranslationsProvider';
5
+
6
+ export const TranslationsTable: React.FC = () => {
7
+ const {
8
+ documents,
9
+ locales,
10
+ loadingDocuments,
11
+ translationStatuses,
12
+ downloadStatus,
13
+ importedTranslations,
14
+ handleImportDocument,
15
+ } = useTranslations();
16
+
17
+ if (loadingDocuments) {
18
+ return (
19
+ <Flex align='center' justify='center' padding={4}>
20
+ <Spinner />
21
+ </Flex>
22
+ );
23
+ }
24
+
25
+ return (
26
+ <Box style={{ maxHeight: '60vh', overflowY: 'auto' }}>
27
+ <Stack space={2}>
28
+ {documents.map((document) => (
29
+ <Card key={document._id} shadow={1} padding={3}>
30
+ <Stack space={3}>
31
+ <Flex justify='space-between' align='flex-start'>
32
+ <Box flex={1}>
33
+ <Text weight='semibold' size={1}>
34
+ {document._id?.replace('drafts.', '') || document._id}
35
+ </Text>
36
+ <Text size={0} muted style={{ marginTop: '2px' }}>
37
+ {document._type}
38
+ </Text>
39
+ </Box>
40
+ </Flex>
41
+
42
+ <Stack space={2}>
43
+ {locales.length > 0 ? (
44
+ locales
45
+ .filter((locale) => locale.enabled !== false)
46
+ .map((locale) => {
47
+ const documentId =
48
+ document._id?.replace('drafts.', '') || document._id;
49
+ const key = `${documentId}:${locale.localeId}`;
50
+ const status = translationStatuses.get(key);
51
+ const isDownloaded = downloadStatus.downloaded.has(key);
52
+ const isImported = importedTranslations.has(key);
53
+
54
+ return (
55
+ <LanguageStatus
56
+ key={`${document._id}-${locale.localeId}`}
57
+ title={locale.description || locale.localeId}
58
+ progress={status?.progress || 0}
59
+ isImported={isImported || isDownloaded}
60
+ importFile={async () => {
61
+ await handleImportDocument(
62
+ documentId,
63
+ locale.localeId
64
+ );
65
+ }}
66
+ />
67
+ );
68
+ })
69
+ ) : (
70
+ <Text size={1} muted>
71
+ No locales configured
72
+ </Text>
73
+ )}
74
+ </Stack>
75
+ </Stack>
76
+ </Card>
77
+ ))}
78
+ </Stack>
79
+ </Box>
80
+ );
81
+ };