sanity-plugin-transifex 0.9.65 → 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.
Files changed (51) hide show
  1. package/.github/workflows/main.yml +1 -1
  2. package/.github/workflows/npm-publish.yml +19 -0
  3. package/dist/helpers.d.ts +5 -0
  4. package/dist/index.d.ts +13 -11
  5. package/dist/sanity-plugin-transifex.cjs.development.js +315 -960
  6. package/dist/sanity-plugin-transifex.cjs.development.js.map +1 -1
  7. package/dist/sanity-plugin-transifex.cjs.production.min.js +1 -1
  8. package/dist/sanity-plugin-transifex.cjs.production.min.js.map +1 -1
  9. package/dist/sanity-plugin-transifex.esm.js +281 -953
  10. package/dist/sanity-plugin-transifex.esm.js.map +1 -1
  11. package/dist/transifexAdapter.d.ts +1 -1
  12. package/package.json +13 -18
  13. package/src/3rdparty-typings/sanity-parts.d.ts +0 -2
  14. package/src/helpers.ts +116 -0
  15. package/src/index.ts +39 -40
  16. package/src/transifexAdapter.ts +14 -11
  17. package/.github/workflows/size.yml +0 -12
  18. package/dist/components/LanguageStatus.d.ts +0 -7
  19. package/dist/components/NewTask.d.ts +0 -6
  20. package/dist/components/Settings.d.ts +0 -5
  21. package/dist/components/TaskView.d.ts +0 -7
  22. package/dist/components/TranslationContext.d.ts +0 -11
  23. package/dist/components/TranslationTab.d.ts +0 -15
  24. package/dist/components/TranslationView.d.ts +0 -1
  25. package/dist/hooks/useSecrets.d.ts +0 -4
  26. package/dist/mergeTranslation.d.ts +0 -1
  27. package/dist/serialization/BaseDocumentDeserializer.d.ts +0 -3
  28. package/dist/serialization/BaseDocumentPatcher.d.ts +0 -2
  29. package/dist/serialization/BaseDocumentSerializer.d.ts +0 -2
  30. package/dist/serialization/BaseSerializationConfig.d.ts +0 -4
  31. package/dist/serialization/helpers.d.ts +0 -1
  32. package/dist/serialization/index.d.ts +0 -5
  33. package/dist/types.d.ts +0 -47
  34. package/sanity.json +0 -12
  35. package/src/components/LanguageStatus.tsx +0 -48
  36. package/src/components/NewTask.tsx +0 -113
  37. package/src/components/Settings.tsx +0 -16
  38. package/src/components/TaskView.tsx +0 -67
  39. package/src/components/TranslationContext.tsx +0 -17
  40. package/src/components/TranslationTab.tsx +0 -100
  41. package/src/components/TranslationView.tsx +0 -49
  42. package/src/components/exampleSchema.js +0 -18
  43. package/src/hooks/useSecrets.ts +0 -30
  44. package/src/mergeTranslation.ts +0 -52
  45. package/src/serialization/BaseDocumentDeserializer.ts +0 -176
  46. package/src/serialization/BaseDocumentPatcher.ts +0 -118
  47. package/src/serialization/BaseDocumentSerializer.ts +0 -214
  48. package/src/serialization/BaseSerializationConfig.ts +0 -42
  49. package/src/serialization/helpers.ts +0 -15
  50. package/src/serialization/index.ts +0 -12
  51. package/src/types.ts +0 -110
@@ -4,17 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
- var React = require('react');
8
- var React__default = _interopDefault(React);
9
- var ui = require('@sanity/ui');
7
+ var sanityTranslationsTab = require('sanity-translations-tab');
8
+ var sanityNaiveHtmlSerializer = require('sanity-naive-html-serializer');
10
9
  var sanityClient = _interopDefault(require('part:@sanity/base/client'));
11
- var schema = _interopDefault(require('part:@sanity/base/schema'));
12
- var blocksToHtml = require('@sanity/block-content-to-html');
13
- var blocksToHtml__default = _interopDefault(blocksToHtml);
14
- var Schema = _interopDefault(require('@sanity/schema'));
15
- var blockTools = _interopDefault(require('@sanity/block-tools'));
16
-
17
- var TranslationContext = /*#__PURE__*/React__default.createContext(null);
18
10
 
19
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
12
  try {
@@ -806,940 +798,17 @@ try {
806
798
  }
807
799
  });
808
800
 
809
- var LocaleCheckbox = function LocaleCheckbox(_ref) {
810
- var locale = _ref.locale,
811
- toggle = _ref.toggle;
812
- return React__default.createElement(ui.Card, {
813
- as: "label",
814
- border: true,
815
- radius: 1,
816
- padding: 2
817
- }, React__default.createElement(ui.Flex, {
818
- align: "center"
819
- }, React__default.createElement(ui.Checkbox, {
820
- disabled: locale.enabled === false,
821
- onChange: function onChange(event) {
822
- var target = event.target;
823
- toggle(locale.localeId, target.checked);
824
- },
825
- style: {
826
- verticalAlign: 'top'
827
- }
828
- }), React__default.createElement(ui.Box, {
829
- marginLeft: 3
830
- }, React__default.createElement(ui.Stack, {
831
- space: 2
832
- }, React__default.createElement(ui.Text, {
833
- size: 1,
834
- weight: "semibold"
835
- }, locale.description)))));
836
- };
837
-
838
- var NewTask = function NewTask(_ref2) {
839
- var locales = _ref2.locales;
840
-
841
- // Lets just stick to the canonical document id for keeping track of
842
- // translations
843
- var _React$useState = React__default.useState([]),
844
- selectedLocales = _React$useState[0],
845
- setSelectedLocales = _React$useState[1];
846
-
847
- var _useState = React.useState(false),
848
- isBusy = _useState[0],
849
- setIsBusy = _useState[1];
850
-
851
- var context = React.useContext(TranslationContext);
852
-
853
- var toggleLocale = function toggleLocale(locale, selected) {
854
- if (!selected) {
855
- setSelectedLocales(selectedLocales.filter(function (l) {
856
- return l === locale;
857
- }));
858
- } else if (!selectedLocales.includes(locale)) {
859
- setSelectedLocales([].concat(selectedLocales, [locale]));
860
- }
861
- };
862
-
863
- var createTask = /*#__PURE__*/function () {
864
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
865
- return runtime_1.wrap(function _callee$(_context) {
866
- while (1) {
867
- switch (_context.prev = _context.next) {
868
- case 0:
869
- if (context) {
870
- _context.next = 3;
871
- break;
872
- }
873
-
874
- console.error('Missing context');
875
- return _context.abrupt("return");
876
-
877
- case 3:
878
- setIsBusy(true);
879
- context.exportForTranslation(context.documentId).then(function (serialized) {
880
- return context.adapter.createTask(context.documentId, serialized, context.transifexSecrets);
881
- }).then(function () {
882
- setIsBusy(false);
883
- });
884
-
885
- case 5:
886
- case "end":
887
- return _context.stop();
888
- }
889
- }
890
- }, _callee);
891
- }));
892
-
893
- return function createTask() {
894
- return _ref3.apply(this, arguments);
895
- };
896
- }();
897
-
898
- return React__default.createElement(ui.Box, null, React__default.createElement(ui.Text, {
899
- as: "label",
900
- weight: "semibold",
901
- size: 1
902
- }, "Select locales"), React__default.createElement(ui.Grid, {
903
- marginTop: 2,
904
- columns: [1, 1, 2, 3],
905
- gap: 1,
906
- paddingBottom: 2
907
- }, (locales || []).map(function (l) {
908
- return React__default.createElement(LocaleCheckbox, {
909
- key: l.localeId,
910
- locale: l,
911
- toggle: function toggle(locale, checked) {
912
- toggleLocale(locale, checked);
913
- }
914
- });
915
- })), React__default.createElement(ui.Box, {
916
- marginBottom: 5
917
- }, React__default.createElement(ui.Button, {
918
- onClick: createTask,
919
- disabled: isBusy || !selectedLocales.length,
920
- tone: "primary",
921
- text: "Create new"
922
- })));
923
- };
924
-
925
- var LanguageStatus = function LanguageStatus(_ref) {
926
- var title = _ref.title,
927
- progress = _ref.progress,
928
- importFile = _ref.importFile;
929
- var progressWrapperStyle = {
930
- height: '5px',
931
- border: '1px black solid',
932
- width: 200
933
- };
934
- var progressStyle = {
935
- height: '5px',
936
- backgroundColor: 'green',
937
- width: progress + "%"
938
- };
939
- return React__default.createElement(ui.Card, {
940
- padding: 2
941
- }, React__default.createElement(ui.Heading, null, title), React__default.createElement(ui.Flex, {
942
- align: "center"
943
- }, React__default.createElement(ui.Box, {
944
- flex: 1
945
- }, React__default.createElement(ui.Inline, null, React__default.createElement(ui.Box, {
946
- style: progressWrapperStyle
947
- }, React__default.createElement(ui.Box, {
948
- style: progressStyle
949
- }, "\xA0")), React__default.createElement(ui.Box, {
950
- paddingLeft: 3
951
- }, React__default.createElement(ui.Text, null, progress, " %")))), React__default.createElement(ui.Button, {
952
- mode: "bleed",
953
- onClick: function onClick() {
954
- return importFile();
955
- },
956
- text: "Import",
957
- tone: "positive"
958
- })));
959
- };
960
-
961
- var TaskView = function TaskView(_ref) {
962
- var task = _ref.task,
963
- locales = _ref.locales;
964
- var context = React.useContext(TranslationContext);
965
- var toast = ui.useToast();
966
-
967
- var _importFile = function importFile(localeId) {
968
- if (!context) {
969
- console.error('Missing context');
970
- return;
971
- }
972
-
973
- context.adapter.getTranslation(task.taskId, localeId, context.transifexSecrets).then(function (record) {
974
- if (record) {
975
- context.importTranslation(localeId, record);
976
- } else {
977
- // TODO: Handle this in a toast
978
- alert('Error getting the translated content!');
979
- }
980
- });
981
- };
982
-
983
- return React__default.createElement(ui.Card, {
984
- padding: 2,
985
- sizing: "border"
986
- }, React__default.createElement(ui.Stack, {
987
- space: 2
988
- }, task.locales.map(function (localeTask) {
989
- var reportPercent = localeTask.progress || 0;
990
- var locale = locales.find(function (l) {
991
- return l.localeId === localeTask.localeId;
992
- });
993
- return React__default.createElement(LanguageStatus, {
994
- key: [task.taskId, localeTask.localeId].join('.'),
995
- importFile: function importFile() {
996
- _importFile(localeTask.localeId);
997
-
998
- toast.push({
999
- title: 'Hello',
1000
- status: 'info'
1001
- });
1002
- },
1003
- title: (locale == null ? void 0 : locale.description) || localeTask.localeId,
1004
- progress: reportPercent
1005
- });
1006
- })));
1007
- };
1008
- /*
1009
-
1010
- <Skeleton isLoaded={!!details}>
1011
- <Box p={2} shadow="md" borderWidth="1px">
1012
- <Box>
1013
- <Grid>
1014
- <Text fontSize="xs">Overall progress</Text>
1015
- </Grid>
1016
- </Box>
1017
- </Box>
1018
- </Skeleton>
1019
- */
1020
-
1021
- /*
1022
- import { SettingsView } from './Settings'
1023
- */
1024
-
1025
- var TranslationView = function TranslationView() {
1026
- var _useState = React.useState([]),
1027
- locales = _useState[0],
1028
- setLocales = _useState[1];
1029
-
1030
- var _useState2 = React.useState(null),
1031
- task = _useState2[0],
1032
- setTask = _useState2[1];
1033
- /*
1034
- const [open, setOpen] = useState(false)
1035
- const onClose = useCallback(() => setOpen(false), [])
1036
- const onOpen = useCallback(() => setOpen(true), [])
1037
- */
1038
-
1039
-
1040
- var context = React.useContext(TranslationContext);
1041
- React.useEffect(function () {
1042
- function fetchData() {
1043
- return _fetchData.apply(this, arguments);
1044
- }
1045
-
1046
- function _fetchData() {
1047
- _fetchData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1048
- return runtime_1.wrap(function _callee$(_context) {
1049
- while (1) {
1050
- switch (_context.prev = _context.next) {
1051
- case 0:
1052
- if (context) {
1053
- _context.next = 3;
1054
- break;
1055
- }
1056
-
1057
- console.error('Missing context');
1058
- return _context.abrupt("return");
1059
-
1060
- case 3:
1061
- context.adapter.getLocales(context.transifexSecrets).then(setLocales).then(function () {
1062
- return context.adapter.getTranslationTask(context.documentId, context.transifexSecrets);
1063
- }).then(setTask);
1064
-
1065
- case 4:
1066
- case "end":
1067
- return _context.stop();
1068
- }
1069
- }
1070
- }, _callee);
1071
- }));
1072
- return _fetchData.apply(this, arguments);
1073
- }
1074
-
1075
- fetchData();
1076
- }, [context]);
1077
- return React__default.createElement(ui.Box, null, React__default.createElement(NewTask, {
1078
- locales: locales
1079
- }), task && React__default.createElement(TaskView, {
1080
- task: task,
1081
- locales: locales
1082
- }));
1083
- };
1084
-
1085
- var client = /*#__PURE__*/sanityClient.withConfig({
1086
- apiVersion: '2021-03-25'
1087
- });
1088
- function useSecrets(id) {
1089
- var _useState = React.useState(true),
1090
- loading = _useState[0],
1091
- setLoading = _useState[1];
1092
-
1093
- var _useState2 = React.useState(null),
1094
- secrets = _useState2[0],
1095
- setSecrets = _useState2[1];
1096
-
1097
- React.useEffect(function () {
1098
- function fetchData() {
1099
- return _fetchData.apply(this, arguments);
1100
- }
1101
-
1102
- function _fetchData() {
1103
- _fetchData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1104
- return runtime_1.wrap(function _callee$(_context) {
1105
- while (1) {
1106
- switch (_context.prev = _context.next) {
1107
- case 0:
1108
- client.fetch('* [_id == $id][0]', {
1109
- id: id
1110
- }).then(function (doc) {
1111
- var result = {};
1112
-
1113
- for (var key in doc) {
1114
- if (key[0] !== '_') {
1115
- result[key] = doc[key];
1116
- }
1117
- }
1118
-
1119
- setSecrets(result);
1120
- setLoading(false);
1121
- });
1122
-
1123
- case 1:
1124
- case "end":
1125
- return _context.stop();
1126
- }
1127
- }
1128
- }, _callee);
1129
- }));
1130
- return _fetchData.apply(this, arguments);
1131
- }
1132
-
1133
- fetchData();
1134
- }, [id]);
1135
- return {
1136
- loading: loading,
1137
- secrets: secrets
1138
- };
1139
- }
1140
-
1141
- var TranslationTab = function TranslationTab(props) {
1142
- var displayed = props.document.displayed;
1143
-
1144
- var documentId = displayed._id.split('drafts.').pop();
1145
-
1146
- var errors = [];
1147
- var importTranslationFunc = props.options.importTranslation;
1148
-
1149
- if (!importTranslationFunc) {
1150
- errors.push('You need to provide an importTranslation function. See documentation.');
1151
- }
1152
-
1153
- var importTranslation = function importTranslation(localeId, doc) {
1154
- return importTranslationFunc(documentId, localeId, doc);
1155
- };
1156
-
1157
- var exportTranslationFunc = props.options.exportForTranslation;
1158
-
1159
- if (!exportTranslationFunc) {
1160
- errors.push('You need to provide an exportForTranslation function. See documentation.');
1161
- }
1162
-
1163
- var exportForTranslation = function exportForTranslation(id) {
1164
- return exportTranslationFunc(id);
1165
- };
1166
-
1167
- var _useSecrets = useSecrets('transifex.secrets'),
1168
- loading = _useSecrets.loading,
1169
- secrets = _useSecrets.secrets;
1170
-
1171
- var hasErrors = errors.length > 0;
1172
-
1173
- if (loading || !secrets) {
1174
- return React__default.createElement("span", null, "Loading...");
1175
- } else if (!secrets) {
1176
- return React__default.createElement("span", null, "Can't find secrets for Transifex. Did you load them into this datastore?");
1177
- } else {
1178
- return React__default.createElement(ui.ThemeProvider, {
1179
- theme: ui.studioTheme
1180
- }, React__default.createElement(ui.Container, {
1181
- width: 1,
1182
- paddingTop: 4,
1183
- marginBottom: 0
1184
- }, React__default.createElement(ui.Layer, {
1185
- zOffset: 1000
1186
- }, React__default.createElement(ui.ToastProvider, null, hasErrors && errors.map(function (e) {
1187
- return React__default.createElement(ui.Text, null, e);
1188
- }), !hasErrors && React__default.createElement(TranslationContext.Provider, {
1189
- value: {
1190
- documentId: documentId,
1191
- adapter: props.options.adapter,
1192
- baseLanguage: props.options.baseLanguage,
1193
- transifexSecrets: secrets,
1194
- importTranslation: importTranslation,
1195
- exportForTranslation: exportForTranslation
1196
- }
1197
- }, React__default.createElement(TranslationView, null))))));
1198
- }
1199
- };
1200
-
1201
- var defaultStopTypes = ['reference', 'date', 'datetime', 'file', 'geopoint', 'image', 'number', 'crop', 'hotspot', 'boolean'];
1202
- var customSerializers = {
1203
- unknownType: function unknownType(props) {
1204
- return blocksToHtml.h('div', {
1205
- className: props.node._type
1206
- }, '');
1207
- },
1208
- types: {
1209
- block: function block(props) {
1210
- return blocksToHtml.h('p', {
1211
- id: props.node._key
1212
- }, props.children);
1213
- }
1214
- },
1215
- list: function list(props) {
1216
- var tag = props.type === 'bullet' ? 'ul' : 'ol';
1217
- return blocksToHtml.h(tag, {
1218
- id: props.key.replace('-parent', '')
1219
- }, props.children);
1220
- },
1221
- listItem: function listItem(props) {
1222
- var children = !props.node.style || props.node.style === 'normal' ? // Don't wrap plain text in paragraphs inside of a list item
1223
- props.children : // But wrap any other style in whatever the block serializer says to use
1224
- blocksToHtml.h(props.serializers.types.block, props, props.children);
1225
- return blocksToHtml.h('li', {
1226
- id: props.node._key
1227
- }, children);
1228
- }
1229
- };
1230
- var customDeserializers = {
1231
- types: {}
1232
- };
1233
- var customBlockDeserializers = [];
1234
-
1235
- var client$1 = /*#__PURE__*/sanityClient.withConfig({
1236
- apiVersion: 'v1'
1237
- });
1238
- var findLatestDraft = function findLatestDraft(documentId) {
1239
- var query = "*[_id match $id && (_id in path(\"drafts.*\") || _id in path(\"*\"))]";
1240
- var params = {
1241
- id: documentId
1242
- };
1243
- return client$1.fetch(query, params).then(function (docs) {
1244
- var _docs$find;
1245
-
1246
- return (_docs$find = docs.find(function (doc) {
1247
- return doc._id.includes('draft');
1248
- })) != null ? _docs$find : docs[0];
1249
- });
1250
- };
1251
-
1252
- var getSchema = function getSchema(name) {
1253
- return schema._original.types.find(function (s) {
1254
- return s.name === name;
1255
- });
1256
- };
1257
-
1258
- var serializeDocument = /*#__PURE__*/function () {
1259
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, translationLevel, baseLang, stopTypes, serializers) {
1260
- var doc, filteredObj, serializedFields, key, value;
1261
- return runtime_1.wrap(function _callee$(_context) {
1262
- while (1) {
1263
- switch (_context.prev = _context.next) {
1264
- case 0:
1265
- if (translationLevel === void 0) {
1266
- translationLevel = 'document';
1267
- }
1268
-
1269
- if (baseLang === void 0) {
1270
- baseLang = 'en';
1271
- }
1272
-
1273
- if (stopTypes === void 0) {
1274
- stopTypes = defaultStopTypes;
1275
- }
1276
-
1277
- if (serializers === void 0) {
1278
- serializers = customSerializers;
1279
- }
1280
-
1281
- _context.next = 6;
1282
- return findLatestDraft(documentId);
1283
-
1284
- case 6:
1285
- doc = _context.sent;
1286
- filteredObj = {};
1287
-
1288
- if (translationLevel === 'field') {
1289
- filteredObj = languageObjectFieldFilter(doc, baseLang);
1290
- } else {
1291
- filteredObj = fieldFilter(doc, getSchema(doc._type).fields, stopTypes);
1292
- }
1293
-
1294
- serializedFields = {};
1295
-
1296
- for (key in filteredObj) {
1297
- value = filteredObj[key];
1298
-
1299
- if (typeof value === 'string') {
1300
- serializedFields[key] = value;
1301
- } else if (Array.isArray(value)) {
1302
- serializedFields[key] = serializeArray(value, key, stopTypes, serializers);
1303
- } else {
1304
- serializedFields[key] = serializeObject(value, key, stopTypes, serializers);
1305
- }
1306
- }
1307
-
1308
- return _context.abrupt("return", {
1309
- name: documentId,
1310
- content: serializeObject(serializedFields, doc._type, stopTypes, serializers)
1311
- });
1312
-
1313
- case 12:
1314
- case "end":
1315
- return _context.stop();
1316
- }
1317
- }
1318
- }, _callee);
1319
- }));
1320
-
1321
- return function serializeDocument(_x, _x2, _x3, _x4, _x5) {
1322
- return _ref.apply(this, arguments);
1323
- };
1324
- }();
1325
-
1326
- var languageObjectFieldFilter = function languageObjectFieldFilter(obj, baseLang) {
1327
- var filteredObj = {};
1328
-
1329
- for (var key in obj) {
1330
- var value = obj[key];
1331
-
1332
- if (value.hasOwnProperty(baseLang)) {
1333
- filteredObj[key] = {};
1334
- filteredObj[key][baseLang] = value[baseLang];
1335
- }
1336
- }
1337
-
1338
- return filteredObj;
1339
- };
1340
-
1341
- var fieldFilter = function fieldFilter(obj, objFields, stopTypes) {
1342
- var filteredObj = {};
1343
-
1344
- var fieldFilter = function fieldFilter(field) {
1345
- if (field.localize === false) {
1346
- return false;
1347
- } else if (field.type.name === 'string' || field.type.name === 'text') {
1348
- return true;
1349
- } else if (Array.isArray(obj[field.name])) {
1350
- return true;
1351
- } else if (!stopTypes.includes(field.type.name)) {
1352
- return true;
1353
- }
1354
-
1355
- return false;
1356
- };
1357
-
1358
- var validFields = ['_key', '_type', '_id'].concat(objFields.filter(fieldFilter).map(function (field) {
1359
- return field.name;
1360
- }));
1361
- validFields.forEach(function (field) {
1362
- if (obj[field]) {
1363
- filteredObj[field] = obj[field];
1364
- }
1365
- });
1366
- return filteredObj;
1367
- };
1368
-
1369
- var serializeArray = function serializeArray(fieldContent, fieldName, stopTypes, serializers) {
1370
- var validBlocks = fieldContent.filter(function (block) {
1371
- return !stopTypes.includes(block._type);
1372
- });
1373
- var filteredBlocks = validBlocks.map(function (block) {
1374
- var schema = getSchema(block._type);
1375
-
1376
- if (schema) {
1377
- return fieldFilter(block, schema.fields, stopTypes);
1378
- } else {
1379
- return block;
1380
- }
1381
- });
1382
- var output = filteredBlocks.map(function (obj) {
1383
- return serializeObject(obj, null, stopTypes, serializers);
1384
- });
1385
- return "<div class=\"" + fieldName + "\">" + output.join() + "</div>";
1386
- };
1387
-
1388
- var serializeObject = function serializeObject(obj, topFieldName, stopTypes, serializers) {
1389
- if (topFieldName === void 0) {
1390
- topFieldName = null;
1391
- }
1392
-
1393
- if (stopTypes.includes(obj._type)) {
1394
- return '';
1395
- }
1396
-
1397
- var hasSerializer = serializers.types && Object.keys(serializers.types).includes(obj._type);
1398
-
1399
- if (hasSerializer) {
1400
- return blocksToHtml__default({
1401
- blocks: [obj],
1402
- serializers: serializers
1403
- });
1404
- }
1405
-
1406
- var tempSerializers = {
1407
- types: {
1408
- block: serializers.types.block
1409
- }
1410
- };
1411
-
1412
- if (obj._type !== 'span' && obj._type !== 'block') {
1413
- var innerHTML = '';
1414
- Object.entries(obj).forEach(function (_ref2) {
1415
- var fieldName = _ref2[0],
1416
- value = _ref2[1];
1417
- var htmlField = '';
1418
-
1419
- if (!['_key', '_type', '_id'].includes(fieldName)) {
1420
- if (typeof value === 'string') {
1421
- var htmlRegex = /^</; //this field may have been recursively turned into html already.
1422
-
1423
- htmlField = value.match(htmlRegex) ? value : "<span class=\"" + fieldName + "\">" + value + "</span>";
1424
- } else if (Array.isArray(value)) {
1425
- htmlField = serializeArray(value, fieldName, stopTypes, serializers);
1426
- } else {
1427
- var schema = getSchema(value._type);
1428
- var toTranslate = value;
1429
-
1430
- if (schema) {
1431
- toTranslate = fieldFilter(value, schema.fields, stopTypes);
1432
- }
1433
-
1434
- var objHTML = serializeObject(toTranslate, null, stopTypes, serializers);
1435
- htmlField = "<div class=" + fieldName + ">" + objHTML + "</div>";
1436
- }
1437
- }
1438
-
1439
- innerHTML += htmlField;
1440
- });
1441
-
1442
- if (!innerHTML) {
1443
- return '';
1444
- } //@ts-ignore
1445
-
1446
-
1447
- tempSerializers.types[obj._type] = function (props) {
1448
- var _topFieldName, _props$node$_key;
1449
-
1450
- return blocksToHtml.h('div', {
1451
- className: (_topFieldName = topFieldName) != null ? _topFieldName : props.node._type,
1452
- id: (_props$node$_key = props.node._key) != null ? _props$node$_key : props.node._id,
1453
- innerHTML: innerHTML
1454
- });
1455
- };
1456
- }
1457
-
1458
- var serializedBlock = '';
1459
-
1460
- try {
1461
- serializedBlock = blocksToHtml__default({
1462
- blocks: [obj],
1463
- serializers: tempSerializers
1464
- });
1465
- } catch (err) {
1466
- console.debug("Had issues serializing block of type \"" + obj._type + "\". Please specify a serialization method for this block in your serialization config. Received error: " + err);
1467
- }
1468
-
1469
- return serializedBlock;
1470
- };
1471
-
1472
- var BaseDocumentSerializer = {
1473
- serializeDocument: serializeDocument,
1474
- fieldFilter: fieldFilter,
1475
- languageObjectFieldFilter: languageObjectFieldFilter,
1476
- serializeArray: serializeArray,
1477
- serializeObject: serializeObject
1478
- };
1479
-
1480
- var noSchemaWarning = function noSchemaWarning(obj) {
1481
- return "WARNING: Unfortunately the deserializer may have issues with this field or object: " + obj.className + ".\n If it's a specific type, you may need to declare at the top level, or write a custom deserializer.";
1482
- };
1483
-
1484
- var defaultSchema = /*#__PURE__*/Schema.compile({
1485
- name: 'default',
1486
- types: [{
1487
- type: 'object',
1488
- name: 'default',
1489
- fields: [{
1490
- name: 'block',
1491
- type: 'array',
1492
- of: [{
1493
- type: 'block'
1494
- }]
1495
- }]
1496
- }]
1497
- });
1498
- var blockContentType = /*#__PURE__*/defaultSchema.get('default').fields.find(function (field) {
1499
- return field.name === 'block';
1500
- }).type;
1501
- var deserializeDocument = /*#__PURE__*/function () {
1502
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, serializedDoc, deserializers, blockDeserializers) {
1503
- return runtime_1.wrap(function _callee$(_context) {
1504
- while (1) {
1505
- switch (_context.prev = _context.next) {
1506
- case 0:
1507
- if (deserializers === void 0) {
1508
- deserializers = customDeserializers;
1509
- }
1510
-
1511
- if (blockDeserializers === void 0) {
1512
- blockDeserializers = customBlockDeserializers;
1513
- }
1514
-
1515
- return _context.abrupt("return", findLatestDraft(documentId).then(function (doc) {
1516
- return deserializeHTML(serializedDoc, schema.get(doc._type), deserializers, blockDeserializers);
1517
- }));
1518
-
1519
- case 3:
1520
- case "end":
1521
- return _context.stop();
1522
- }
1523
- }
1524
- }, _callee);
1525
- }));
1526
-
1527
- return function deserializeDocument(_x, _x2, _x3, _x4) {
1528
- return _ref.apply(this, arguments);
1529
- };
1530
- }();
1531
-
1532
- var deserializeHTML = function deserializeHTML(html, target, deserializers, blockDeserializers) {
1533
- //parent node is always div with classname of field -- get its children
1534
- var HTMLnode = new DOMParser().parseFromString(html, 'text/html').body.children[0];
1535
-
1536
- if (!HTMLnode) {
1537
- return {};
1538
- } //@ts-ignore
1539
-
1540
-
1541
- var output; //catch embedded object as a field -- not necessarily foolproof
1542
-
1543
- if (HTMLnode.children.length === 1 && target && target.type && HTMLnode.children[0].className === target.type.name) {
1544
- HTMLnode = HTMLnode.children[0];
1545
- }
1546
-
1547
- if (target && target.type && target.type.name && Object.keys(deserializers.types).includes(target.type.name)) {
1548
- var deserialize = deserializers.types[target.type.name];
1549
- output = deserialize(HTMLnode);
1550
- } else {
1551
- var children = Array.from(HTMLnode.children);
1552
- output = target && target.type && target.type.hasOwnProperty('of') ? [] : {};
1553
- children.forEach(function (child) {
1554
- var deserializedObj; //allow for custom deserialization
1555
-
1556
- if (Object.keys(deserializers.types).includes(child.className)) {
1557
- var _deserialize = deserializers.types[child.className];
1558
- deserializedObj = _deserialize(child);
1559
- } //flat string, it's an unrich field
1560
- else if (child.tagName.toLowerCase() === 'span') {
1561
- deserializedObj = child.innerHTML;
1562
- } //has specific class name, so it's either a field or obj
1563
- else if (child.className) {
1564
- var objType;
1565
-
1566
- if (target.fields) {
1567
- objType = target.fields.find(function (field) {
1568
- return field.name === child.className;
1569
- });
1570
- }
1571
-
1572
- if (!objType && schema.get(child.className)) {
1573
- objType = schema.get(child.className);
1574
- }
1575
-
1576
- if (!objType) {
1577
- console.debug(noSchemaWarning(child));
1578
- objType = blockContentType;
1579
- }
1580
-
1581
- try {
1582
- deserializedObj = deserializeHTML(child.outerHTML, objType, deserializers, blockDeserializers);
1583
- } catch (err) {
1584
- console.debug(err);
1585
-
1586
- try {
1587
- deserializedObj = deserializeHTML(child.outerHTML, schema.get('object'), deserializers, blockDeserializers);
1588
- } catch (err) {
1589
- console.debug("Tried to deserialize block of type " + child.className + " but failed! Received error " + err);
1590
- }
1591
- } // @ts-ignore
1592
-
1593
-
1594
- if (Array.isArray(output) && deserializedObj) {
1595
- deserializedObj._type = child.className;
1596
- deserializedObj._key = child.id;
1597
- }
1598
- } else {
1599
- deserializedObj = blockTools.htmlToBlocks(child.outerHTML, blockContentType, {
1600
- rules: blockDeserializers
1601
- })[0];
1602
- deserializedObj._key = child.id;
1603
- } // @ts-ignore
1604
-
1605
-
1606
- if (Array.isArray(output)) {
1607
- output.push(deserializedObj);
1608
- } else {
1609
- // @ts-ignore
1610
- output[child.className] = deserializedObj;
1611
- }
1612
- });
1613
- }
1614
-
1615
- return output;
1616
- };
1617
-
1618
- var BaseDocumentDeserializer = {
1619
- deserializeDocument: deserializeDocument,
1620
- deserializeHTML: deserializeHTML
1621
- };
1622
-
1623
- var client$2 = /*#__PURE__*/sanityClient.withConfig({
1624
- apiVersion: '2021-03-25'
1625
- });
1626
-
1627
- var fieldLevelPatch = function fieldLevelPatch(translatedFields, documentId, localeId, baseLang) {
1628
- if (baseLang === void 0) {
1629
- baseLang = 'en';
1630
- }
1631
-
1632
- return findLatestDraft(documentId).then(function (doc) {
1633
- var merged = {};
1634
-
1635
- for (var field in translatedFields) {
1636
- var translatedVal = translatedFields[field][baseLang];
1637
- var origVal = doc[field][baseLang];
1638
- merged[field] = doc[field];
1639
- var valToPatch = void 0;
1640
-
1641
- if (typeof translatedVal === 'string') {
1642
- valToPatch = translatedVal;
1643
- } else if (Array.isArray(translatedVal)) {
1644
- valToPatch = reconcileArray(origVal != null ? origVal : [], translatedVal);
1645
- } else {
1646
- valToPatch = reconcileObject(origVal != null ? origVal : {}, translatedVal);
1647
- }
1648
-
1649
- merged[field][localeId] = valToPatch;
1650
- }
1651
-
1652
- client$2.patch(doc._id).set(merged).commit();
1653
- });
1654
- };
1655
-
1656
- var documentLevelPatch = function documentLevelPatch(translatedFields, documentId, localeId) {
1657
- /* try whatever existing draft of this doc exists first --
1658
- * If user has created the i18n version, use that. If not,
1659
- * make it from the existing draft
1660
- */
1661
- return findLatestDraft("i18n." + documentId + "." + localeId).then(function (doc) {
1662
- if (!doc) {
1663
- return findLatestDraft(documentId);
1664
- } else {
1665
- return doc;
1666
- }
1667
- }).then(function (doc) {
1668
- var merged = reconcileObject(doc, translatedFields);
1669
- merged._id = "drafts.i18n." + documentId + "." + localeId;
1670
- merged._lang = localeId;
1671
- client$2.createOrReplace(merged);
1672
- });
1673
- };
1674
-
1675
- var reconcileArray = function reconcileArray(origArray, translatedArray) {
1676
- //deep copy needed for field level patching
1677
- var combined = JSON.parse(JSON.stringify(origArray));
1678
- translatedArray.forEach(function (block) {
1679
- if (!block._key) {
1680
- return;
1681
- }
1682
-
1683
- var foundBlockIdx = origArray.findIndex(function (origBlock) {
1684
- return origBlock._key === block._key;
1685
- });
1686
-
1687
- if (foundBlockIdx < 0) {
1688
- console.log("This block no longer exists on the original document. Was it removed? " + block._key);
1689
- } else if (origArray[foundBlockIdx]._type === 'block' || origArray[foundBlockIdx]._type === 'span') {
1690
- combined[foundBlockIdx] = block;
1691
- } else if (Array.isArray(origArray[foundBlockIdx])) {
1692
- combined[foundBlockIdx] = reconcileArray(origArray[foundBlockIdx], block);
1693
- } else {
1694
- combined[foundBlockIdx] = reconcileObject(origArray[foundBlockIdx], block);
1695
- }
1696
- });
1697
- return combined;
1698
- };
1699
-
1700
- var reconcileObject = function reconcileObject(origObject, translatedObject) {
1701
- var updatedObj = JSON.parse(JSON.stringify(origObject));
1702
- Object.entries(translatedObject).forEach(function (_ref) {
1703
- var key = _ref[0],
1704
- value = _ref[1];
1705
-
1706
- if (!value || key[0] === '_') {
1707
- return;
1708
- }
1709
-
1710
- if (typeof value === 'string') {
1711
- updatedObj[key] = value;
1712
- } else if (Array.isArray(value)) {
1713
- var _origObject$key;
1714
-
1715
- updatedObj[key] = reconcileArray((_origObject$key = origObject[key]) != null ? _origObject$key : [], value);
1716
- } else {
1717
- var _origObject$key2;
1718
-
1719
- updatedObj[key] = reconcileObject((_origObject$key2 = origObject[key]) != null ? _origObject$key2 : {}, value);
1720
- }
1721
- });
1722
- return updatedObj;
1723
- };
1724
-
1725
- var BaseDocumentPatcher = {
1726
- fieldLevelPatch: fieldLevelPatch,
1727
- documentLevelPatch: documentLevelPatch,
1728
- reconcileArray: reconcileArray,
1729
- reconcileObject: reconcileObject
1730
- };
1731
-
1732
801
  var baseTransifexUrl = 'https://rest.api.transifex.com';
1733
802
 
1734
803
  var getHeaders = function getHeaders(secrets) {
1735
804
  return {
1736
- Authorization: "Bearer " + secrets.token,
805
+ Authorization: "Bearer " + (secrets == null ? void 0 : secrets.token),
1737
806
  'Content-Type': 'application/vnd.api+json'
1738
807
  };
1739
808
  };
1740
809
 
1741
810
  var projOrgSlug = function projOrgSlug(secrets) {
1742
- return "o:" + secrets.organization + ":p:" + secrets.project;
811
+ return "o:" + (secrets == null ? void 0 : secrets.organization) + ":p:" + (secrets == null ? void 0 : secrets.project);
1743
812
  };
1744
813
 
1745
814
  var getLocales = /*#__PURE__*/function () {
@@ -1814,7 +883,7 @@ var getTranslationTask = /*#__PURE__*/function () {
1814
883
  locales: res.data.map(function (locale) {
1815
884
  return {
1816
885
  localeId: locale.relationships.language.data.id.split(':')[1],
1817
- progress: Math.floor(100 * (locale.attributes.translated_strings / parseFloat(locale.attributes.total_strings)))
886
+ progress: Math.floor(100 * (locale.attributes.reviewed_strings / parseFloat(locale.attributes.total_strings)))
1818
887
  };
1819
888
  })
1820
889
  };
@@ -1906,7 +975,9 @@ var createResource = /*#__PURE__*/function () {
1906
975
  }();
1907
976
 
1908
977
  var createTask = /*#__PURE__*/function () {
1909
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(documentId, document, secrets) {
978
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(documentId, document, //unfortunately Transifex doesn't let you specify locales on creating a task
979
+ //@ts-ignore
980
+ localeIds, secrets) {
1910
981
  var resourceId, resourceUploadUrl, resourceUploadBody;
1911
982
  return runtime_1.wrap(function _callee4$(_context4) {
1912
983
  while (1) {
@@ -1970,7 +1041,7 @@ var createTask = /*#__PURE__*/function () {
1970
1041
  }, _callee4);
1971
1042
  }));
1972
1043
 
1973
- return function createTask(_x7, _x8, _x9) {
1044
+ return function createTask(_x7, _x8, _x9, _x10) {
1974
1045
  return _ref4.apply(this, arguments);
1975
1046
  };
1976
1047
  }();
@@ -2040,7 +1111,7 @@ var getTranslation = /*#__PURE__*/function () {
2040
1111
  }, _callee5);
2041
1112
  }));
2042
1113
 
2043
- return function getTranslation(_x10, _x11, _x12) {
1114
+ return function getTranslation(_x11, _x12, _x13) {
2044
1115
  return _ref5.apply(this, arguments);
2045
1116
  };
2046
1117
  }();
@@ -2063,7 +1134,7 @@ var handleFileDownload = /*#__PURE__*/function () {
2063
1134
  }, _callee6);
2064
1135
  }));
2065
1136
 
2066
- return function handleFileDownload(_x13) {
1137
+ return function handleFileDownload(_x14) {
2067
1138
  return _ref6.apply(this, arguments);
2068
1139
  };
2069
1140
  }();
@@ -2075,36 +1146,320 @@ var TransifexAdapter = {
2075
1146
  getTranslation: getTranslation
2076
1147
  };
2077
1148
 
1149
+ var client = /*#__PURE__*/sanityClient.withConfig({
1150
+ apiVersion: '2021-03-25'
1151
+ }); //document fetch
1152
+
1153
+ var findLatestDraft = function findLatestDraft(documentId, ignoreI18n) {
1154
+ if (ignoreI18n === void 0) {
1155
+ ignoreI18n = true;
1156
+ }
1157
+
1158
+ //eliminates i18n versions
1159
+ var query = "*[_id match $id " + (ignoreI18n ? ' && (_id in path("drafts.*") || _id in path("*"))' : '') + "]";
1160
+ var params = {
1161
+ id: "*" + documentId
1162
+ };
1163
+ return client.fetch(query, params).then(function (docs) {
1164
+ var _docs$find;
1165
+
1166
+ return (_docs$find = docs.find(function (doc) {
1167
+ return doc._id.includes('draft');
1168
+ })) != null ? _docs$find : docs[0];
1169
+ });
1170
+ }; //revision fetch
1171
+
1172
+ var findDocumentAtRevision = /*#__PURE__*/function () {
1173
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, rev) {
1174
+ var dataset, baseUrl, url, revisionDoc;
1175
+ return runtime_1.wrap(function _callee$(_context) {
1176
+ while (1) {
1177
+ switch (_context.prev = _context.next) {
1178
+ case 0:
1179
+ dataset = client.config().dataset;
1180
+ baseUrl = "/data/history/" + dataset + "/documents/" + documentId + "?revision=" + rev;
1181
+ url = client.getUrl(baseUrl);
1182
+ _context.next = 5;
1183
+ return fetch(url, {
1184
+ credentials: 'include'
1185
+ }).then(function (req) {
1186
+ return req.json();
1187
+ }).then(function (req) {
1188
+ return req.documents[0];
1189
+ });
1190
+
1191
+ case 5:
1192
+ revisionDoc = _context.sent;
1193
+
1194
+ if (!(!revisionDoc || revisionDoc._rev !== rev)) {
1195
+ _context.next = 12;
1196
+ break;
1197
+ }
1198
+
1199
+ baseUrl = "/data/history/" + dataset + "/documents/drafts." + documentId + "?revision=" + rev;
1200
+ url = client.getUrl(baseUrl);
1201
+ _context.next = 11;
1202
+ return fetch(url, {
1203
+ credentials: 'include'
1204
+ }).then(function (req) {
1205
+ return req.json();
1206
+ }).then(function (req) {
1207
+ return req.documents[0];
1208
+ });
1209
+
1210
+ case 11:
1211
+ revisionDoc = _context.sent;
1212
+
1213
+ case 12:
1214
+ return _context.abrupt("return", revisionDoc);
1215
+
1216
+ case 13:
1217
+ case "end":
1218
+ return _context.stop();
1219
+ }
1220
+ }
1221
+ }, _callee);
1222
+ }));
1223
+
1224
+ return function findDocumentAtRevision(_x, _x2) {
1225
+ return _ref.apply(this, arguments);
1226
+ };
1227
+ }(); //document-level patch
1228
+
1229
+ var documentLevelPatch = /*#__PURE__*/function () {
1230
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, translatedFields, localeId) {
1231
+ var baseDoc, merged, targetId, i18nDoc, cleanedMerge;
1232
+ return runtime_1.wrap(function _callee2$(_context2) {
1233
+ while (1) {
1234
+ switch (_context2.prev = _context2.next) {
1235
+ case 0:
1236
+ if (!translatedFields._rev) {
1237
+ _context2.next = 6;
1238
+ break;
1239
+ }
1240
+
1241
+ _context2.next = 3;
1242
+ return findDocumentAtRevision(documentId, translatedFields._rev);
1243
+
1244
+ case 3:
1245
+ baseDoc = _context2.sent;
1246
+ _context2.next = 9;
1247
+ break;
1248
+
1249
+ case 6:
1250
+ _context2.next = 8;
1251
+ return findLatestDraft(documentId);
1252
+
1253
+ case 8:
1254
+ baseDoc = _context2.sent;
1255
+
1256
+ case 9:
1257
+ merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.documentLevelMerge(translatedFields, baseDoc);
1258
+ targetId = "i18n." + documentId + "." + localeId;
1259
+ _context2.next = 13;
1260
+ return findLatestDraft(targetId, false);
1261
+
1262
+ case 13:
1263
+ i18nDoc = _context2.sent;
1264
+
1265
+ if (i18nDoc) {
1266
+ cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
1267
+
1268
+ Object.entries(merged).forEach(function (_ref3) {
1269
+ var key = _ref3[0],
1270
+ value = _ref3[1];
1271
+
1272
+ if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
1273
+ cleanedMerge[key] = value;
1274
+ }
1275
+ });
1276
+ client.transaction() //@ts-ignore
1277
+ .patch(i18nDoc._id, function (p) {
1278
+ return p.set(cleanedMerge);
1279
+ }).commit();
1280
+ } else {
1281
+ merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
1282
+
1283
+ if (baseDoc._lang) {
1284
+ merged._lang = localeId;
1285
+ } else if (baseDoc.__i18n_lang) {
1286
+ merged.__i18n_lang = localeId;
1287
+ }
1288
+
1289
+ client.create(merged);
1290
+ }
1291
+
1292
+ case 15:
1293
+ case "end":
1294
+ return _context2.stop();
1295
+ }
1296
+ }
1297
+ }, _callee2);
1298
+ }));
1299
+
1300
+ return function documentLevelPatch(_x3, _x4, _x5) {
1301
+ return _ref2.apply(this, arguments);
1302
+ };
1303
+ }(); //field level patch
1304
+
1305
+ var fieldLevelPatch = /*#__PURE__*/function () {
1306
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, translatedFields, localeId) {
1307
+ var baseDoc, merged;
1308
+ return runtime_1.wrap(function _callee3$(_context3) {
1309
+ while (1) {
1310
+ switch (_context3.prev = _context3.next) {
1311
+ case 0:
1312
+ if (!translatedFields._rev) {
1313
+ _context3.next = 6;
1314
+ break;
1315
+ }
1316
+
1317
+ _context3.next = 3;
1318
+ return findDocumentAtRevision(documentId, translatedFields._rev);
1319
+
1320
+ case 3:
1321
+ baseDoc = _context3.sent;
1322
+ _context3.next = 9;
1323
+ break;
1324
+
1325
+ case 6:
1326
+ _context3.next = 8;
1327
+ return findLatestDraft(documentId);
1328
+
1329
+ case 8:
1330
+ baseDoc = _context3.sent;
1331
+
1332
+ case 9:
1333
+ merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
1334
+ client.patch(baseDoc._id).set(merged).commit();
1335
+
1336
+ case 11:
1337
+ case "end":
1338
+ return _context3.stop();
1339
+ }
1340
+ }
1341
+ }, _callee3);
1342
+ }));
1343
+
1344
+ return function fieldLevelPatch(_x6, _x7, _x8) {
1345
+ return _ref4.apply(this, arguments);
1346
+ };
1347
+ }();
1348
+
2078
1349
  var defaultDocumentLevelConfig = {
2079
- exportForTranslation: function exportForTranslation(id) {
2080
- return BaseDocumentSerializer.serializeDocument(id, 'document', 'en', defaultStopTypes, customSerializers);
2081
- },
1350
+ exportForTranslation: /*#__PURE__*/function () {
1351
+ var _exportForTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) {
1352
+ var doc, serialized;
1353
+ return runtime_1.wrap(function _callee$(_context) {
1354
+ while (1) {
1355
+ switch (_context.prev = _context.next) {
1356
+ case 0:
1357
+ _context.next = 2;
1358
+ return findLatestDraft(id);
1359
+
1360
+ case 2:
1361
+ doc = _context.sent;
1362
+ serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'document');
1363
+ serialized.name = id;
1364
+ return _context.abrupt("return", serialized);
1365
+
1366
+ case 6:
1367
+ case "end":
1368
+ return _context.stop();
1369
+ }
1370
+ }
1371
+ }, _callee);
1372
+ }));
1373
+
1374
+ function exportForTranslation(_x) {
1375
+ return _exportForTranslation.apply(this, arguments);
1376
+ }
1377
+
1378
+ return exportForTranslation;
1379
+ }(),
2082
1380
  importTranslation: function importTranslation(id, localeId, document) {
2083
- return BaseDocumentDeserializer.deserializeDocument(id, document).then(function (deserialized) {
2084
- return BaseDocumentPatcher.documentLevelPatch(deserialized, id, localeId);
2085
- });
1381
+ var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1382
+ documentLevelPatch(id, deserialized, localeId);
2086
1383
  },
2087
- adapter: TransifexAdapter
1384
+ adapter: TransifexAdapter,
1385
+ secretsNamespace: 'transifex'
2088
1386
  };
2089
1387
  var defaultFieldLevelConfig = {
2090
- exportForTranslation: function exportForTranslation(id) {
2091
- return BaseDocumentSerializer.serializeDocument(id, 'field', 'en', defaultStopTypes, customSerializers);
2092
- },
1388
+ exportForTranslation: /*#__PURE__*/function () {
1389
+ var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id) {
1390
+ var doc, serialized;
1391
+ return runtime_1.wrap(function _callee2$(_context2) {
1392
+ while (1) {
1393
+ switch (_context2.prev = _context2.next) {
1394
+ case 0:
1395
+ _context2.next = 2;
1396
+ return findLatestDraft(id);
1397
+
1398
+ case 2:
1399
+ doc = _context2.sent;
1400
+ serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'field');
1401
+ serialized.name = id;
1402
+ return _context2.abrupt("return", serialized);
1403
+
1404
+ case 6:
1405
+ case "end":
1406
+ return _context2.stop();
1407
+ }
1408
+ }
1409
+ }, _callee2);
1410
+ }));
1411
+
1412
+ function exportForTranslation(_x2) {
1413
+ return _exportForTranslation2.apply(this, arguments);
1414
+ }
1415
+
1416
+ return exportForTranslation;
1417
+ }(),
2093
1418
  importTranslation: function importTranslation(id, localeId, document) {
2094
- return BaseDocumentDeserializer.deserializeDocument(id, document).then(function (deserialized) {
2095
- return BaseDocumentPatcher.fieldLevelPatch(deserialized, id, localeId, 'en');
2096
- });
1419
+ var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1420
+ fieldLevelPatch(id, deserialized, localeId);
2097
1421
  },
2098
- adapter: TransifexAdapter
1422
+ adapter: TransifexAdapter,
1423
+ secretsNamespace: 'transifex'
2099
1424
  };
2100
1425
 
2101
- exports.BaseDocumentDeserializer = BaseDocumentDeserializer;
2102
- exports.BaseDocumentPatcher = BaseDocumentPatcher;
2103
- exports.BaseDocumentSerializer = BaseDocumentSerializer;
1426
+ Object.defineProperty(exports, 'TranslationsTab', {
1427
+ enumerable: true,
1428
+ get: function () {
1429
+ return sanityTranslationsTab.TranslationsTab;
1430
+ }
1431
+ });
1432
+ Object.defineProperty(exports, 'BaseDocumentDeserializer', {
1433
+ enumerable: true,
1434
+ get: function () {
1435
+ return sanityNaiveHtmlSerializer.BaseDocumentDeserializer;
1436
+ }
1437
+ });
1438
+ Object.defineProperty(exports, 'BaseDocumentMerger', {
1439
+ enumerable: true,
1440
+ get: function () {
1441
+ return sanityNaiveHtmlSerializer.BaseDocumentMerger;
1442
+ }
1443
+ });
1444
+ Object.defineProperty(exports, 'BaseDocumentSerializer', {
1445
+ enumerable: true,
1446
+ get: function () {
1447
+ return sanityNaiveHtmlSerializer.BaseDocumentSerializer;
1448
+ }
1449
+ });
1450
+ Object.defineProperty(exports, 'customSerializers', {
1451
+ enumerable: true,
1452
+ get: function () {
1453
+ return sanityNaiveHtmlSerializer.customSerializers;
1454
+ }
1455
+ });
1456
+ Object.defineProperty(exports, 'defaultStopTypes', {
1457
+ enumerable: true,
1458
+ get: function () {
1459
+ return sanityNaiveHtmlSerializer.defaultStopTypes;
1460
+ }
1461
+ });
2104
1462
  exports.TransifexAdapter = TransifexAdapter;
2105
- exports.TranslationTab = TranslationTab;
2106
- exports.customSerializers = customSerializers;
2107
1463
  exports.defaultDocumentLevelConfig = defaultDocumentLevelConfig;
2108
1464
  exports.defaultFieldLevelConfig = defaultFieldLevelConfig;
2109
- exports.defaultStopTypes = defaultStopTypes;
2110
1465
  //# sourceMappingURL=sanity-plugin-transifex.cjs.development.js.map