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.
- package/LICENSE.md +1 -1
- package/dist/index.d.mts +95 -73
- package/dist/index.d.ts +95 -73
- package/dist/index.js +9066 -1207
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9083 -1197
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -3
- package/src/adapter/core.ts +41 -4
- package/src/adapter/getLocales.ts +2 -2
- 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 +299 -837
- package/src/components/shared/BaseTranslationWrapper.tsx +82 -0
- package/src/components/shared/LocaleCheckbox.tsx +47 -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 +6 -9
- package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +5 -24
- package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +3 -23
- package/src/configuration/baseDocumentLevelConfig/index.ts +16 -68
- package/src/configuration/baseFieldLevelConfig.ts +15 -50
- package/src/index.ts +29 -43
- 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/importDocument.ts +4 -5
- package/src/translation/uploadFiles.ts +1 -1
- package/src/types.ts +3 -19
- package/src/utils/batchProcessor.ts +111 -0
- package/src/utils/importUtils.ts +95 -0
- package/src/utils/serialize.ts +25 -5
- package/src/utils/shared.ts +1 -1
- package/src/adapter/index.ts +0 -13
- package/src/components/NewTask.tsx +0 -251
- package/src/components/TaskView.tsx +0 -257
- package/src/components/TranslationContext.tsx +0 -24
- package/src/components/TranslationView.tsx +0 -114
- package/src/components/TranslationsTab.tsx +0 -181
- /package/src/components/{LanguageStatus.tsx → shared/LanguageStatus.tsx} +0 -0
- /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
|
+
};
|