sanity-plugin-studio-smartling 1.1.6 → 1.4.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/src/index.ts CHANGED
@@ -2,48 +2,44 @@ import { TranslationsTab } from 'sanity-translations-tab'
2
2
  import {
3
3
  BaseDocumentDeserializer,
4
4
  BaseDocumentSerializer,
5
- BaseDocumentPatcher,
5
+ BaseDocumentMerger,
6
6
  defaultStopTypes,
7
7
  customSerializers,
8
8
  } from 'sanity-naive-html-serializer'
9
9
  import { SmartlingAdapter } from './adapter'
10
+ import { findLatestDraft, documentLevelPatch, fieldLevelPatch } from './helpers'
11
+ import { SanityDocument } from '@sanity/types'
10
12
 
11
13
  const defaultDocumentLevelConfig = {
12
- exportForTranslation: (id: string) =>
13
- BaseDocumentSerializer.serializeDocument(
14
- id,
15
- 'document',
16
- 'en',
17
- defaultStopTypes,
18
- customSerializers
19
- ),
14
+ exportForTranslation: async (id: string) => {
15
+ const doc = await findLatestDraft(id)
16
+ const serialized = BaseDocumentSerializer.serializeDocument(doc, 'document')
17
+ //needed for lookup by translation tab
18
+ serialized.name = id
19
+ return serialized
20
+ },
20
21
  importTranslation: (id: string, localeId: string, document: string) => {
21
- return BaseDocumentDeserializer.deserializeDocument(
22
- id,
22
+ const deserialized = BaseDocumentDeserializer.deserializeDocument(
23
23
  document
24
- ).then((deserialized: Record<string, any>) =>
25
- BaseDocumentPatcher.documentLevelPatch(deserialized, id, localeId)
26
- )
24
+ ) as SanityDocument
25
+ documentLevelPatch(id, deserialized, localeId)
27
26
  },
28
27
  adapter: SmartlingAdapter,
29
28
  }
30
29
 
31
30
  const defaultFieldLevelConfig = {
32
- exportForTranslation: (id: string) =>
33
- BaseDocumentSerializer.serializeDocument(
34
- id,
35
- 'field',
36
- 'en',
37
- defaultStopTypes,
38
- customSerializers
39
- ),
31
+ exportForTranslation: async (id: string) => {
32
+ const doc = await findLatestDraft(id)
33
+ const serialized = BaseDocumentSerializer.serializeDocument(doc, 'field')
34
+ //needed for lookup by translation tab
35
+ serialized.name = id
36
+ return serialized
37
+ },
40
38
  importTranslation: (id: string, localeId: string, document: string) => {
41
- return BaseDocumentDeserializer.deserializeDocument(
42
- id,
39
+ const deserialized = BaseDocumentDeserializer.deserializeDocument(
43
40
  document
44
- ).then((deserialized: Record<string, any>) =>
45
- BaseDocumentPatcher.fieldLevelPatch(deserialized, id, localeId, 'en')
46
- )
41
+ ) as SanityDocument
42
+ fieldLevelPatch(id, deserialized, localeId)
47
43
  },
48
44
  adapter: SmartlingAdapter,
49
45
  }
@@ -52,7 +48,7 @@ export {
52
48
  TranslationsTab,
53
49
  BaseDocumentDeserializer,
54
50
  BaseDocumentSerializer,
55
- BaseDocumentPatcher,
51
+ BaseDocumentMerger,
56
52
  defaultStopTypes,
57
53
  customSerializers,
58
54
  SmartlingAdapter,