Socket
Socket
Sign inDemoInstall

sanity-translations-tab

Package Overview
Dependencies
123
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.44 to 1.2.0

3

dist/components/TranslationContext.d.ts
import React from 'react';
import { Adapter, Secrets } from '../types';
import { Adapter, Secrets, WorkflowIdentifiers } from '../types';
export declare type ContextProps = {

@@ -10,3 +10,4 @@ documentId: string;

secrets: Secrets;
workflowOptions?: WorkflowIdentifiers[];
};
export declare const TranslationContext: React.Context<ContextProps | null>;
/// <reference types="react" />
import { SanityDocument } from '@sanity/client';
import { Adapter } from '../types';
import { Adapter, WorkflowIdentifiers } from '../types';
declare type TranslationTabProps = {

@@ -14,2 +14,3 @@ document: {

importTranslation: (id: string, localeId: string, doc: Record<string, any>) => Promise<void>;
workflowOptions?: WorkflowIdentifiers[];
};

@@ -16,0 +17,0 @@ };

@@ -11,2 +11,3 @@ 'use strict';

var ui = require('@sanity/ui');
var styled = _interopDefault(require('styled-components'));
var icons = require('@sanity/icons');

@@ -53,2 +54,11 @@ var sanityClient = _interopDefault(require('part:@sanity/base/client'));

function _taggedTemplateLiteralLoose(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}
strings.raw = raw;
return strings;
}
function createCommonjsModule(fn, module) {

@@ -146,5 +156,5 @@ return module = { exports: {} }, fn(module, module.exports), module.exports;

var IteratorPrototype = {};
IteratorPrototype[iteratorSymbol] = function () {
define(IteratorPrototype, iteratorSymbol, function () {
return this;
};
});

@@ -163,4 +173,5 @@ var getProto = Object.getPrototypeOf;

Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
GeneratorFunctionPrototype.constructor = GeneratorFunction;
GeneratorFunction.prototype = GeneratorFunctionPrototype;
define(Gp, "constructor", GeneratorFunctionPrototype);
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
GeneratorFunction.displayName = define(

@@ -279,5 +290,5 @@ GeneratorFunctionPrototype,

defineIteratorMethods(AsyncIterator.prototype);
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
};
});
exports.AsyncIterator = AsyncIterator;

@@ -475,9 +486,9 @@

// See https://github.com/facebook/regenerator/issues/274 for more details.
Gp[iteratorSymbol] = function() {
define(Gp, iteratorSymbol, function() {
return this;
};
});
Gp.toString = function() {
define(Gp, "toString", function() {
return "[object Generator]";
};
});

@@ -801,3 +812,4 @@ function pushTryEntry(locs) {

// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, we can escape
// in case runtime.js accidentally runs in strict mode, in modern engines
// we can explicitly access globalThis. In older engines we can escape
// strict mode using a global Function call. This could conceivably fail

@@ -809,6 +821,13 @@ // if a Content Security Policy forbids using Function, but in that case

// problems, please detail your unique predicament in a GitHub issue.
Function("r", "regeneratorRuntime = r")(runtime);
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
}
}
});
var _templateObject;
var WrapText = /*#__PURE__*/styled(ui.Box)(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n white-space: normal;\n"])));
var LocaleCheckbox = function LocaleCheckbox(_ref) {

@@ -820,3 +839,2 @@ var locale = _ref.locale,

mode: "ghost",
tone: "positive",
onClick: function onClick() {

@@ -841,3 +859,3 @@ toggle(locale.localeId, !checked);

onChange: function onChange() {}
}), React__default.createElement(ui.Box, null, React__default.createElement(ui.Text, {
}), React__default.createElement(WrapText, null, React__default.createElement(ui.Text, {
size: 1,

@@ -857,2 +875,6 @@ weight: "semibold"

var _React$useState2 = React__default.useState(),
selectedWorkflowUid = _React$useState2[0],
setSelectedWorkflowUid = _React$useState2[1];
var _useState = React.useState(false),

@@ -891,3 +913,3 @@ isBusy = _useState[0],

context.exportForTranslation(context.documentId).then(function (serialized) {
return context.adapter.createTask(context.documentId, serialized, selectedLocales, context.secrets);
return context.adapter.createTask(context.documentId, serialized, selectedLocales, context.secrets, selectedWorkflowUid);
}).then(function () {

@@ -914,2 +936,9 @@ setIsBusy(false);

return React__default.createElement(ui.Stack, {
paddingTop: 4,
space: 4
}, React__default.createElement(ui.Text, {
as: "h2",
weight: "semibold",
size: 2
}, "Create New Translation Job"), React__default.createElement(ui.Stack, {
space: 3

@@ -947,7 +976,26 @@ }, React__default.createElement(ui.Flex, {

});
})), React__default.createElement(ui.Button, {
}))), (context == null ? void 0 : context.workflowOptions) && context.workflowOptions.length > 0 && React__default.createElement(ui.Stack, {
space: 3
}, React__default.createElement(ui.Text, {
weight: "semibold",
size: 1,
as: "label",
htmlFor: "workflow-select"
}, "Select translation workflow"), React__default.createElement(ui.Grid, {
columns: [1, 1, 2]
}, React__default.createElement(ui.Select, {
id: "workflowSelect",
onChange: function onChange(e) {
setSelectedWorkflowUid(e.target.value);
}
}, React__default.createElement("option", null, "Default locale workflows"), context.workflowOptions.map(function (w) {
return React__default.createElement("option", {
key: "workflow-opt-" + w.workflowUid,
value: w.workflowUid
}, w.workflowName);
})))), React__default.createElement(ui.Button, {
onClick: createTask,
disabled: isBusy || !selectedLocales.length,
tone: "positive",
text: "Create new job"
text: "Create Job"
}));

@@ -1059,7 +1107,8 @@ };

return React__default.createElement(ui.Stack, {
space: 3
space: 4
}, React__default.createElement(ui.Text, {
as: "h2",
weight: "semibold",
size: 1
}, "Current job progress"), React__default.createElement(ui.Box, null, task.locales.map(function (localeTask) {
size: 2
}, "Current Job Progress"), React__default.createElement(ui.Box, null, task.locales.map(function (localeTask) {
var reportPercent = localeTask.progress || 0;

@@ -1132,3 +1181,3 @@ var locale = locales.find(function (l) {

return React__default.createElement(ui.Stack, {
space: 5
space: 6
}, React__default.createElement(NewTask, {

@@ -1283,3 +1332,4 @@ locales: locales

adapter: props.options.adapter,
baseLanguage: props.options.baseLanguage
baseLanguage: props.options.baseLanguage,
workflowOptions: props.options.workflowOptions
}

@@ -1286,0 +1336,0 @@ }, React__default.createElement(TranslationView, null))))));

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=e(t),r=require("@sanity/util/content"),o=require("@sanity/ui"),a=require("@sanity/icons"),i=e(require("part:@sanity/base/client")),c=n.createContext(null);function u(e,t,n,r,o,a,i){try{var c=e[a](i),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,o)}function l(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){u(a,r,o,i,c,"next",e)}function c(e){u(a,r,o,i,c,"throw",e)}i(void 0)}))}}var s,f=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,r){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new k(r||[]);return o._invoke=function(e,t,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return{value:void 0,done:!0}}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var c=x(i,n);if(c){if(c===s)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var u=l(e,t,n);if("normal"===u.type){if(r=n.done?"completed":"suspendedYield",u.arg===s)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r="completed",n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var s={};function f(){}function d(){}function p(){}var h={};h[o]=function(){return this};var m=Object.getPrototypeOf,v=m&&m(m(T([])));v&&v!==t&&n.call(v,o)&&(h=v);var g=p.prototype=f.prototype=Object.create(h);function y(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){var r;this._invoke=function(o,a){function i(){return new t((function(r,i){!function r(o,a,i,c){var u=l(e[o],e,a);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,c)}),(function(e){r("throw",e,i,c)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return r("throw",e,i,c)}))}c(u.arg)}(o,a,r,i)}))}return r=r?r.then(i,i):i()}}function x(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=l(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,s;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function E(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function b(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function T(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:S}}function S(){return{value:void 0,done:!0}}return d.prototype=g.constructor=p,p.constructor=d,d.displayName=c(p,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,i,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},y(w.prototype),w.prototype[a]=function(){return this},e.AsyncIterator=w,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new w(u(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},y(g),c(g,i,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=T,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return i.type="throw",i.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,s):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;b(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(s={exports:{}}),s.exports),d=function(e){var t=e.locale,r=e.toggle,a=e.checked;return n.createElement(o.Button,{mode:"ghost",tone:"positive",onClick:function(){r(t.localeId,!a)},disabled:!1===t.enabled,style:{cursor:"pointer"},radius:2},n.createElement(o.Flex,{align:"center",gap:3},n.createElement(o.Switch,{style:{pointerEvents:"none"},disabled:!1===t.enabled,checked:a,onChange:function(){}}),n.createElement(o.Box,null,n.createElement(o.Text,{size:1,weight:"semibold"},t.description))))},p=function(e){var r=e.locales,a=n.useState([]),i=a[0],u=a[1],s=t.useState(!1),p=s[0],h=s[1],m=t.useContext(c),v=function(){var e=l(f.mark((function e(){return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m){e.next=3;break}return console.error("Missing context"),e.abrupt("return");case 3:h(!0),m.exportForTranslation(m.documentId).then((function(e){return m.adapter.createTask(m.documentId,e,i,m.secrets)})).then((function(){h(!1)}));case 5:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),g=r.filter((function(e){return!1!==e.enabled}));return n.createElement(o.Stack,{space:3},n.createElement(o.Flex,{align:"center",justify:"space-between"},n.createElement(o.Text,{weight:"semibold",size:1},1===g.length?"Select locale":"Select locales"),n.createElement(o.Button,{fontSize:1,padding:2,text:"Toggle All",onClick:function(){return u(g.length===i.length?[]:r.filter((function(e){return!1!==e.enabled})).map((function(e){return e.localeId})))}})),n.createElement(o.Grid,{columns:[1,1,2,3],gap:1},(r||[]).map((function(e){return n.createElement(d,{key:e.localeId,locale:e,toggle:function(e,t){return function(e,t){t?i.includes(e)||u([].concat(i,[e])):u(i.filter((function(t){return t!==e})))}(e,t)},checked:i.includes(e.localeId)})}))),n.createElement(o.Button,{onClick:v,disabled:p||!i.length,tone:"positive",text:"Create new job"}))};function h(e){var t=e.progress;return t?n.createElement(o.Card,{border:!0,radius:2,style:{width:"100%",position:"relative"}},n.createElement(o.Flex,{style:{position:"absolute",left:0,right:0,top:0,bottom:0,zIndex:1},align:"center",justify:"center"},n.createElement(o.Label,{size:1},t,"%")),n.createElement(o.Card,{style:{width:"100%",transform:"scaleX("+t/100+")",transformOrigin:"left",transition:"transform .2s ease",boxSizing:"border-box"},padding:2,tone:"positive"})):null}var m=function(e){var t=e.progress,r=e.importFile;return n.createElement(o.Card,{shadow:1},n.createElement(o.Grid,{columns:5,gap:3,padding:3},n.createElement(o.Flex,{columnStart:1,columnEnd:3,align:"center"},n.createElement(o.Text,{weight:"bold",size:1},e.title)),t&&t>0?n.createElement(o.Flex,{columnStart:3,columnEnd:5,align:"center"},n.createElement(h,{progress:t})):null,n.createElement(o.Box,{columnStart:5,columnEnd:6},n.createElement(o.Button,{style:{width:"100%"},mode:"ghost",onClick:function(){return r()},text:"Import",tone:"positive",icon:a.DownloadIcon}))))},v=function(e){var r=e.task,a=e.locales,i=t.useContext(c),u=o.useToast();return n.createElement(o.Stack,{space:3},n.createElement(o.Text,{weight:"semibold",size:1},"Current job progress"),n.createElement(o.Box,null,r.locales.map((function(e){var t=e.progress||0,o=a.find((function(t){return t.localeId===e.localeId}));return n.createElement(m,{key:[r.taskId,e.localeId].join("."),importFile:function(){var t;t=e.localeId,i?i.adapter.getTranslation(r.taskId,t,i.secrets).then((function(e){e?i.importTranslation(t,e):alert("Error getting the translated content!")})):console.error("Missing context"),u.push({title:"Hello",status:"info"})},title:(null==o?void 0:o.description)||e.localeId,progress:t})}))))},g=function(){var e=t.useState([]),r=e[0],a=e[1],i=t.useState(null),u=i[0],s=i[1],d=t.useContext(c);return t.useEffect((function(){function e(){return(e=l(f.mark((function e(){return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d){e.next=3;break}return console.error("Missing context"),e.abrupt("return");case 3:d.adapter.getLocales(d.secrets).then(a).then((function(){return d.adapter.getTranslationTask(d.documentId,d.secrets)})).then(s);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[d]),n.createElement(o.Stack,{space:5},n.createElement(p,{locales:r}),u&&n.createElement(v,{task:u,locales:r}))},y=i.withConfig({apiVersion:"2021-03-25"}),w=function(){var e=window.localStorage.getItem("dummyTasks");return e?JSON.parse(e):[]},x=function(e){var t=w();window.localStorage.setItem("dummyTasks",JSON.stringify([].concat(t,[e])))},E=function(e){return w().find((function(t){return t.taskId===e}))||null};exports.DummyAdapter={getLocales:function(){var e=l(f.mark((function e(){return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){e([{enabled:!0,description:"German",localeId:"de"},{enabled:!0,description:"Norwegian (Bokmål)",localeId:"no_nb"},{enabled:!1,description:"Icelandic",localeId:"is"}])})));case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),getTranslationTask:function(){var e=l(f.mark((function e(t){return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.debug("Fetching translation tasks for document",t),e.abrupt("return",new Promise((function(e){var t=w();e(t.length?t[t.length-1]:null)})));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),createTask:function(){var e=l(f.mark((function e(t,n,r){return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.debug("Sending over serialized document",n),e.abrupt("return",new Promise((function(e){var n={taskId:(new Date).getTime().toString(),documentId:t,locales:r.map((function(e){return{localeId:e,progress:80}}))};x(n),e(n)})));case 2:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),getTranslation:function(){var e=l(f.mark((function e(t,n){var r;return f.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.debug("Fetching translation for locale",n),e.next=3,setTimeout((function(){}),1e3);case 3:if(r=E(t)){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",new Promise((function(e){e({_id:r.documentId,title:"This is just a dummy translation"})})));case 7:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}()},exports.TranslationsTab=function(e){var a=e.document.displayed,i=a&&a._id?a._id.split("drafts.").pop():"",u=t.useMemo((function(){var t=[],o=e.options.importTranslation;o||t.push({key:r.randomKey(12),text:n.createElement(n.Fragment,null,"You need to provide an ",n.createElement("code",null,"importTranslation")," function. See documentation.")});var a=e.options.exportForTranslation;return a||t.push({key:r.randomKey(12),text:n.createElement(n.Fragment,null,"You need to provide an ",n.createElement("code",null,"exportForTranslation")," function. See documentation.")}),{errors:t,importTranslation:function(e,t){return o(i,e,t)},exportForTranslation:function(e){return a(e)}}}),[e.options,i]),s=u.errors,d=u.importTranslation,p=u.exportForTranslation,h=function(e){var n=t.useState(!0),r=n[0],o=n[1],a=t.useState(null),i=a[0],c=a[1];return t.useEffect((function(){function t(){return(t=l(f.mark((function t(){return f.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:y.fetch("* [_id == $id][0]",{id:e}).then((function(e){var t={};for(var n in e)"_"!==n[0]&&(t[n]=e[n]);c(t),o(!1)}));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}!function(){t.apply(this,arguments)}()}),[e]),{loading:r,secrets:i}}((e.options.secretsNamespace||"translationService")+".secrets"),m=h.secrets,v=s.length>0;return n.createElement(o.ThemeProvider,null,h.loading||!m?n.createElement(o.Flex,{padding:5,align:"center",justify:"center"},n.createElement(o.Spinner,null)):n.createElement(o.Box,{padding:4},m?n.createElement(o.Layer,{zOffset:1e3},n.createElement(o.ToastProvider,null,v&&n.createElement(o.Stack,{space:3},s.map((function(e){return n.createElement(o.Card,{key:e.key,tone:"caution",padding:[2,3,4,4],shadow:1,radius:2},n.createElement(o.Text,null,e.text))}))),!v&&n.createElement(c.Provider,{value:{documentId:i,secrets:m,importTranslation:d,exportForTranslation:p,adapter:e.options.adapter,baseLanguage:e.options.baseLanguage}},n.createElement(g,null)))):n.createElement(o.Card,{tone:"caution",padding:[2,3,4,4],shadow:1,radius:2},n.createElement(o.Text,null,"Can't find secrets for your translation service. Did you load them into this dataset?"))))};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=e(t),r=require("@sanity/util/content"),o=require("@sanity/ui"),a=e(require("styled-components")),i=require("@sanity/icons"),c=e(require("part:@sanity/base/client")),l=n.createContext(null);function u(e,t,n,r,o,a,i){try{var c=e[a](i),l=c.value}catch(e){return void n(e)}c.done?t(l):Promise.resolve(l).then(r,o)}function s(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){u(a,r,o,i,c,"next",e)}function c(e){u(a,r,o,i,c,"throw",e)}i(void 0)}))}}function f(e,t){return t||(t=e.slice(0)),e.raw=t,e}var d,p,h=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new k(r||[]);return o._invoke=function(e,t,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return{value:void 0,done:!0}}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var c=E(i,n);if(c){if(c===s)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=u(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===s)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}(e,n,a),o}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var s={};function f(){}function d(){}function p(){}var h={};c(h,o,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(T([])));g&&g!==t&&n.call(g,o)&&(h=g);var v=p.prototype=f.prototype=Object.create(h);function y(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){var r;this._invoke=function(o,a){function i(){return new t((function(r,i){!function r(o,a,i,c){var l=u(e[o],e,a);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,c)}),(function(e){r("throw",e,i,c)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return r("throw",e,i,c)}))}c(l.arg)}(o,a,r,i)}))}return r=r?r.then(i,i):i()}}function E(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,E(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,s;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function x(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function b(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(x,this),this.reset(!0)}function T(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:S}}function S(){return{value:void 0,done:!0}}return d.prototype=p,c(v,"constructor",p),c(p,"constructor",d),d.displayName=c(p,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,i,"GeneratorFunction")),e.prototype=Object.create(v),e},e.awrap=function(e){return{__await:e}},y(w.prototype),c(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new w(l(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},y(v),c(v,i,"Generator"),c(v,o,(function(){return this})),c(v,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=T,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return i.type="throw",i.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(c&&l){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,s):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;b(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(p={exports:{}}),p.exports),m=a(o.Box)(d||(d=f(["\n white-space: normal;\n"]))),g=function(e){var t=e.locale,r=e.toggle,a=e.checked;return n.createElement(o.Button,{mode:"ghost",onClick:function(){r(t.localeId,!a)},disabled:!1===t.enabled,style:{cursor:"pointer"},radius:2},n.createElement(o.Flex,{align:"center",gap:3},n.createElement(o.Switch,{style:{pointerEvents:"none"},disabled:!1===t.enabled,checked:a,onChange:function(){}}),n.createElement(m,null,n.createElement(o.Text,{size:1,weight:"semibold"},t.description))))},v=function(e){var r=e.locales,a=n.useState([]),i=a[0],c=a[1],u=n.useState(),f=u[0],d=u[1],p=t.useState(!1),m=p[0],v=p[1],y=t.useContext(l),w=function(){var e=s(h.mark((function e(){return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(y){e.next=3;break}return console.error("Missing context"),e.abrupt("return");case 3:v(!0),y.exportForTranslation(y.documentId).then((function(e){return y.adapter.createTask(y.documentId,e,i,y.secrets,f)})).then((function(){v(!1)}));case 5:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),E=r.filter((function(e){return!1!==e.enabled}));return n.createElement(o.Stack,{paddingTop:4,space:4},n.createElement(o.Text,{as:"h2",weight:"semibold",size:2},"Create New Translation Job"),n.createElement(o.Stack,{space:3},n.createElement(o.Flex,{align:"center",justify:"space-between"},n.createElement(o.Text,{weight:"semibold",size:1},1===E.length?"Select locale":"Select locales"),n.createElement(o.Button,{fontSize:1,padding:2,text:"Toggle All",onClick:function(){return c(E.length===i.length?[]:r.filter((function(e){return!1!==e.enabled})).map((function(e){return e.localeId})))}})),n.createElement(o.Grid,{columns:[1,1,2,3],gap:1},(r||[]).map((function(e){return n.createElement(g,{key:e.localeId,locale:e,toggle:function(e,t){return function(e,t){t?i.includes(e)||c([].concat(i,[e])):c(i.filter((function(t){return t!==e})))}(e,t)},checked:i.includes(e.localeId)})})))),(null==y?void 0:y.workflowOptions)&&y.workflowOptions.length>0&&n.createElement(o.Stack,{space:3},n.createElement(o.Text,{weight:"semibold",size:1,as:"label",htmlFor:"workflow-select"},"Select translation workflow"),n.createElement(o.Grid,{columns:[1,1,2]},n.createElement(o.Select,{id:"workflowSelect",onChange:function(e){d(e.target.value)}},n.createElement("option",null,"Default locale workflows"),y.workflowOptions.map((function(e){return n.createElement("option",{key:"workflow-opt-"+e.workflowUid,value:e.workflowUid},e.workflowName)}))))),n.createElement(o.Button,{onClick:w,disabled:m||!i.length,tone:"positive",text:"Create Job"}))};function y(e){var t=e.progress;return t?n.createElement(o.Card,{border:!0,radius:2,style:{width:"100%",position:"relative"}},n.createElement(o.Flex,{style:{position:"absolute",left:0,right:0,top:0,bottom:0,zIndex:1},align:"center",justify:"center"},n.createElement(o.Label,{size:1},t,"%")),n.createElement(o.Card,{style:{width:"100%",transform:"scaleX("+t/100+")",transformOrigin:"left",transition:"transform .2s ease",boxSizing:"border-box"},padding:2,tone:"positive"})):null}var w=function(e){var t=e.progress,r=e.importFile;return n.createElement(o.Card,{shadow:1},n.createElement(o.Grid,{columns:5,gap:3,padding:3},n.createElement(o.Flex,{columnStart:1,columnEnd:3,align:"center"},n.createElement(o.Text,{weight:"bold",size:1},e.title)),t&&t>0?n.createElement(o.Flex,{columnStart:3,columnEnd:5,align:"center"},n.createElement(y,{progress:t})):null,n.createElement(o.Box,{columnStart:5,columnEnd:6},n.createElement(o.Button,{style:{width:"100%"},mode:"ghost",onClick:function(){return r()},text:"Import",tone:"positive",icon:i.DownloadIcon}))))},E=function(e){var r=e.task,a=e.locales,i=t.useContext(l),c=o.useToast();return n.createElement(o.Stack,{space:4},n.createElement(o.Text,{as:"h2",weight:"semibold",size:2},"Current Job Progress"),n.createElement(o.Box,null,r.locales.map((function(e){var t=e.progress||0,o=a.find((function(t){return t.localeId===e.localeId}));return n.createElement(w,{key:[r.taskId,e.localeId].join("."),importFile:function(){var t;t=e.localeId,i?i.adapter.getTranslation(r.taskId,t,i.secrets).then((function(e){e?i.importTranslation(t,e):alert("Error getting the translated content!")})):console.error("Missing context"),c.push({title:"Hello",status:"info"})},title:(null==o?void 0:o.description)||e.localeId,progress:t})}))))},x=function(){var e=t.useState([]),r=e[0],a=e[1],i=t.useState(null),c=i[0],u=i[1],f=t.useContext(l);return t.useEffect((function(){function e(){return(e=s(h.mark((function e(){return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(f){e.next=3;break}return console.error("Missing context"),e.abrupt("return");case 3:f.adapter.getLocales(f.secrets).then(a).then((function(){return f.adapter.getTranslationTask(f.documentId,f.secrets)})).then(u);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[f]),n.createElement(o.Stack,{space:6},n.createElement(v,{locales:r}),c&&n.createElement(E,{task:c,locales:r}))},b=c.withConfig({apiVersion:"2021-03-25"}),k=function(){var e=window.localStorage.getItem("dummyTasks");return e?JSON.parse(e):[]},T=function(e){var t=k();window.localStorage.setItem("dummyTasks",JSON.stringify([].concat(t,[e])))},S=function(e){return k().find((function(t){return t.taskId===e}))||null};exports.DummyAdapter={getLocales:function(){var e=s(h.mark((function e(){return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){e([{enabled:!0,description:"German",localeId:"de"},{enabled:!0,description:"Norwegian (Bokmål)",localeId:"no_nb"},{enabled:!1,description:"Icelandic",localeId:"is"}])})));case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),getTranslationTask:function(){var e=s(h.mark((function e(t){return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.debug("Fetching translation tasks for document",t),e.abrupt("return",new Promise((function(e){var t=k();e(t.length?t[t.length-1]:null)})));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),createTask:function(){var e=s(h.mark((function e(t,n,r){return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.debug("Sending over serialized document",n),e.abrupt("return",new Promise((function(e){var n={taskId:(new Date).getTime().toString(),documentId:t,locales:r.map((function(e){return{localeId:e,progress:80}}))};T(n),e(n)})));case 2:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),getTranslation:function(){var e=s(h.mark((function e(t,n){var r;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.debug("Fetching translation for locale",n),e.next=3,setTimeout((function(){}),1e3);case 3:if(r=S(t)){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",new Promise((function(e){e({_id:r.documentId,title:"This is just a dummy translation"})})));case 7:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}()},exports.TranslationsTab=function(e){var a=e.document.displayed,i=a&&a._id?a._id.split("drafts.").pop():"",c=t.useMemo((function(){var t=[],o=e.options.importTranslation;o||t.push({key:r.randomKey(12),text:n.createElement(n.Fragment,null,"You need to provide an ",n.createElement("code",null,"importTranslation")," function. See documentation.")});var a=e.options.exportForTranslation;return a||t.push({key:r.randomKey(12),text:n.createElement(n.Fragment,null,"You need to provide an ",n.createElement("code",null,"exportForTranslation")," function. See documentation.")}),{errors:t,importTranslation:function(e,t){return o(i,e,t)},exportForTranslation:function(e){return a(e)}}}),[e.options,i]),u=c.errors,f=c.importTranslation,d=c.exportForTranslation,p=function(e){var n=t.useState(!0),r=n[0],o=n[1],a=t.useState(null),i=a[0],c=a[1];return t.useEffect((function(){function t(){return(t=s(h.mark((function t(){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:b.fetch("* [_id == $id][0]",{id:e}).then((function(e){var t={};for(var n in e)"_"!==n[0]&&(t[n]=e[n]);c(t),o(!1)}));case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}!function(){t.apply(this,arguments)}()}),[e]),{loading:r,secrets:i}}((e.options.secretsNamespace||"translationService")+".secrets"),m=p.secrets,g=u.length>0;return n.createElement(o.ThemeProvider,null,p.loading||!m?n.createElement(o.Flex,{padding:5,align:"center",justify:"center"},n.createElement(o.Spinner,null)):n.createElement(o.Box,{padding:4},m?n.createElement(o.Layer,{zOffset:1e3},n.createElement(o.ToastProvider,null,g&&n.createElement(o.Stack,{space:3},u.map((function(e){return n.createElement(o.Card,{key:e.key,tone:"caution",padding:[2,3,4,4],shadow:1,radius:2},n.createElement(o.Text,null,e.text))}))),!g&&n.createElement(l.Provider,{value:{documentId:i,secrets:m,importTranslation:f,exportForTranslation:d,adapter:e.options.adapter,baseLanguage:e.options.baseLanguage,workflowOptions:e.options.workflowOptions}},n.createElement(x,null)))):n.createElement(o.Card,{tone:"caution",padding:[2,3,4,4],shadow:1,radius:2},n.createElement(o.Text,null,"Can't find secrets for your translation service. Did you load them into this dataset?"))))};
//# sourceMappingURL=sanity-translations-tab.cjs.production.min.js.map
import React, { useState, useContext, useEffect, useMemo } from 'react';
import { randomKey } from '@sanity/util/content';
import { Stack, Flex, Text, Button, Grid, Switch, Box, Card, Label, useToast, ThemeProvider, Spinner, Layer, ToastProvider } from '@sanity/ui';
import { Stack, Text, Flex, Button, Grid, Select, Switch, Box, Card, Label, useToast, ThemeProvider, Spinner, Layer, ToastProvider } from '@sanity/ui';
import styled from 'styled-components';
import { DownloadIcon } from '@sanity/icons';

@@ -45,2 +46,11 @@ import sanityClient from 'part:@sanity/base/client';

function _taggedTemplateLiteralLoose(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}
strings.raw = raw;
return strings;
}
function createCommonjsModule(fn, module) {

@@ -138,5 +148,5 @@ return module = { exports: {} }, fn(module, module.exports), module.exports;

var IteratorPrototype = {};
IteratorPrototype[iteratorSymbol] = function () {
define(IteratorPrototype, iteratorSymbol, function () {
return this;
};
});

@@ -155,4 +165,5 @@ var getProto = Object.getPrototypeOf;

Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
GeneratorFunctionPrototype.constructor = GeneratorFunction;
GeneratorFunction.prototype = GeneratorFunctionPrototype;
define(Gp, "constructor", GeneratorFunctionPrototype);
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
GeneratorFunction.displayName = define(

@@ -271,5 +282,5 @@ GeneratorFunctionPrototype,

defineIteratorMethods(AsyncIterator.prototype);
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
};
});
exports.AsyncIterator = AsyncIterator;

@@ -467,9 +478,9 @@

// See https://github.com/facebook/regenerator/issues/274 for more details.
Gp[iteratorSymbol] = function() {
define(Gp, iteratorSymbol, function() {
return this;
};
});
Gp.toString = function() {
define(Gp, "toString", function() {
return "[object Generator]";
};
});

@@ -793,3 +804,4 @@ function pushTryEntry(locs) {

// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, we can escape
// in case runtime.js accidentally runs in strict mode, in modern engines
// we can explicitly access globalThis. In older engines we can escape
// strict mode using a global Function call. This could conceivably fail

@@ -801,6 +813,13 @@ // if a Content Security Policy forbids using Function, but in that case

// problems, please detail your unique predicament in a GitHub issue.
Function("r", "regeneratorRuntime = r")(runtime);
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
}
}
});
var _templateObject;
var WrapText = /*#__PURE__*/styled(Box)(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n white-space: normal;\n"])));
var LocaleCheckbox = function LocaleCheckbox(_ref) {

@@ -812,3 +831,2 @@ var locale = _ref.locale,

mode: "ghost",
tone: "positive",
onClick: function onClick() {

@@ -833,3 +851,3 @@ toggle(locale.localeId, !checked);

onChange: function onChange() {}
}), React.createElement(Box, null, React.createElement(Text, {
}), React.createElement(WrapText, null, React.createElement(Text, {
size: 1,

@@ -849,2 +867,6 @@ weight: "semibold"

var _React$useState2 = React.useState(),
selectedWorkflowUid = _React$useState2[0],
setSelectedWorkflowUid = _React$useState2[1];
var _useState = useState(false),

@@ -883,3 +905,3 @@ isBusy = _useState[0],

context.exportForTranslation(context.documentId).then(function (serialized) {
return context.adapter.createTask(context.documentId, serialized, selectedLocales, context.secrets);
return context.adapter.createTask(context.documentId, serialized, selectedLocales, context.secrets, selectedWorkflowUid);
}).then(function () {

@@ -906,2 +928,9 @@ setIsBusy(false);

return React.createElement(Stack, {
paddingTop: 4,
space: 4
}, React.createElement(Text, {
as: "h2",
weight: "semibold",
size: 2
}, "Create New Translation Job"), React.createElement(Stack, {
space: 3

@@ -939,7 +968,26 @@ }, React.createElement(Flex, {

});
})), React.createElement(Button, {
}))), (context == null ? void 0 : context.workflowOptions) && context.workflowOptions.length > 0 && React.createElement(Stack, {
space: 3
}, React.createElement(Text, {
weight: "semibold",
size: 1,
as: "label",
htmlFor: "workflow-select"
}, "Select translation workflow"), React.createElement(Grid, {
columns: [1, 1, 2]
}, React.createElement(Select, {
id: "workflowSelect",
onChange: function onChange(e) {
setSelectedWorkflowUid(e.target.value);
}
}, React.createElement("option", null, "Default locale workflows"), context.workflowOptions.map(function (w) {
return React.createElement("option", {
key: "workflow-opt-" + w.workflowUid,
value: w.workflowUid
}, w.workflowName);
})))), React.createElement(Button, {
onClick: createTask,
disabled: isBusy || !selectedLocales.length,
tone: "positive",
text: "Create new job"
text: "Create Job"
}));

@@ -1051,7 +1099,8 @@ };

return React.createElement(Stack, {
space: 3
space: 4
}, React.createElement(Text, {
as: "h2",
weight: "semibold",
size: 1
}, "Current job progress"), React.createElement(Box, null, task.locales.map(function (localeTask) {
size: 2
}, "Current Job Progress"), React.createElement(Box, null, task.locales.map(function (localeTask) {
var reportPercent = localeTask.progress || 0;

@@ -1124,3 +1173,3 @@ var locale = locales.find(function (l) {

return React.createElement(Stack, {
space: 5
space: 6
}, React.createElement(NewTask, {

@@ -1275,3 +1324,4 @@ locales: locales

adapter: props.options.adapter,
baseLanguage: props.options.baseLanguage
baseLanguage: props.options.baseLanguage,
workflowOptions: props.options.workflowOptions
}

@@ -1278,0 +1328,0 @@ }, React.createElement(TranslationView, null))))));

@@ -21,7 +21,11 @@ export declare type TranslationTask = {

};
export declare type WorkflowIdentifiers = {
workflowUid: string;
workflowName: string;
};
export interface Adapter {
getLocales: (secrets: Secrets | null) => Promise<TranslationLocale[]>;
getTranslationTask: (documentId: string, secrets: Secrets | null) => Promise<TranslationTask | null>;
createTask: (documentId: string, document: Record<string, any>, localeIds: string[], secrets: Secrets | null) => Promise<TranslationTask>;
createTask: (documentId: string, document: Record<string, any>, localeIds: string[], secrets: Secrets | null, workflowUid?: string) => Promise<TranslationTask>;
getTranslation: (taskid: string, localeId: string, secrets: Secrets | null) => Promise<any | null>;
}
{
"version": "1.1.44",
"version": "1.2.0",
"license": "MIT",

@@ -27,3 +27,3 @@ "main": "dist/index.js",

"react-dom": "^16 || ^17",
"styled-components": "^5"
"styled-components": "^5.3.3"
},

@@ -43,2 +43,5 @@ "husky": {

"author": "Sanity.io",
"contributors": [
"annie@all-turtles.com"
],
"module": "dist/sanity-translations-tab.esm.js",

@@ -67,2 +70,3 @@ "size-limit": [

"@types/react": "^16.9.56",
"@types/styled-components": "^5.1.20",
"husky": "^4.3.0",

@@ -69,0 +73,0 @@ "size-limit": "^4.7.0",

@@ -5,4 +5,6 @@ # sanity-translations-tab

## Development
For guidelines on contributing to this document
## In-studio development
1. Clone this repo into a Studio's `plugins` directory.

@@ -31,4 +33,4 @@ 2. Add `"sanity-translations-tab"` to the `plugins` key of `sanity.json`

// These two async functions are expected by the plugin
exportForTranslation: async (props) => props,
importTranslation: async (props) => props,
exportForTranslation: async props => props,
importTranslation: async props => props,
}),

@@ -57,1 +59,20 @@ ])

to run the component in a dev server
## Isolated development
To develop this plugin as a separate repository (outside of your studio environment) and test it locally in a studio during development, you'll need:
- a Sanity studio with a custom desk structure that uses `TranslationsTab` (see implementation of [Studio Plugin for Sanity & Smartling](https://github.com/sanity-io/sanity-plugin-studio-smartling))
- a [symlink](https://medium.com/dailyjs/how-to-use-npm-link-7375b6219557) configured to run `TranslationsTab` from this local development version.
Assuming you already have a studio, the following will get you up and running with a forked repo and symlink:
1. Fork or clone this repo locally in its own directory (not as part of a studio)
2. Run `npm install` to install the plugin's dependencies.
3. Run `npm link` from this plugin's directory (eg, `~/code/sanity-translations-tab`) to create a global symlink to this local instance of the `sanity-translations-tab` dependency.
4. Run `npm run build` to compile an initial version.
5. Run `npm link sanity-translations-tab` inside the directory of the studio you want to use the plugin in (eg, `~/code/my-studio`). This will tell the studio application to use the global symlink to this instance of the dependency.
6. Add `import { TranslationsTab } from 'sanity-translations-tab'` to `deskStructure.js` in the studio. If previously importing `TranslationsTab` from an adapter library such as `sanity-plugin-smartling-studio`, remove that import statement.
7. Run `sanity start` to run the studio locally.
8. Run `npm run watch` from the `sanity-translations-tab` directory to start a watch task.
9. Start making changes to the translations tab, as needed, and they should automatically compile in the studio in the browser.

@@ -25,2 +25,7 @@ export type TranslationTask = {

export type WorkflowIdentifiers = {
workflowUid: string
workflowName: string
}
export interface Adapter {

@@ -36,3 +41,4 @@ getLocales: (secrets: Secrets | null) => Promise<TranslationLocale[]>

localeIds: string[],
secrets: Secrets | null
secrets: Secrets | null,
workflowUid?: string
) => Promise<TranslationTask>

@@ -39,0 +45,0 @@ getTranslation: (

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc