treebank-react
Version:
Treebank display engine for React
2 lines • 33.2 kB
JavaScript
!function(e,t){if("object"===typeof exports&&"object"===typeof module)module.exports=t(require("react"),require("d3"),require("dagre-d3"),require("xml2js"));else if("function"===typeof define&&define.amd)define(["react","d3","dagre-d3","xml2js"],t);else{var n="object"===typeof exports?t(require("react"),require("d3"),require("dagre-d3"),require("xml2js")):t(e.react,e.d3,e["dagre-d3"],e.xml2js);for(var r in n)("object"===typeof exports?exports:e)[r]=n[r]}}(this,(function(e,t,n,r){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/treebank-react/",n(n.s=14)}([function(t,n){t.exports=e},function(e,t,n){e.exports=n(15)()},function(e,t,n){e.exports={xml:"Xml_xml__rDBB1",word:"Xml_word__1KQsw",active:"Xml_active__2pHyq",highlight:"Xml_highlight__2CExk",bracket:"Xml_bracket__2jMk-",element:"Xml_element__2UAgq",attribute:"Xml_attribute__1yJWB",attributeText:"Xml_attributeText__s0Hws"}},function(e,n){e.exports=t},function(e,t,n){e.exports={graph:"Graph_graph__61aOY",node:"Graph_node__206k1",active:"Graph_active__BgUAv",highlight:"Graph_highlight__34IXY",elliptic:"Graph_elliptic__8kvLT"}},function(e,t,n){e.exports={information:"PartOfSpeech_information__2wKMB",dl:"PartOfSpeech_dl__34YRv",container:"PartOfSpeech_container__1UAbJ",dt:"PartOfSpeech_dt__brvjJ",dd:"PartOfSpeech_dd__c2Bm3"}},function(e,t,n){e.exports={information:"AdditionalFields_information__1DKph",dl:"AdditionalFields_dl__2NgAs",container:"AdditionalFields_container__1PvOz",dt:"AdditionalFields_dt__vWdSD",dd:"AdditionalFields_dd__iXWjo"}},function(e,t,n){e.exports={annotators:"Annotators_annotators__3tUlp",dl:"Annotators_dl__3w5YQ",container:"Annotators_container__cZH47",dt:"Annotators_dt__48WM3",dd:"Annotators_dd__3ntRr"}},function(e,t,n){e.exports={text:"Text_text__3vMKP",word:"Text_word__u68jU",active:"Text_active__8HwsG",highlight:"Text_highlight__2Uvua",elliptic:"Text_elliptic__1mO5p"}},function(e,t,n){e.exports={button:"Collapse_button__2f77d",right:"Collapse_right__1XDGM"}},function(e,t){e.exports=n},function(e,t){e.exports=r},function(e,t){var n=function(e){function t(){this.fetch=!1,this.DOMException=e.DOMException}return t.prototype=e,new t}("undefined"!==typeof self?self:this);!function(e){!function(t){var n="URLSearchParams"in e,r="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in e,a="ArrayBuffer"in e;if(a)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&s.indexOf(Object.prototype.toString.call(e))>-1};function l(e){if("string"!==typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function u(e){return"string"!==typeof e&&(e=String(e)),e}function h(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r&&(t[Symbol.iterator]=function(){return t}),t}function d(e){this.map={},e instanceof d?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function f(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function p(e){return new Promise((function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}}))}function g(e){var t=new FileReader,n=p(t);return t.readAsArrayBuffer(e),n}function v(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"===typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:n&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&o&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=v(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||c(e))?this._bodyArrayBuffer=v(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"===typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):n&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var e=f(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(g)}),this.text=function(){var e=f(this);if(e)return e;if(this._bodyBlob)return function(e){var t=new FileReader,n=p(t);return t.readAsText(e),n}(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),r=0;r<t.length;r++)n[r]=String.fromCharCode(t[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(e,t){e=l(e),t=u(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},d.prototype.delete=function(e){delete this.map[l(e)]},d.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},d.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},d.prototype.set=function(e,t){this.map[l(e)]=u(t)},d.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},d.prototype.keys=function(){var e=[];return this.forEach((function(t,n){e.push(n)})),h(e)},d.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),h(e)},d.prototype.entries=function(){var e=[];return this.forEach((function(t,n){e.push([n,t])})),h(e)},r&&(d.prototype[Symbol.iterator]=d.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var n=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new d(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new d(t.headers)),this.method=function(e){var t=e.toUpperCase();return y.indexOf(t)>-1?t:e}(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function _(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var n=e.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}})),t}function E(e){var t=new d;return e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var n=e.split(":"),r=n.shift().trim();if(r){var o=n.join(":").trim();t.append(r,o)}})),t}function w(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new d(t.headers),this.url=t.url||"",this._initBody(e)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},m.call(b.prototype),m.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},w.error=function(){var e=new w(null,{status:0,statusText:""});return e.type="error",e};var k=[301,302,303,307,308];w.redirect=function(e,t){if(-1===k.indexOf(t))throw new RangeError("Invalid status code");return new w(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(j){t.DOMException=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function x(e,n){return new Promise((function(r,i){var a=new b(e,n);if(a.signal&&a.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var s=new XMLHttpRequest;function c(){s.abort()}s.onload=function(){var e={status:s.status,statusText:s.statusText,headers:E(s.getAllResponseHeaders()||"")};e.url="responseURL"in s?s.responseURL:e.headers.get("X-Request-URL");var t="response"in s?s.response:s.responseText;r(new w(t,e))},s.onerror=function(){i(new TypeError("Network request failed"))},s.ontimeout=function(){i(new TypeError("Network request failed"))},s.onabort=function(){i(new t.DOMException("Aborted","AbortError"))},s.open(a.method,a.url,!0),"include"===a.credentials?s.withCredentials=!0:"omit"===a.credentials&&(s.withCredentials=!1),"responseType"in s&&o&&(s.responseType="blob"),a.headers.forEach((function(e,t){s.setRequestHeader(t,e)})),a.signal&&(a.signal.addEventListener("abort",c),s.onreadystatechange=function(){4===s.readyState&&a.signal.removeEventListener("abort",c)}),s.send("undefined"===typeof a._bodyInit?null:a._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=d,e.Request=b,e.Response=w),t.Headers=d,t.Request=b,t.Response=w,t.fetch=x}({})}(n),delete n.fetch.polyfill,(t=n.fetch).default=n.fetch,t.fetch=n.fetch,t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response,e.exports=t},function(e){e.exports=JSON.parse('{"plugins":{"morph":{"noRetrieval":"online","retrievers":{"BspMorphRetriever":{"resource":"newMorphologyServiceLat"}},"postagSchema":["pos","pers","num","tense","mood","voice","gend","case","degree"],"styledThrough":"pos","attributes":{"pos":{"long":"Part of Speech","short":"pos","values":{"noun":{"long":"noun","short":"noun","postag":"n","style":{"color":"rgb(43, 114, 124)"}},"adj":{"long":"adjective","short":"adj","postag":"a","style":{"color":"blue"}},"adv":{"long":"adverb","short":"adv","postag":"d","style":{"color":"darkorange"}},"conj":{"long":"conjunction","short":"conj","postag":"c","style":{"color":"deeppink"}},"prep":{"long":"preposition","short":"prep","postag":"r","style":{"color":"green"}},"pron":{"long":"pronoun","short":"pron","postag":"p","style":{"color":"purple"}},"excl":{"long":"exclamation","short":"excl","postag":"e","style":{"color":"gold"}},"verb":{"long":"verb","short":"verb","postag":"v","style":{"color":"red"}},"nrl":{"long":"numeral","short":"nrl","postag":"m","style":{"color":"lightgreen"}},"punct":{"long":"punctuation","short":"punct","postag":"u"},"irreg":{"long":"irregular","short":"irreg","postag":"x","style":{"color":"gray"}}}},"pers":{"long":"Person","short":"pers","values":{"1st":{"long":"first person","short":"1st","postag":"1"},"2nd":{"long":"second person","short":"2nd","postag":"2"},"3rd":{"long":"third person","short":"3rd","postag":"3"}},"rules":[{"if":{"pos":"verb","mood":"*"},"unless":{"mood":["part","inf"]}}]},"num":{"long":"Number","short":"num","rules":[{"if":{"pos":["noun","adj","nrl","pron"]}},{"if":{"pos":"verb","mood":"*"},"unless":{"mood":"inf"}}],"values":{"sg":{"long":"singular","short":"sg","postag":"s"},"pl":{"long":"plural","short":"pl","postag":"p"}}},"tense":{"long":"Tense","short":"tense","rules":[{"if":{"pos":"verb"}}],"values":{"pr":{"long":"present","short":"pr","postag":"p"},"imp":{"long":"imperfect","short":"imp","postag":"i"},"perf":{"long":"perfect","short":"perf","postag":"r"},"pqpf":{"long":"plusquamperfect","short":"pqpf","postag":"l"},"fex":{"long":"future perfect","short":"fex","postag":"t"},"fut":{"long":"future","short":"fut","postag":"f"}}},"mood":{"long":"Mood","short":"mood","rules":[{"if":{"pos":"verb"}}],"values":{"ind":{"long":"indicative","short":"ind","postag":"i"},"sub":{"long":"subjunctive","short":"sub","postag":"s"},"inf":{"long":"infinitive","short":"inf","postag":"n"},"imp":{"long":"imperative","short":"imp","postag":"m"},"gerund":{"long":"gerund","short":"gerund","postag":"d"},"gerundive":{"long":"gerundive","short":"gerundive","postag":"g"},"part":{"long":"participle","short":"part","postag":"p"},"sup":{"long":"supine","short":"sup","postag":"u"}}},"voice":{"long":"Voice","short":"voice","rules":[{"if":{"pos":"verb"}}],"values":{"act":{"long":"active","short":"act","postag":"a"},"pass":{"long":"passive","short":"pass","postag":"p"},"dep":{"long":"deponens","short":"dep","postag":"d"}}},"gend":{"long":"gender","short":"gend","rules":[{"if":{"pos":["noun","adj","pron","nrl"]}},{"if":{"pos":"verb","mood":"part"}},{"if":{"pos":"verb","mood":"gerundive"}}],"values":{"masc":{"long":"masculine","short":"masc","postag":"m"},"fem":{"long":"feminine","short":"fem","postag":"f"},"neut":{"long":"neuter","short":"neut","postag":"n"}}},"case":{"long":"Casus","short":"case","rules":[{"if":{"pos":["noun","adj","pron","nrl"]}},{"if":{"pos":"verb","mood":"part"}},{"if":{"pos":"verb","mood":"gerund"}},{"if":{"pos":"verb","mood":"gerundive"}}],"values":{"nom":{"long":"nominative","short":"nom","postag":"n"},"gen":{"long":"genitive","short":"gen","postag":"g"},"dat":{"long":"dative","short":"dat","postag":"d"},"acc":{"long":"accusative","short":"acc","postag":"a"},"voc":{"long":"vocative","short":"voc","postag":"v"},"abl":{"long":"ablative","short":"abl","postag":"b"},"loc":{"long":"locative","short":"loc","postag":"l"}}},"degree":{"long":"Degree","short":"degree","rules":[{"if":{"pos":"adj"}},{"if":{"pos":"adv"}},{"if":{"pos":"verb","mood":"part"}}],"values":{"pos":{"long":"positive","short":"pos","postag":"p"},"comp":{"long":"comparative","short":"comp","postag":"c"},"sup":{"long":"superlative","short":"sup","postag":"s"}}}},"mappings":{"BspMorphRetriever":{"attributes":{"pofs":"pos","comp":"degree"},"values":{"pos":{"verb\\nparticiple":"verb","verb participle":"verb"},"tense":{"pluperfect":"plusquamperfect"}}}}}}}')},function(e,t,n){e.exports=n(17)},function(e,t,n){"use strict";var r=n(16);function o(){}function i(){}i.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,i,a){if(a!==r){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:o};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),i=Object(r.createContext)();i.displayName="SentenceContext";var a=i;function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e,t){if(e){if("string"===typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"!==typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(c){o=!0,i=c}finally{try{r||null==s.return||s.return()}finally{if(o)throw i}}return n}}(e,t)||c(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var u=n(1),h=Object(u.shape)({$:Object(u.shape)({id:u.string.isRequired,form:u.string,lemma:u.string,postag:u.string,relation:u.string,head:u.string,sg:u.string,comment:u.string,artificial:u.string,gloss:u.string,alternateGloss:u.string,semanticRole:u.string,include:u.string,multiword:u.string,notes:u.string})}),d=(Object(u.shape)({$:Object(u.shape)({id:u.string.isRequired,document_id:u.string,subdoc:u.string,span:u.string}),word:Object(u.arrayOf)(h)}),n(6)),f=n.n(d),p=function(e){var t=l(e,2),n=t[0],r=t[1];return o.a.createElement("div",{key:n,className:f.a.container},o.a.createElement("dt",{className:f.a.dt},n),o.a.createElement("dd",{className:f.a.dd},r))},g=function(e){var t=e.active,n=e.fields;if(t){var r=function(e,t){var n=e.$;return t.filter((function(e){return Object.prototype.hasOwnProperty.call(n,e)})).map((function(e){return[e,n[e]]}))}(t,n);if(0!==r.length)return o.a.createElement("div",{className:f.a.information},o.a.createElement("dl",{className:f.a.dl},r.map(p)))}return o.a.createElement("div",null)};g.defaultProps={active:null,fields:["sg","comment","artificial","gloss","alternateGloss","semanticRole","include","multiword","notes"]};var v=g,m=function(){return o.a.createElement(a.Consumer,null,(function(e){var t=e.active;return o.a.createElement(v,{active:t})}))},y=Object(r.createContext)();y.displayName="TreebankContext";var b=y,_=n(7),E=n.n(_),w=["short","name","address","uri"],k=function(e){return function(e){var t=e.treebank.annotator;return t?t.map((function(e){return w.map((function(t){return{title:t,value:e[t]?e[t][0]:""}})).filter((function(e){return""!==e.value}))})):[]}(e.json).map((function(e,t){return o.a.createElement("div",{key:"annotator-".concat(t),className:E.a.annotators},o.a.createElement("dl",{className:E.a.dl},e.map((function(e,n){return function(e,t,n){var r=e.title,i=e.value;return o.a.createElement("div",{key:"annotator-field-".concat(t,"-").concat(n),className:E.a.container},o.a.createElement("dt",{className:E.a.dt},r),o.a.createElement("dd",{className:E.a.dd},i))}(e,t,n)}))))}))},x=function(){return o.a.createElement(b.Consumer,null,(function(e){var t=e.json;return o.a.createElement(k,{json:t})}))},j=n(9),A=n.n(j),O=function(e){var t=e.title,n=e.children,i=e.collapsed,a=l(Object(r.useState)(i),2),s=a[0],c=a[1];return Object(r.useEffect)((function(){c(i)}),[i]),o.a.createElement("div",null,o.a.createElement("button",{type:"button",className:A.a.button,onClick:function(){return c(!s)}},o.a.createElement("div",null,t),o.a.createElement("div",{className:A.a.right},s?"+":"-")),s?null:n)};O.defaultProps={collapsed:!0};var S=O,T=n(4),P=n.n(T);function N(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function C(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function B(e,t,n){return t&&C(e.prototype,t),n&&C(e,n),e}var R=n(10),I=n.n(R),U=n(3),D={rankdir:"TB",nodesep:40,edgesep:10,ranksep:30},H=function(){function e(t,n,r,o,i,a,s){N(this,e),this.selectedSvg=t,this.selectedG=n,this.nodes=r,this.links=o,this.onClick=i,this.prevNodes=a,this.prevLinks=s,this.state="initial",this.active=null,this.previousActive=null,this.toHighlight=new Set,this.unHighlight=new Set,this.draw=this.draw.bind(this),this.checkGraphSize=this.checkGraphSize.bind(this),this.redraw=this.redraw.bind(this),this.checkLinks=this.checkLinks.bind(this),this.checkNodes=this.checkNodes.bind(this),this.changeMeta=this.changeMeta.bind(this)}return B(e,[{key:"draw",value:function(){"complete"!==this.state&&({initial:this.checkGraphSize,sameSize:this.checkLinks,linksIdentical:this.checkNodes,metaChanged:this.changeMeta,redraw:this.redraw}[this.state](),this.draw())}},{key:"checkGraphSize",value:function(){this.prevNodes&&this.prevLinks&&this.nodes.length===this.prevNodes.length&&this.links.length===this.prevLinks.length?this.state="sameSize":this.state="redraw"}},{key:"checkLinks",value:function(){var e;for(e=0;e<this.links.length;e+=1){var t=this.links[e],n=this.prevLinks[e];if(t.head!==n.head||t.source!==n.source||t.target!==n.target||t.label!==n.label)return void(this.state="redraw")}this.state="linksIdentical"}},{key:"checkNodes",value:function(){var e;for(this.toHighlight.clear(),this.unHighlight.clear(),e=0;e<this.nodes.length;e+=1){var t=this.nodes[e],n=this.prevNodes[e];if(t.id!==n.id||t.label!==n.label||t.postag!==n.postag)return void(this.state="redraw");n.config.isActive&&(this.previousActive=n),t.config.isActive&&(this.active=t),t.config.isHighlighted&&!n.config.isHighlighted&&this.toHighlight.add(t.id),!t.config.isHighlighted&&n.config.isHighlighted&&this.unHighlight.add(t.id)}this.active&&!this.previousActive||!this.active&&this.previousActive||this.active&&this.previousActive&&this.active.id!==this.previousActive.id||this.toHighlight.size>0||this.unHighlight.size>0?this.state="metaChanged":this.state="complete"}},{key:"changeMeta",value:function(){var e=this.active,t=this.previousActive,n=this.toHighlight,r=this.unHighlight,o=this.onClick;this.selectedG.selectAll("g.node").each((function(){e&&this.__data__===e.id&&(this.classList.add(P.a.active),U.select(this).on("mousedown",(function(e){var t=e.target;o(t.__data__)}))),t&&this.__data__===t.id&&(this.classList.remove(P.a.active),U.select(this).on("mousedown",(function(e){var t=e.target;o(t.__data__)}))),n.has(this.__data__)&&this.classList.add(P.a.highlight),r.has(this.__data__)&&this.classList.remove(P.a.highlight)})),this.state="complete"}},{key:"redraw",value:function(){var e=this,t=(new I.a.graphlib.Graph).setGraph(D);this.nodes.forEach((function(e){var n=e.id,r=e.label,o=e.config,i=o.labelType,a=o.labelStyle,s=o.class;t.setNode(n,{label:r,labelType:i,labelStyle:a,class:s,paddingLeft:2,paddingRight:2,paddingTop:2,paddingBottom:2})})),this.links.forEach((function(e){var n=e.source,r=e.target,o=e.label,i=e.config.arrowheadStyle;t.setEdge(n,r,{label:o,arrowheadStyle:i,curve:U.curveBasis})}));var n=new I.a.render,r=U.zoom().on("zoom",(function(t){e.selectedG.attr("transform",t.transform)})).scaleExtent([.3,2.5]);this.selectedSvg.call(r),this.selectedG.attr("transform",U.zoomIdentity),n(this.selectedG,t),this.setInitialPosition(r),this.selectedSvg.selectAll("g.node").on("mousedown",(function(t){var n=t.target;e.onClick(n.__data__)})),this.state="complete"}},{key:"setInitialPosition",value:function(e){var t=this.selectedSvg.node(),n=t.getBBox(),r=t.clientWidth;if(n.width>r-30){var o=U.zoomIdentity.translate(15,15),i=(r-30)/n.width;this.selectedSvg.call(e.transform,o.scale(i))}else{var a=U.zoomIdentity.translate((r-n.width)/2,15);this.selectedSvg.call(e.transform,a)}}}]),e}(),L=function(e){var t=e.nodes,n=e.links,i=e.onClick,a=Object(r.useRef)(null),s=Object(r.useRef)(null),c=Object(r.useRef)(null),l=Object(r.useRef)(null);return Object(r.useEffect)((function(){!function(e,t,n,r,o,i,a){var s=U.select(e.current),c=U.select(t.current);new H(s,c,n,r,o,i,a).draw()}(a,s,t,n,i,c.current,l.current),c.current=t,l.current=n}),[t,n]),o.a.createElement("svg",{ref:a,className:P.a.graph},o.a.createElement("g",{ref:s}))},M=n(11),q=n(12),F=n.n(q),G=n(13),$=function(e){var t={};return function(n){return t.hasOwnProperty(n)||(t[n]=e(n)),t[n]}},z=function(){function e(t){N(this,e),this.config=t,this.getColor=$(this.getColor.bind(this)),this.deconstructPostag=$(this.deconstructPostag.bind(this))}return B(e,[{key:"deconstructPostag",value:function(e){var t=[];if(e&&this.config.plugins&&this.config.plugins.morph){var n=this.config.plugins.morph,r=n.postagSchema,o=n.attributes;r.forEach((function(n,r){var i=o[n],a=Object.entries(i.values).find((function(t){return l(t,2)[1].postag===e[r]}));a&&t.push([{long:i.long,short:i.short,key:n},{long:a[1].long,short:a[1].short,key:a[0]}])}))}return t}},{key:"getColor",value:function(e){if(e&&this.config.plugins&&this.config.plugins.morph){var t=this.config.plugins.morph,n=t.postagSchema,r=t.styledThrough,o=t.attributes,i=n.findIndex((function(e){return e===r})),a=o[r];if(a&&i>-1){var s=Object.values(a.values),c=s.findIndex((function(t){return t.postag===e[i]}));if(c>-1){var l=s[c];if(l.style&&l.style.color)return l.style.color}}}return null}}]),e}(),X=function(e){var t=e.sentence,n=e.active,r=e.toggleActive,i=function(e,t,n,r,o){var i={nodes:[{id:"0",label:"[ROOT]",config:{labelType:"html",class:o.node}}],links:[]};return e.word.forEach((function(e){var a=function(e,t,n,r,o){var i=e.$,a=i.id,s=i.form,c=i.postag,l=i.artificial,u=r.getColor(c),h=t&&t.$.id===a,d=!h&&n.has(a),f=[o.node];return h&&f.push(o.active),d&&f.push(o.highlight),"elliptic"===l&&f.push(o.elliptic),{artificial:l,id:a,postag:c,label:s,config:{labelStyle:"color: ".concat(u),labelType:"html",class:f.join(" "),isActive:h,isHighlighted:d}}}(e,t,n,r,o),s=function(e){var t=e.$,n=t.id,r=t.head,o=t.relation;return n&&r?{label:o,source:r,target:n,config:{arrowheadStyle:"display: none"}}:null}(e);i.nodes.push(a),s&&i.links.push(s)})),i}(t,n,e.highlight,e.config,P.a),a=i.nodes,s=i.links;return o.a.createElement(L,{nodes:a,links:s,onClick:r})};X.defaultProps={active:null,highlight:new Set};var W=X,K=function(){return o.a.createElement(a.Consumer,null,(function(e){var t=e.sentence,n=e.active,r=e.toggleActive,i=e.highlight,a=e.config;return o.a.createElement(W,{sentence:t,active:n,toggleActive:r,highlight:i,config:a})}))},J=n(5),Y=n.n(J),V=function(e){var t=l(e,2),n=t[0],r=n.long,i=n.short,a=n.key,s=t[1];return o.a.createElement("div",{key:a,className:Y.a.container},o.a.createElement("dt",{className:Y.a.dt},r||i||a),function(e){var t=e.long,n=e.short,r=e.key;return o.a.createElement("dd",{className:Y.a.dd},t||n||r)}(s))},Q=function(e){var t=e.active,n=e.config;if(t){var r=t.$,i=r.postag,a=r.lemma;return o.a.createElement("div",{className:Y.a.information},o.a.createElement("dl",{className:Y.a.dl},function(e){return o.a.createElement("div",{className:Y.a.container},o.a.createElement("dt",{className:Y.a.dt},"Lemma"),o.a.createElement("dd",{className:Y.a.dd},e))}(a),n.deconstructPostag(i).map(V)))}return o.a.createElement("div",null)};Q.defaultProps={active:null};var Z=Q,ee=function(){return o.a.createElement(a.Consumer,null,(function(e){var t=e.active,n=e.config;return o.a.createElement(Z,{active:t,config:n})}))},te=function(e,t){return t.word.find((function(t){return t.$.id===e}))},ne=function(e){var t,n,i=e.id,s=e.callback,c=e.active,u=e.setActive,h=e.highlight,d=e.json,f=e.config,p=e.children;if(null!==c||null!==u)t=c,n=u||function(){};else{var g=l(Object(r.useState)(null),2);t=g[0],n=g[1]}var v=new Set(h),m=function(e,t){return e.treebank.sentence.find((function(e){var n=e.$;return n.id&&n.id===t}))}(d,i),y=te(t,m);return Object(r.useEffect)((function(){s&&s({treebank:d,sentence:m,configuration:f})}),[i,d]),Object(r.useEffect)((function(){n(c)}),[i,d]),o.a.createElement(a.Provider,{value:{sentence:m,config:f,active:y,toggleActive:function(e){var r=te(e,m);n(r&&y&&t===e?null:e)},highlight:v}},p)},re=function(e){var t=e.id,n=e.callback,r=e.active,i=e.setActive,a=e.highlight,s=e.children;return o.a.createElement(b.Consumer,null,(function(e){var c=e.json,l=e.config;return o.a.createElement(ne,{id:t,callback:n,active:r,setActive:i,highlight:a,json:c,config:l},s)}))};re.defaultProps={callback:null,active:null,setActive:null,highlight:[],children:null};var oe=re;function ie(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!==typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var ae=n(8),se=n.n(ae),ce=function(e){var t=e.$,n=t.id;return function(e){return e.padStart(4,"0")}(t.insertion_id||n)},le=function(e,t){var n=ce(e),r=ce(t);return n<r?-1:r<n?1:0},ue=function(e){var t=e.sentence,n=e.active,i=e.toggleActive,a=e.highlight,s=e.config,c=ie(t.word).sort(le).map((function(e){return function(e,t,n,i,a){var s=e.$,c=s.id,l=s.form,u=s.postag,h=s.artificial,d=t.getColor(u),f=[se.a.word];n&&n.$.id===c?f.push(se.a.active):i.has(c)&&f.push(se.a.highlight),"elliptic"===h&&f.push(se.a.elliptic);var p=function(){a(c)};return o.a.createElement(r.Fragment,{key:c},o.a.createElement("span",{role:"button",tabIndex:"0",onClick:p,onKeyDown:function(e){"Enter"===e.key&&p()},className:f.join(" "),style:{color:d}},l)," ")}(e,s,n,a,i)}));return o.a.createElement("div",{className:se.a.text},o.a.createElement("p",null,c))};ue.defaultProps={active:null,toggleActive:function(){},highlight:new Set};var he=ue,de=function(){return o.a.createElement(a.Consumer,null,(function(e){var t=e.sentence,n=e.active,r=e.toggleActive,i=e.highlight,a=e.config;return o.a.createElement(he,{sentence:t,active:n,highlight:i,toggleActive:r,config:a})}))},fe=function(e,t,n){return function(e,t,n,r){var o="aldt"===e?"aldt2".concat(t):e;F()("".concat(n).concat(encodeURIComponent(o),".json")).then((function(e){if(!e.ok)throw new Error("Network response was not ok");return e.json()})).then((function(e){return r(new z(e))})).catch((function(){return r(new z(G))}))}(e.treebank.$.format,e.treebank.$["xml:lang"],t,n)},pe=function(e){var t=e.treebank,n=e.configUrl,i=e.callback,a=e.children,s=l(Object(r.useState)({}),2),c=s[0],u=s[1],h=c.json,d=c.config,f=c.loaded;return Object(r.useEffect)((function(){var e=function(e){var t;return Object(M.parseString)(e,(function(e,n){t=n})),t}(t);fe(e,n,(function(t){u({json:e,config:t,loaded:!0})}))}),[t]),Object(r.useEffect)((function(){i&&f&&i({treebank:h,configuration:d})}),[h]),f?o.a.createElement(b.Provider,{value:{json:h,config:d}},a):o.a.createElement("div",null)};pe.defaultProps={configUrl:"https://arethusa-configs.perseids.org/",callback:null,children:null};var ge=pe,ve=n(2),me=n.n(ve),ye=function(e){return Object.entries(e).map((function(e){var t=l(e,2),n=t[0],i=t[1];return o.a.createElement(r.Fragment,{key:n}," ",o.a.createElement("span",{className:me.a.attribute},n,"="),o.a.createElement("span",{className:me.a.attributeText},'"',i,'"'))}))},be=function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"";return o.a.createElement(r.Fragment,{key:n},o.a.createElement("span",{className:me.a.bracket},a,"<"),o.a.createElement("span",{className:me.a.element},e),ye(t),i?" /":"",o.a.createElement("span",{className:me.a.bracket},">"),o.a.createElement("br",null))},_e=function(e){var t,n,i=e.sentence,a=e.active,s=e.toggleActive,c=e.highlight;return o.a.createElement("div",{className:me.a.xml},be("sentence",i.$,"sentence"),i.word.map((function(e){return function(e,t,n,r){var i=e.$.id,a=[me.a.word],s=function(){n(i)};return t&&t.$.id===i?a.push(me.a.active):r.has(i)&&a.push(me.a.highlight),o.a.createElement("div",{key:i,role:"button",tabIndex:"0",className:a.join(" "),onClick:s,onKeyDown:function(e){"Enter"===e.key&&s()}},be("word",e.$,i,!0,o.a.createElement(o.a.Fragment,null,"\xa0\xa0\xa0\xa0")))}(e,a,s,c)})),(t="sentence",n="sentence-close",o.a.createElement(r.Fragment,{key:n},o.a.createElement("span",{className:me.a.bracket},"<"),o.a.createElement("span",{className:me.a.element},"/",t),o.a.createElement("span",{className:me.a.bracket},">"))))};_e.defaultProps={active:null,toggleActive:function(){},highlight:new Set};var Ee=_e,we=function(){return o.a.createElement(a.Consumer,null,(function(e){var t=e.sentence,n=e.active,r=e.toggleActive,i=e.highlight;return o.a.createElement(Ee,{sentence:t,active:n,toggleActive:r,highlight:i})}))};n.d(t,"AdditionalFields",(function(){return m})),n.d(t,"Annotators",(function(){return x})),n.d(t,"Collapse",(function(){return S})),n.d(t,"Graph",(function(){return K})),n.d(t,"PartOfSpeech",(function(){return ee})),n.d(t,"Sentence",(function(){return oe})),n.d(t,"Text",(function(){return de})),n.d(t,"Treebank",(function(){return ge})),n.d(t,"Xml",(function(){return we}))}])}));
//# sourceMappingURL=index.js.map