gt-sanity 2.0.21 → 2.1.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/dist/index.cjs +1220 -763
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -1
- package/dist/index.d.ts +113 -1
- package/dist/index.js +1211 -754
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter/core.ts +27 -2
- package/src/adapter/types.ts +9 -0
- package/src/components/TranslationsProvider.tsx +92 -6
- package/src/components/page/TranslationsTable.tsx +5 -3
- package/src/components/shared/SingleDocumentView.tsx +5 -3
- package/src/components/tab/TranslationView.tsx +24 -14
- package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +1 -1
- package/src/configuration/baseFieldLevelConfig.ts +1 -1
- package/src/configuration/internationalizedArrayConfig/internationalizedArrayPatch.ts +59 -0
- package/src/index.ts +114 -58
- package/src/schema/InternationalizedArrayInput.tsx +278 -0
- package/src/schema/__tests__/createInternationalizedArrayTypes.test.ts +169 -0
- package/src/schema/createInternationalizedArrayTypes.ts +209 -0
- package/src/schema/types.ts +84 -0
- package/src/serialization/__tests__/BaseDocumentDeserializer/baseDeserialization.test.ts +3 -3
- package/src/serialization/__tests__/BaseDocumentMerger/baseMerge.test.ts +1 -1
- package/src/serialization/__tests__/BaseDocumentMerger/documentLevelMerge.test.ts +1 -1
- package/src/serialization/__tests__/BaseDocumentMerger/fieldLevelMerge.test.ts +1 -1
- package/src/serialization/__tests__/BaseDocumentSerializer/baseSerialization.test.ts +2 -2
- package/src/serialization/__tests__/BaseDocumentSerializer/documentInlineMarks.test.ts +4 -2
- package/src/serialization/__tests__/global.setup.ts +6 -0
- package/src/serialization/__tests__/helpers.ts +2 -1
- package/src/serialization/internationalizedArray/__tests__/internationalizedArray.test.ts +265 -0
- package/src/serialization/internationalizedArray/__tests__/serializeRoundTrip.test.ts +83 -0
- package/src/serialization/internationalizedArray/collapse.ts +52 -0
- package/src/serialization/internationalizedArray/detect.ts +81 -0
- package/src/serialization/internationalizedArray/merge.ts +149 -0
- package/src/serialization/types.ts +5 -1
- package/src/translation/__tests__/strategy.test.ts +47 -0
- package/src/translation/importDocument.ts +9 -5
- package/src/translation/strategy.ts +92 -0
- package/src/translation/uploadFiles.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/__tests__/batchProcessor.test.ts +61 -2
- package/src/utils/batchProcessor.ts +11 -6
- package/src/utils/serialize.ts +24 -7
- package/src/serialization/index.ts +0 -16
package/src/utils/serialize.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { SanityDocument, Schema } from 'sanity';
|
|
2
|
+
import { BaseDocumentDeserializer } from '../serialization/deserialize/BaseDocumentDeserializer';
|
|
3
|
+
import { BaseDocumentSerializer } from '../serialization/serialize/index';
|
|
2
4
|
import {
|
|
3
|
-
BaseDocumentDeserializer,
|
|
4
|
-
BaseDocumentSerializer,
|
|
5
5
|
defaultStopTypes,
|
|
6
6
|
customSerializers,
|
|
7
7
|
customBlockDeserializers,
|
|
8
|
-
} from '../serialization/';
|
|
8
|
+
} from '../serialization/BaseSerializationConfig';
|
|
9
9
|
import { PortableTextHtmlComponents } from '@portabletext/to-html';
|
|
10
10
|
import { pluginConfig } from '../adapter/core';
|
|
11
11
|
import merge from 'lodash.merge';
|
|
12
12
|
import { deleteMatchingFields } from './applyDocuments';
|
|
13
13
|
import type { FieldMatcher } from '../adapter/types';
|
|
14
14
|
import { getPublishedId } from './documentIds';
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
CustomDeserializers,
|
|
17
|
+
TranslationLevel,
|
|
18
|
+
} from '../serialization/types';
|
|
19
|
+
import { collapseToSourceLocale } from '../serialization/internationalizedArray/collapse';
|
|
16
20
|
|
|
17
21
|
export function deserializeDocument(document: string) {
|
|
18
22
|
const deserializers = merge(
|
|
@@ -34,7 +38,8 @@ export function deserializeDocument(document: string) {
|
|
|
34
38
|
export function serializeDocument(
|
|
35
39
|
document: SanityDocument,
|
|
36
40
|
schema: Schema,
|
|
37
|
-
baseLanguage: string
|
|
41
|
+
baseLanguage: string,
|
|
42
|
+
level: TranslationLevel = 'document'
|
|
38
43
|
) {
|
|
39
44
|
const stopTypes = [
|
|
40
45
|
...defaultStopTypes,
|
|
@@ -45,15 +50,27 @@ export function serializeDocument(
|
|
|
45
50
|
pluginConfig.getAdditionalSerializers()
|
|
46
51
|
) satisfies Partial<PortableTextHtmlComponents>;
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
let docToSerialize = stripIgnoredFields(
|
|
49
54
|
document,
|
|
50
55
|
pluginConfig.getIgnoreFields(),
|
|
51
56
|
pluginConfig.getDedupeFields()
|
|
52
57
|
);
|
|
53
58
|
|
|
59
|
+
// The internationalized-array model collapses each localized field down to
|
|
60
|
+
// its source-locale value, then serializes through the standard document
|
|
61
|
+
// path so the existing HTML format and deserializer are reused as-is.
|
|
62
|
+
let innerLevel: TranslationLevel = level;
|
|
63
|
+
if (level === 'internationalizedArray') {
|
|
64
|
+
docToSerialize = collapseToSourceLocale(
|
|
65
|
+
docToSerialize,
|
|
66
|
+
baseLanguage
|
|
67
|
+
) as SanityDocument;
|
|
68
|
+
innerLevel = 'document';
|
|
69
|
+
}
|
|
70
|
+
|
|
54
71
|
const serialized = BaseDocumentSerializer(schema).serializeDocument(
|
|
55
72
|
docToSerialize,
|
|
56
|
-
|
|
73
|
+
innerLevel,
|
|
57
74
|
baseLanguage,
|
|
58
75
|
stopTypes,
|
|
59
76
|
serializers
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { BaseDocumentMerger } from './BaseDocumentMerger';
|
|
2
|
-
export { BaseDocumentSerializer } from './serialize';
|
|
3
|
-
export { BaseDocumentDeserializer } from './deserialize/BaseDocumentDeserializer';
|
|
4
|
-
export {
|
|
5
|
-
defaultStopTypes,
|
|
6
|
-
customSerializers,
|
|
7
|
-
customBlockDeserializers,
|
|
8
|
-
} from './BaseSerializationConfig';
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
CustomDeserializers,
|
|
12
|
-
SerializedDocument,
|
|
13
|
-
Deserializer,
|
|
14
|
-
Merger,
|
|
15
|
-
} from './types';
|
|
16
|
-
export { attachGTData, detachGTData } from './data';
|