@smartcat/sanity-plugin 1.0.0 → 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 (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 +168 -0
  5. package/dist/_chunks-cjs/index.cjs.map +1 -0
  6. package/dist/_chunks-cjs/index2.cjs +311 -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 +169 -0
  13. package/dist/_chunks-es/index.js.map +1 -0
  14. package/dist/_chunks-es/index2.js +313 -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 +2103 -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 +2110 -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 +287 -0
  39. package/dist/locjson.d.ts +287 -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 +262 -0
  45. package/dist/progress.d.ts +262 -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 +258 -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 +27 -0
  78. package/src/lib/locjson/index.ts +10 -0
  79. package/src/lib/locjson/locjson.test.ts +545 -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 +98 -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 +17 -0
  87. package/src/lib/resolveConfig.test.ts +62 -0
  88. package/src/lib/resolveConfig.ts +47 -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 +387 -0
  95. package/src/progress/index.ts +7 -0
  96. package/src/progress/progress.test.ts +268 -0
  97. package/src/schema/settings.ts +55 -0
  98. package/src/schema/translatableOptions.ts +25 -0
  99. package/src/schema/translationProject.ts +264 -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 +44 -0
  108. package/src/tool/ItemProgress.tsx +176 -0
  109. package/src/tool/LogPanel.tsx +207 -0
  110. package/src/tool/ProjectView.tsx +975 -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 +79 -0
  116. package/src/tool/index.ts +19 -0
  117. package/src/tool/processing.test.ts +623 -0
  118. package/src/tool/processing.ts +766 -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,122 @@
1
+ import { Plugin as Plugin_2 } from "sanity";
2
+
3
+ /**
4
+ * A language an installation can translate into.
5
+ * `id` is the locale tag used in Sanity (and document-internationalization).
6
+ * `smartcatLanguage` is the code Smartcat expects; set it only when the Sanity
7
+ * tag differs from Smartcat's (e.g. id "PL-PL" → smartcatLanguage "pl"). Defaults to `id`.
8
+ *
9
+ * @public
10
+ */
11
+ export declare interface SmartcatLanguage {
12
+ id: string;
13
+ title: string;
14
+ smartcatLanguage?: string;
15
+ }
16
+
17
+ /**
18
+ * Plugin configuration, supplied by the consuming Studio.
19
+ *
20
+ * @public
21
+ */
22
+ export declare interface SmartcatPluginConfig {
23
+ /**
24
+ * Document types the "Add to translation project" action and status line
25
+ * appear on. Omit to allow every document type (except the plugin's own
26
+ * `smartcat.*` types). This affects the Studio UI only — not which linked
27
+ * documents get pulled into a project (see `rootTypes`).
28
+ */
29
+ translatableTypes?: string[];
30
+ /**
31
+ * Root/standalone document types — the "include linked documents" crawl stops
32
+ * when it reaches one (they're translated on their own, as peers). Omit to
33
+ * inherit the explicitly-configured `translatableTypes`, or `[]` if that is
34
+ * also omitted (i.e. no boundary: pull in every transitively-linked
35
+ * translatable document).
36
+ */
37
+ rootTypes?: string[];
38
+ /**
39
+ * Source language tag for new projects. Required.
40
+ */
41
+ sourceLanguage: string;
42
+ /**
43
+ * Languages content can be translated into. Used to populate
44
+ * a project's target languages. Optional at this phase.
45
+ */
46
+ languages?: SmartcatLanguage[];
47
+ /**
48
+ * Field name `@sanity/document-internationalization` stores each document's
49
+ * locale in. Must match that plugin's `languageField` setting. Defaults to
50
+ * `'language'`.
51
+ */
52
+ documentI18nPluginLanguageField?: string;
53
+ /**
54
+ * How `sanity-plugin-internationalized-array` identifies the locale within an
55
+ * array field's members. `'language'` (default) for v5+; set to `'_key'` to
56
+ * support v4.x and lower, which keyed members by the language code.
57
+ */
58
+ fieldI18nPluginLanguageField?: string;
59
+ }
60
+
61
+ /**
62
+ * Smartcat translation plugin for Sanity Studio.
63
+ *
64
+ * - Adds a `smartcat.translationProject` document type (a named set of items).
65
+ * - Adds an "Add to translation project" document action on the configured
66
+ * `translatableTypes`.
67
+ * - Shows a status line on those types when the document belongs to one or more
68
+ * translation projects.
69
+ *
70
+ * @public
71
+ */
72
+ export declare const smartcatTranslation: Plugin_2<SmartcatPluginConfig>;
73
+
74
+ /**
75
+ * Schema option this plugin adds, mirroring how `@sanity/document-internationalization`
76
+ * contributes `options.documentInternationalization.exclude`.
77
+ *
78
+ * Set it on a field — or once on a custom type — to force translation of a type
79
+ * the default allowlist (`string`/`text`/Portable Text) would otherwise skip,
80
+ * e.g. a custom string alias. The kind is derived from the resolved `jsonType`.
81
+ */
82
+ export declare interface SmartcatTranslationSchemaOptions {
83
+ smartcatTranslation?: {
84
+ /**
85
+ * Force this field/type into translation even when its base type isn't in the
86
+ * default allowlist. Overrides a `documentInternationalization.exclude` on the
87
+ * same field. Ignored if the type has no translatable representation.
88
+ */
89
+ include?: boolean;
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Document type for a translation project (a named set of items to translate).
95
+ *
96
+ * @public
97
+ */
98
+ export declare const TRANSLATION_PROJECT_TYPE = "smartcat.translationProject";
99
+
100
+ /**
101
+ * Lifecycle of a translation project. Drives the export/import Functions.
102
+ *
103
+ * @public
104
+ */
105
+ export declare type TranslationProjectStatus =
106
+ | "draft"
107
+ | "queued"
108
+ | "sent"
109
+ | "translating"
110
+ | "importing"
111
+ | "downloaded"
112
+ | "completed"
113
+ | "error";
114
+
115
+ export {};
116
+
117
+ declare module "sanity" {
118
+ interface StringOptions extends SmartcatTranslationSchemaOptions {}
119
+ interface TextOptions extends SmartcatTranslationSchemaOptions {}
120
+ interface ArrayOptions extends SmartcatTranslationSchemaOptions {}
121
+ interface ObjectOptions extends SmartcatTranslationSchemaOptions {}
122
+ }
@@ -0,0 +1,122 @@
1
+ import { Plugin as Plugin_2 } from "sanity";
2
+
3
+ /**
4
+ * A language an installation can translate into.
5
+ * `id` is the locale tag used in Sanity (and document-internationalization).
6
+ * `smartcatLanguage` is the code Smartcat expects; set it only when the Sanity
7
+ * tag differs from Smartcat's (e.g. id "PL-PL" → smartcatLanguage "pl"). Defaults to `id`.
8
+ *
9
+ * @public
10
+ */
11
+ export declare interface SmartcatLanguage {
12
+ id: string;
13
+ title: string;
14
+ smartcatLanguage?: string;
15
+ }
16
+
17
+ /**
18
+ * Plugin configuration, supplied by the consuming Studio.
19
+ *
20
+ * @public
21
+ */
22
+ export declare interface SmartcatPluginConfig {
23
+ /**
24
+ * Document types the "Add to translation project" action and status line
25
+ * appear on. Omit to allow every document type (except the plugin's own
26
+ * `smartcat.*` types). This affects the Studio UI only — not which linked
27
+ * documents get pulled into a project (see `rootTypes`).
28
+ */
29
+ translatableTypes?: string[];
30
+ /**
31
+ * Root/standalone document types — the "include linked documents" crawl stops
32
+ * when it reaches one (they're translated on their own, as peers). Omit to
33
+ * inherit the explicitly-configured `translatableTypes`, or `[]` if that is
34
+ * also omitted (i.e. no boundary: pull in every transitively-linked
35
+ * translatable document).
36
+ */
37
+ rootTypes?: string[];
38
+ /**
39
+ * Source language tag for new projects. Required.
40
+ */
41
+ sourceLanguage: string;
42
+ /**
43
+ * Languages content can be translated into. Used to populate
44
+ * a project's target languages. Optional at this phase.
45
+ */
46
+ languages?: SmartcatLanguage[];
47
+ /**
48
+ * Field name `@sanity/document-internationalization` stores each document's
49
+ * locale in. Must match that plugin's `languageField` setting. Defaults to
50
+ * `'language'`.
51
+ */
52
+ documentI18nPluginLanguageField?: string;
53
+ /**
54
+ * How `sanity-plugin-internationalized-array` identifies the locale within an
55
+ * array field's members. `'language'` (default) for v5+; set to `'_key'` to
56
+ * support v4.x and lower, which keyed members by the language code.
57
+ */
58
+ fieldI18nPluginLanguageField?: string;
59
+ }
60
+
61
+ /**
62
+ * Smartcat translation plugin for Sanity Studio.
63
+ *
64
+ * - Adds a `smartcat.translationProject` document type (a named set of items).
65
+ * - Adds an "Add to translation project" document action on the configured
66
+ * `translatableTypes`.
67
+ * - Shows a status line on those types when the document belongs to one or more
68
+ * translation projects.
69
+ *
70
+ * @public
71
+ */
72
+ export declare const smartcatTranslation: Plugin_2<SmartcatPluginConfig>;
73
+
74
+ /**
75
+ * Schema option this plugin adds, mirroring how `@sanity/document-internationalization`
76
+ * contributes `options.documentInternationalization.exclude`.
77
+ *
78
+ * Set it on a field — or once on a custom type — to force translation of a type
79
+ * the default allowlist (`string`/`text`/Portable Text) would otherwise skip,
80
+ * e.g. a custom string alias. The kind is derived from the resolved `jsonType`.
81
+ */
82
+ export declare interface SmartcatTranslationSchemaOptions {
83
+ smartcatTranslation?: {
84
+ /**
85
+ * Force this field/type into translation even when its base type isn't in the
86
+ * default allowlist. Overrides a `documentInternationalization.exclude` on the
87
+ * same field. Ignored if the type has no translatable representation.
88
+ */
89
+ include?: boolean;
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Document type for a translation project (a named set of items to translate).
95
+ *
96
+ * @public
97
+ */
98
+ export declare const TRANSLATION_PROJECT_TYPE = "smartcat.translationProject";
99
+
100
+ /**
101
+ * Lifecycle of a translation project. Drives the export/import Functions.
102
+ *
103
+ * @public
104
+ */
105
+ export declare type TranslationProjectStatus =
106
+ | "draft"
107
+ | "queued"
108
+ | "sent"
109
+ | "translating"
110
+ | "importing"
111
+ | "downloaded"
112
+ | "completed"
113
+ | "error";
114
+
115
+ export {};
116
+
117
+ declare module "sanity" {
118
+ interface StringOptions extends SmartcatTranslationSchemaOptions {}
119
+ interface TextOptions extends SmartcatTranslationSchemaOptions {}
120
+ interface ArrayOptions extends SmartcatTranslationSchemaOptions {}
121
+ interface ObjectOptions extends SmartcatTranslationSchemaOptions {}
122
+ }