@smartcat/sanity-plugin 1.0.0 → 1.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.
Files changed (121) hide show
  1. package/README.md +294 -0
  2. package/dist/_chunks-cjs/constants.cjs +13 -0
  3. package/dist/_chunks-cjs/constants.cjs.map +1 -0
  4. package/dist/_chunks-cjs/index.cjs +174 -0
  5. package/dist/_chunks-cjs/index.cjs.map +1 -0
  6. package/dist/_chunks-cjs/index2.cjs +338 -0
  7. package/dist/_chunks-cjs/index2.cjs.map +1 -0
  8. package/dist/_chunks-cjs/workflow.cjs +16 -0
  9. package/dist/_chunks-cjs/workflow.cjs.map +1 -0
  10. package/dist/_chunks-es/constants.js +14 -0
  11. package/dist/_chunks-es/constants.js.map +1 -0
  12. package/dist/_chunks-es/index.js +175 -0
  13. package/dist/_chunks-es/index.js.map +1 -0
  14. package/dist/_chunks-es/index2.js +340 -0
  15. package/dist/_chunks-es/index2.js.map +1 -0
  16. package/dist/_chunks-es/workflow.js +17 -0
  17. package/dist/_chunks-es/workflow.js.map +1 -0
  18. package/dist/export.cjs +160 -0
  19. package/dist/export.cjs.map +1 -0
  20. package/dist/export.d.cts +162 -0
  21. package/dist/export.d.ts +162 -0
  22. package/dist/export.js +162 -0
  23. package/dist/export.js.map +1 -0
  24. package/dist/import.cjs +169 -0
  25. package/dist/import.cjs.map +1 -0
  26. package/dist/import.d.cts +155 -0
  27. package/dist/import.d.ts +155 -0
  28. package/dist/import.js +169 -0
  29. package/dist/import.js.map +1 -0
  30. package/dist/index.cjs +2172 -0
  31. package/dist/index.cjs.map +1 -0
  32. package/dist/index.d.cts +122 -0
  33. package/dist/index.d.ts +122 -0
  34. package/dist/index.js +2179 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/locjson.cjs +12 -0
  37. package/dist/locjson.cjs.map +1 -0
  38. package/dist/locjson.d.cts +291 -0
  39. package/dist/locjson.d.ts +291 -0
  40. package/dist/locjson.js +12 -0
  41. package/dist/locjson.js.map +1 -0
  42. package/dist/progress.cjs +16 -0
  43. package/dist/progress.cjs.map +1 -0
  44. package/dist/progress.d.cts +277 -0
  45. package/dist/progress.d.ts +277 -0
  46. package/dist/progress.js +16 -0
  47. package/dist/progress.js.map +1 -0
  48. package/dist/smartcat.cjs +287 -0
  49. package/dist/smartcat.cjs.map +1 -0
  50. package/dist/smartcat.d.cts +234 -0
  51. package/dist/smartcat.d.ts +234 -0
  52. package/dist/smartcat.js +287 -0
  53. package/dist/smartcat.js.map +1 -0
  54. package/dist/templates.cjs +12 -0
  55. package/dist/templates.cjs.map +1 -0
  56. package/dist/templates.d.cts +52 -0
  57. package/dist/templates.d.ts +52 -0
  58. package/dist/templates.js +12 -0
  59. package/dist/templates.js.map +1 -0
  60. package/package.json +101 -15
  61. package/src/actions/AddToProjectAction.tsx +274 -0
  62. package/src/export/export.test.ts +537 -0
  63. package/src/export/index.ts +393 -0
  64. package/src/form/TranslationStatusInput.tsx +212 -0
  65. package/src/import/import.test.ts +346 -0
  66. package/src/import/index.ts +418 -0
  67. package/src/index.ts +63 -0
  68. package/src/lib/constants.ts +23 -0
  69. package/src/lib/documentTitle.test.ts +43 -0
  70. package/src/lib/documentTitle.ts +30 -0
  71. package/src/lib/languageMap.test.ts +56 -0
  72. package/src/lib/languageMap.ts +71 -0
  73. package/src/lib/linkedDocuments.test.ts +56 -0
  74. package/src/lib/linkedDocuments.ts +100 -0
  75. package/src/lib/locjson/deserialize.ts +60 -0
  76. package/src/lib/locjson/fields.ts +355 -0
  77. package/src/lib/locjson/filename.ts +34 -0
  78. package/src/lib/locjson/index.ts +10 -0
  79. package/src/lib/locjson/locjson.test.ts +615 -0
  80. package/src/lib/locjson/paths.test.ts +41 -0
  81. package/src/lib/locjson/paths.ts +73 -0
  82. package/src/lib/locjson/portableText.ts +157 -0
  83. package/src/lib/locjson/serialize.ts +124 -0
  84. package/src/lib/locjson/types.ts +106 -0
  85. package/src/lib/log.ts +33 -0
  86. package/src/lib/projectItems.ts +31 -0
  87. package/src/lib/resolveConfig.test.ts +62 -0
  88. package/src/lib/resolveConfig.ts +54 -0
  89. package/src/lib/workflow.test.ts +37 -0
  90. package/src/lib/workflow.ts +48 -0
  91. package/src/lib/zip.fixtures.ts +75 -0
  92. package/src/lib/zip.test.ts +110 -0
  93. package/src/lib/zip.ts +164 -0
  94. package/src/progress/core.ts +409 -0
  95. package/src/progress/index.ts +7 -0
  96. package/src/progress/progress.test.ts +290 -0
  97. package/src/schema/settings.ts +55 -0
  98. package/src/schema/translatableOptions.ts +25 -0
  99. package/src/schema/translationProject.ts +268 -0
  100. package/src/smartcat/client.test.ts +222 -0
  101. package/src/smartcat/client.ts +351 -0
  102. package/src/smartcat/index.ts +10 -0
  103. package/src/smartcat/types.ts +99 -0
  104. package/src/templates/core.ts +55 -0
  105. package/src/templates/index.ts +5 -0
  106. package/src/templates/templates.test.ts +50 -0
  107. package/src/tool/Dashboard.tsx +46 -0
  108. package/src/tool/ItemProgress.tsx +176 -0
  109. package/src/tool/LogPanel.tsx +207 -0
  110. package/src/tool/ProjectView.tsx +1004 -0
  111. package/src/tool/ProjectsView.tsx +208 -0
  112. package/src/tool/StatusBadge.tsx +33 -0
  113. package/src/tool/StudioInit.tsx +42 -0
  114. package/src/tool/WorkflowSelect.tsx +41 -0
  115. package/src/tool/data.ts +86 -0
  116. package/src/tool/index.ts +19 -0
  117. package/src/tool/processing.test.ts +698 -0
  118. package/src/tool/processing.ts +839 -0
  119. package/src/tool/useTemplates.ts +84 -0
  120. package/src/tool/useWorkflowSelection.ts +65 -0
  121. package/src/types.ts +77 -0
@@ -0,0 +1,291 @@
1
+ /**
2
+ * Builds the Smartcat document filename for a Sanity document:
3
+ * "<type>/<sanitized title>-<id prefix>.locjson"
4
+ * e.g. "page/About Us-3f14f092.locjson".
5
+ *
6
+ * The type acts as a folder; the id prefix guarantees uniqueness. Identity on
7
+ * import comes from the file's `x-sanity` metadata, not this name, so renames
8
+ * are safe. When the exported content came from the document's draft, a `-draft`
9
+ * marker is appended so it's visible in Smartcat (`…-3f14f092-draft.locjson`).
10
+ */
11
+ export declare function buildLocjsonFilename(
12
+ documentType: string,
13
+ documentId: string,
14
+ title?: string,
15
+ options?: {
16
+ draft?: boolean;
17
+ },
18
+ ): string;
19
+
20
+ export declare interface DeserializedDocument {
21
+ documentId?: string;
22
+ documentType?: string;
23
+ sourceLanguage?: string;
24
+ /** Translated field values, keyed by field path. */
25
+ fields: Record<string, unknown>;
26
+ /**
27
+ * Source (pre-translation) text per field path, as the raw joined string. Used
28
+ * to decide whether a field is JSON (so its translation can be validated before
29
+ * import). Always the string form, even for HTML units.
30
+ */
31
+ sources: Record<string, string>;
32
+ }
33
+
34
+ /**
35
+ * Parses a (translated) LocJSON file back into Sanity field values.
36
+ *
37
+ * Uses each unit's `target` (falling back to `source` when a unit hasn't been
38
+ * translated yet, so the result is always coherent). HTML units are converted
39
+ * back to Portable Text via the field's compiled block content type.
40
+ */
41
+ export declare function deserializeFromLocjson(
42
+ locjson: LocJSON,
43
+ options: DeserializeOptions,
44
+ ): DeserializedDocument;
45
+
46
+ export declare interface DeserializeOptions {
47
+ /** DOM parser for HTML units (DOMParser in Studio, jsdom in Functions). */
48
+ parseHtml: ParseHtml;
49
+ /** Returns the compiled block content type for a Portable Text field path. */
50
+ getBlockContentType: (fieldPath: string) => unknown;
51
+ }
52
+
53
+ /**
54
+ * Selects translatable fields from a **compiled** Sanity schema type.
55
+ *
56
+ * Document-mode types (default policy, installation-agnostic):
57
+ * - `string` and `text` fields -> plain units
58
+ * - Portable Text (arrays containing `block` members) -> HTML units
59
+ * - everything else (slug, url, datetime, number, boolean, reference, image,
60
+ * non-block arrays, objects, system `_` fields, excluded names) is excluded.
61
+ *
62
+ * Field-mode types (any internationalized-array field present): only the
63
+ * internationalized-array fields are translatable; each is classified by its
64
+ * inner `value` type (string/text -> plain, Portable Text -> HTML).
65
+ *
66
+ * The compiled schema shape isn't strongly typed publicly, so this reads it
67
+ * defensively. Callers that need overrides can post-filter the result.
68
+ */
69
+ export declare function getTranslatableFields(
70
+ compiledType: unknown,
71
+ options?: GetTranslatableFieldsOptions,
72
+ ): TranslatableField[];
73
+
74
+ declare interface GetTranslatableFieldsOptions {
75
+ /**
76
+ * Field names to exclude (e.g. the i18n language field, passed by the caller
77
+ * as the configured `documentI18nPluginLanguageField`). Defaults to none.
78
+ */
79
+ exclude?: string[];
80
+ }
81
+
82
+ /**
83
+ * Parses translated HTML back into Portable Text using the field's compiled
84
+ * block content type. `parseHtml` supplies a DOM parser:
85
+ * - Studio: (html) => new DOMParser().parseFromString(html, 'text/html')
86
+ * - Functions: (html) => new JSDOM(html).window.document
87
+ */
88
+ export declare function htmlToPortableText(
89
+ html: string,
90
+ blockContentType: unknown,
91
+ parseHtml: ParseHtml,
92
+ ): PortableTextBlock[];
93
+
94
+ /**
95
+ * Selects translatable fields from a document's **data** (no schema needed) —
96
+ * for use in Sanity Functions, which run server-side without the Studio schema.
97
+ *
98
+ * Applies the same homogeneity rule as {@link getTranslatableFields}: if any
99
+ * field holds internationalized-array members, the document is field-mode and
100
+ * only those fields are selected (classified by a sample member's `value`);
101
+ * otherwise top-level `string`/Portable Text fields are selected (document-mode).
102
+ */
103
+ export declare function inferTranslatableFields(
104
+ doc: Record<string, unknown>,
105
+ options?: GetTranslatableFieldsOptions,
106
+ ): TranslatableField[];
107
+
108
+ /**
109
+ * Where a document's translations live:
110
+ * - `document`: separate locale documents linked via translation.metadata
111
+ * (@sanity/document-internationalization).
112
+ * - `field`: inline per-language array members on the same document
113
+ * (sanity-plugin-internationalized-array).
114
+ *
115
+ * This is a per-type property derived from the schema; it never travels in
116
+ * LocJSON. On a `field` field the source value is the source-language array
117
+ * member's `value` rather than the field itself.
118
+ */
119
+ export declare type LocalizationMode = "document" | "field";
120
+
121
+ export declare interface LocJSON {
122
+ properties: LocJSONProperties;
123
+ units: LocUnit[];
124
+ }
125
+
126
+ export declare interface LocJSONProperties {
127
+ version: number;
128
+ "x-sanity"?: SanityFileMeta;
129
+ }
130
+
131
+ export declare interface LocUnit {
132
+ /** Unique, stable id within the file. We use the Sanity field path. */
133
+ key: string;
134
+ properties?: LocUnitProperties;
135
+ source: string[];
136
+ target: string[];
137
+ }
138
+
139
+ export declare interface LocUnitProperties {
140
+ comments?: string[];
141
+ "x-smartcat-format"?: SmartcatFormat;
142
+ "x-smartcat-split"?: "full";
143
+ "x-sanity"?: SanityUnitMeta;
144
+ }
145
+
146
+ /**
147
+ * Reorders fields to match `orderedPaths` (e.g. a schema's field order). Fields
148
+ * not listed keep their original relative order and go last. Stable.
149
+ */
150
+ export declare function orderFieldsBy(
151
+ fields: TranslatableField[],
152
+ orderedPaths: string[] | undefined,
153
+ ): TranslatableField[];
154
+
155
+ /** Parses an HTML string into a DOM Document. Provided by the environment. */
156
+ export declare type ParseHtml = (html: string) => Document;
157
+
158
+ /** A Portable Text block (loosely typed — shape varies by schema). */
159
+ export declare type PortableTextBlock = Record<string, unknown>;
160
+
161
+ /**
162
+ * Renders Portable Text to an HTML string for translation.
163
+ * Whole-field: the entire block array becomes one HTML document fragment.
164
+ */
165
+ export declare function portableTextToHtml(
166
+ blocks: PortableTextBlock[] | undefined | null,
167
+ ): string;
168
+
169
+ /** Our per-document metadata, stored at file level. */
170
+ export declare interface SanityFileMeta {
171
+ documentId: string;
172
+ documentType: string;
173
+ /** `_rev` at export time, to detect source drift when translations return. */
174
+ rev?: string;
175
+ sourceLanguage: string;
176
+ }
177
+
178
+ /** Our per-unit metadata, stored at unit level. */
179
+ export declare interface SanityUnitMeta {
180
+ /** Path of the Sanity field this unit represents (also used as the unit key). */
181
+ fieldPath: string;
182
+ }
183
+
184
+ /** A minimal view of a Sanity document needed for serialization. */
185
+ export declare interface SerializableDocument {
186
+ _id: string;
187
+ _type: string;
188
+ _rev?: string;
189
+ [key: string]: unknown;
190
+ }
191
+
192
+ export declare interface SerializeOptions {
193
+ sourceLanguage: string;
194
+ /**
195
+ * How internationalized-array members identify their locale: a field name
196
+ * (e.g. `'language'`) or `'_key'` (v4.x and lower). Resolved by the caller (see
197
+ * `resolveConfig`); no default is assumed here.
198
+ */
199
+ fieldLanguageKey: string;
200
+ /**
201
+ * Called when a Portable Text field is skipped because it contains block types
202
+ * that can't be serialized (see {@link findUnserializableBlockTypes}). The
203
+ * whole field is left out so its content isn't dropped or corrupted on the
204
+ * round-trip; the caller surfaces this to the user's log.
205
+ */
206
+ onSkippedField?: (info: {
207
+ fieldPath: string;
208
+ title?: string;
209
+ types: string[];
210
+ }) => void;
211
+ }
212
+
213
+ /**
214
+ * Serializes a Sanity document into a LocJSON file: one unit per translatable
215
+ * field. Plain fields become plain units (segments split on newlines); Portable
216
+ * Text fields become whole-field HTML units (Smartcat segments them internally).
217
+ *
218
+ * Fields with no value are skipped, so the file only contains real source text.
219
+ */
220
+ export declare function serializeToLocjson(
221
+ doc: SerializableDocument,
222
+ fields: TranslatableField[],
223
+ options: SerializeOptions,
224
+ ): LocJSON;
225
+
226
+ /**
227
+ * Minimal LocJSON type definitions.
228
+ *
229
+ * LocJSON is Smartcat's JSON localization format: a set of `units`, each with a
230
+ * stable `key`, a `source` (array of string segments) and a `target` that
231
+ * Smartcat fills in. File- and unit-level `properties` may carry arbitrary
232
+ * `x-*` metadata that round-trips through translation.
233
+ */
234
+ /** How a unit's content should be treated by Smartcat. "plain" is the default and is omitted. */
235
+ export declare type SmartcatFormat = "markdown" | "html";
236
+
237
+ /** A translatable field selected from a document/schema. */
238
+ export declare interface TranslatableField {
239
+ /** Path to the field (dotted; nested through plain objects). Also the base unit key. */
240
+ path: string;
241
+ kind: TranslatableFieldKind;
242
+ /** How serialize extracts the source value (direct field vs. source-language array member). */
243
+ localization: LocalizationMode;
244
+ /** Optional human title, surfaced to translators as a unit comment. */
245
+ title?: string;
246
+ /**
247
+ * Shape of the (source-language member's) value. Absent means `scalar` — the
248
+ * historical behavior. Present when the value nests translatable leaves.
249
+ */
250
+ value?: ValueShape;
251
+ }
252
+
253
+ /** Kind of translatable field, deciding how it is serialized. */
254
+ export declare type TranslatableFieldKind = "plain" | "portableText";
255
+
256
+ /**
257
+ * A translatable leaf inside an array/object member value, addressed relative to
258
+ * that value (see `paths.ts`). `subPath` is empty for a scalar member value.
259
+ */
260
+ export declare interface TranslatableLeaf {
261
+ subPath: string;
262
+ kind: TranslatableFieldKind;
263
+ title?: string;
264
+ }
265
+
266
+ /**
267
+ * How a field-mode member value is shaped:
268
+ * - `scalar` — the value is itself the translatable leaf (string/text/Portable Text).
269
+ * - `arrayOfScalar` — an array of strings; one leaf per index.
270
+ * - `arrayOfObject` — an array of objects; the listed `leaves` per item (by `_key`).
271
+ * - `object` — a single object; the listed `leaves`.
272
+ */
273
+ export declare type ValueShape =
274
+ | {
275
+ container: "scalar";
276
+ kind: TranslatableFieldKind;
277
+ }
278
+ | {
279
+ container: "arrayOfScalar";
280
+ kind: TranslatableFieldKind;
281
+ }
282
+ | {
283
+ container: "arrayOfObject";
284
+ leaves: TranslatableLeaf[];
285
+ }
286
+ | {
287
+ container: "object";
288
+ leaves: TranslatableLeaf[];
289
+ };
290
+
291
+ export {};
@@ -0,0 +1,291 @@
1
+ /**
2
+ * Builds the Smartcat document filename for a Sanity document:
3
+ * "<type>/<sanitized title>-<id prefix>.locjson"
4
+ * e.g. "page/About Us-3f14f092.locjson".
5
+ *
6
+ * The type acts as a folder; the id prefix guarantees uniqueness. Identity on
7
+ * import comes from the file's `x-sanity` metadata, not this name, so renames
8
+ * are safe. When the exported content came from the document's draft, a `-draft`
9
+ * marker is appended so it's visible in Smartcat (`…-3f14f092-draft.locjson`).
10
+ */
11
+ export declare function buildLocjsonFilename(
12
+ documentType: string,
13
+ documentId: string,
14
+ title?: string,
15
+ options?: {
16
+ draft?: boolean;
17
+ },
18
+ ): string;
19
+
20
+ export declare interface DeserializedDocument {
21
+ documentId?: string;
22
+ documentType?: string;
23
+ sourceLanguage?: string;
24
+ /** Translated field values, keyed by field path. */
25
+ fields: Record<string, unknown>;
26
+ /**
27
+ * Source (pre-translation) text per field path, as the raw joined string. Used
28
+ * to decide whether a field is JSON (so its translation can be validated before
29
+ * import). Always the string form, even for HTML units.
30
+ */
31
+ sources: Record<string, string>;
32
+ }
33
+
34
+ /**
35
+ * Parses a (translated) LocJSON file back into Sanity field values.
36
+ *
37
+ * Uses each unit's `target` (falling back to `source` when a unit hasn't been
38
+ * translated yet, so the result is always coherent). HTML units are converted
39
+ * back to Portable Text via the field's compiled block content type.
40
+ */
41
+ export declare function deserializeFromLocjson(
42
+ locjson: LocJSON,
43
+ options: DeserializeOptions,
44
+ ): DeserializedDocument;
45
+
46
+ export declare interface DeserializeOptions {
47
+ /** DOM parser for HTML units (DOMParser in Studio, jsdom in Functions). */
48
+ parseHtml: ParseHtml;
49
+ /** Returns the compiled block content type for a Portable Text field path. */
50
+ getBlockContentType: (fieldPath: string) => unknown;
51
+ }
52
+
53
+ /**
54
+ * Selects translatable fields from a **compiled** Sanity schema type.
55
+ *
56
+ * Document-mode types (default policy, installation-agnostic):
57
+ * - `string` and `text` fields -> plain units
58
+ * - Portable Text (arrays containing `block` members) -> HTML units
59
+ * - everything else (slug, url, datetime, number, boolean, reference, image,
60
+ * non-block arrays, objects, system `_` fields, excluded names) is excluded.
61
+ *
62
+ * Field-mode types (any internationalized-array field present): only the
63
+ * internationalized-array fields are translatable; each is classified by its
64
+ * inner `value` type (string/text -> plain, Portable Text -> HTML).
65
+ *
66
+ * The compiled schema shape isn't strongly typed publicly, so this reads it
67
+ * defensively. Callers that need overrides can post-filter the result.
68
+ */
69
+ export declare function getTranslatableFields(
70
+ compiledType: unknown,
71
+ options?: GetTranslatableFieldsOptions,
72
+ ): TranslatableField[];
73
+
74
+ declare interface GetTranslatableFieldsOptions {
75
+ /**
76
+ * Field names to exclude (e.g. the i18n language field, passed by the caller
77
+ * as the configured `documentI18nPluginLanguageField`). Defaults to none.
78
+ */
79
+ exclude?: string[];
80
+ }
81
+
82
+ /**
83
+ * Parses translated HTML back into Portable Text using the field's compiled
84
+ * block content type. `parseHtml` supplies a DOM parser:
85
+ * - Studio: (html) => new DOMParser().parseFromString(html, 'text/html')
86
+ * - Functions: (html) => new JSDOM(html).window.document
87
+ */
88
+ export declare function htmlToPortableText(
89
+ html: string,
90
+ blockContentType: unknown,
91
+ parseHtml: ParseHtml,
92
+ ): PortableTextBlock[];
93
+
94
+ /**
95
+ * Selects translatable fields from a document's **data** (no schema needed) —
96
+ * for use in Sanity Functions, which run server-side without the Studio schema.
97
+ *
98
+ * Applies the same homogeneity rule as {@link getTranslatableFields}: if any
99
+ * field holds internationalized-array members, the document is field-mode and
100
+ * only those fields are selected (classified by a sample member's `value`);
101
+ * otherwise top-level `string`/Portable Text fields are selected (document-mode).
102
+ */
103
+ export declare function inferTranslatableFields(
104
+ doc: Record<string, unknown>,
105
+ options?: GetTranslatableFieldsOptions,
106
+ ): TranslatableField[];
107
+
108
+ /**
109
+ * Where a document's translations live:
110
+ * - `document`: separate locale documents linked via translation.metadata
111
+ * (@sanity/document-internationalization).
112
+ * - `field`: inline per-language array members on the same document
113
+ * (sanity-plugin-internationalized-array).
114
+ *
115
+ * This is a per-type property derived from the schema; it never travels in
116
+ * LocJSON. On a `field` field the source value is the source-language array
117
+ * member's `value` rather than the field itself.
118
+ */
119
+ export declare type LocalizationMode = "document" | "field";
120
+
121
+ export declare interface LocJSON {
122
+ properties: LocJSONProperties;
123
+ units: LocUnit[];
124
+ }
125
+
126
+ export declare interface LocJSONProperties {
127
+ version: number;
128
+ "x-sanity"?: SanityFileMeta;
129
+ }
130
+
131
+ export declare interface LocUnit {
132
+ /** Unique, stable id within the file. We use the Sanity field path. */
133
+ key: string;
134
+ properties?: LocUnitProperties;
135
+ source: string[];
136
+ target: string[];
137
+ }
138
+
139
+ export declare interface LocUnitProperties {
140
+ comments?: string[];
141
+ "x-smartcat-format"?: SmartcatFormat;
142
+ "x-smartcat-split"?: "full";
143
+ "x-sanity"?: SanityUnitMeta;
144
+ }
145
+
146
+ /**
147
+ * Reorders fields to match `orderedPaths` (e.g. a schema's field order). Fields
148
+ * not listed keep their original relative order and go last. Stable.
149
+ */
150
+ export declare function orderFieldsBy(
151
+ fields: TranslatableField[],
152
+ orderedPaths: string[] | undefined,
153
+ ): TranslatableField[];
154
+
155
+ /** Parses an HTML string into a DOM Document. Provided by the environment. */
156
+ export declare type ParseHtml = (html: string) => Document;
157
+
158
+ /** A Portable Text block (loosely typed — shape varies by schema). */
159
+ export declare type PortableTextBlock = Record<string, unknown>;
160
+
161
+ /**
162
+ * Renders Portable Text to an HTML string for translation.
163
+ * Whole-field: the entire block array becomes one HTML document fragment.
164
+ */
165
+ export declare function portableTextToHtml(
166
+ blocks: PortableTextBlock[] | undefined | null,
167
+ ): string;
168
+
169
+ /** Our per-document metadata, stored at file level. */
170
+ export declare interface SanityFileMeta {
171
+ documentId: string;
172
+ documentType: string;
173
+ /** `_rev` at export time, to detect source drift when translations return. */
174
+ rev?: string;
175
+ sourceLanguage: string;
176
+ }
177
+
178
+ /** Our per-unit metadata, stored at unit level. */
179
+ export declare interface SanityUnitMeta {
180
+ /** Path of the Sanity field this unit represents (also used as the unit key). */
181
+ fieldPath: string;
182
+ }
183
+
184
+ /** A minimal view of a Sanity document needed for serialization. */
185
+ export declare interface SerializableDocument {
186
+ _id: string;
187
+ _type: string;
188
+ _rev?: string;
189
+ [key: string]: unknown;
190
+ }
191
+
192
+ export declare interface SerializeOptions {
193
+ sourceLanguage: string;
194
+ /**
195
+ * How internationalized-array members identify their locale: a field name
196
+ * (e.g. `'language'`) or `'_key'` (v4.x and lower). Resolved by the caller (see
197
+ * `resolveConfig`); no default is assumed here.
198
+ */
199
+ fieldLanguageKey: string;
200
+ /**
201
+ * Called when a Portable Text field is skipped because it contains block types
202
+ * that can't be serialized (see {@link findUnserializableBlockTypes}). The
203
+ * whole field is left out so its content isn't dropped or corrupted on the
204
+ * round-trip; the caller surfaces this to the user's log.
205
+ */
206
+ onSkippedField?: (info: {
207
+ fieldPath: string;
208
+ title?: string;
209
+ types: string[];
210
+ }) => void;
211
+ }
212
+
213
+ /**
214
+ * Serializes a Sanity document into a LocJSON file: one unit per translatable
215
+ * field. Plain fields become plain units (segments split on newlines); Portable
216
+ * Text fields become whole-field HTML units (Smartcat segments them internally).
217
+ *
218
+ * Fields with no value are skipped, so the file only contains real source text.
219
+ */
220
+ export declare function serializeToLocjson(
221
+ doc: SerializableDocument,
222
+ fields: TranslatableField[],
223
+ options: SerializeOptions,
224
+ ): LocJSON;
225
+
226
+ /**
227
+ * Minimal LocJSON type definitions.
228
+ *
229
+ * LocJSON is Smartcat's JSON localization format: a set of `units`, each with a
230
+ * stable `key`, a `source` (array of string segments) and a `target` that
231
+ * Smartcat fills in. File- and unit-level `properties` may carry arbitrary
232
+ * `x-*` metadata that round-trips through translation.
233
+ */
234
+ /** How a unit's content should be treated by Smartcat. "plain" is the default and is omitted. */
235
+ export declare type SmartcatFormat = "markdown" | "html";
236
+
237
+ /** A translatable field selected from a document/schema. */
238
+ export declare interface TranslatableField {
239
+ /** Path to the field (dotted; nested through plain objects). Also the base unit key. */
240
+ path: string;
241
+ kind: TranslatableFieldKind;
242
+ /** How serialize extracts the source value (direct field vs. source-language array member). */
243
+ localization: LocalizationMode;
244
+ /** Optional human title, surfaced to translators as a unit comment. */
245
+ title?: string;
246
+ /**
247
+ * Shape of the (source-language member's) value. Absent means `scalar` — the
248
+ * historical behavior. Present when the value nests translatable leaves.
249
+ */
250
+ value?: ValueShape;
251
+ }
252
+
253
+ /** Kind of translatable field, deciding how it is serialized. */
254
+ export declare type TranslatableFieldKind = "plain" | "portableText";
255
+
256
+ /**
257
+ * A translatable leaf inside an array/object member value, addressed relative to
258
+ * that value (see `paths.ts`). `subPath` is empty for a scalar member value.
259
+ */
260
+ export declare interface TranslatableLeaf {
261
+ subPath: string;
262
+ kind: TranslatableFieldKind;
263
+ title?: string;
264
+ }
265
+
266
+ /**
267
+ * How a field-mode member value is shaped:
268
+ * - `scalar` — the value is itself the translatable leaf (string/text/Portable Text).
269
+ * - `arrayOfScalar` — an array of strings; one leaf per index.
270
+ * - `arrayOfObject` — an array of objects; the listed `leaves` per item (by `_key`).
271
+ * - `object` — a single object; the listed `leaves`.
272
+ */
273
+ export declare type ValueShape =
274
+ | {
275
+ container: "scalar";
276
+ kind: TranslatableFieldKind;
277
+ }
278
+ | {
279
+ container: "arrayOfScalar";
280
+ kind: TranslatableFieldKind;
281
+ }
282
+ | {
283
+ container: "arrayOfObject";
284
+ leaves: TranslatableLeaf[];
285
+ }
286
+ | {
287
+ container: "object";
288
+ leaves: TranslatableLeaf[];
289
+ };
290
+
291
+ export {};
@@ -0,0 +1,12 @@
1
+ import { buildLocjsonFilename, deserializeFromLocjson, getTranslatableFields, htmlToPortableText, inferTranslatableFields, orderFieldsBy, portableTextToHtml, serializeToLocjson } from "./_chunks-es/index2.js";
2
+ export {
3
+ buildLocjsonFilename,
4
+ deserializeFromLocjson,
5
+ getTranslatableFields,
6
+ htmlToPortableText,
7
+ inferTranslatableFields,
8
+ orderFieldsBy,
9
+ portableTextToHtml,
10
+ serializeToLocjson
11
+ };
12
+ //# sourceMappingURL=locjson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locjson.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: !0 });
3
+ var progress = require("./_chunks-cjs/index.cjs");
4
+ exports.buildProgress = progress.buildProgress;
5
+ exports.buildStageNameMap = progress.buildStageNameMap;
6
+ exports.hasConfirmedContent = progress.hasConfirmedContent;
7
+ exports.isTargetComplete = progress.isTargetComplete;
8
+ exports.itemsFromProject = progress.itemsFromProject;
9
+ exports.keyify = progress.keyify;
10
+ exports.runProgressSync = progress.runProgressSync;
11
+ exports.sourceIdPrefix = progress.sourceIdPrefix;
12
+ exports.stagesFromDocument = progress.stagesFromDocument;
13
+ exports.summarizeCompletion = progress.summarizeCompletion;
14
+ exports.targetKey = progress.targetKey;
15
+ exports.targetPercent = progress.targetPercent;
16
+ //# sourceMappingURL=progress.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}