wikimedia/mediawiki-extensions-Wikibase

View on GitHub
client/data-bridge/dist/data-bridge.init.js

Summary

Maintainability
A
0 mins
Test Coverage
/*!/*@nomin*/(()=>{var e,t={1547:(e,t,i)=>{"use strict";i.r(t),i(8674),i(7727);var r,n=i(8534),o=i(5082),a=i(2482);i(4603),i(8450),i(4916),i(2479),function(e){e.SINGLE_BEST_VALUE="single-best-value"}(r||(r={}));var s,c,l=r;class d{constructor(e){(0,a.Z)(this,"hrefRegExp",void 0),(0,a.Z)(this,"ENTITY_ID_REGEX_INDEX",2),(0,a.Z)(this,"PROPERTY_ID_REGEX_INDEX",3),(0,a.Z)(this,"ENTITY_TITLE_REGEX_INDEX",1),this.hrefRegExp=new RegExp(e)}extractDataFromLink(e){const t=e.href.match(this.hrefRegExp);return t&&t[this.ENTITY_ID_REGEX_INDEX]&&t[this.PROPERTY_ID_REGEX_INDEX]&&t[this.ENTITY_TITLE_REGEX_INDEX]?{entityId:t[this.ENTITY_ID_REGEX_INDEX],propertyId:t[this.PROPERTY_ID_REGEX_INDEX],entityTitle:t[this.ENTITY_TITLE_REGEX_INDEX]}:null}validateEditFlow(e){return e&&Object.values(l).includes(e)?e:null}getEditFlowFromParent(e){return 1!==e.querySelectorAll("a").length?null:this.validateEditFlow(e.dataset.bridgeEditFlow)}extractDataFromElement(e){const t=this.getEditFlowFromParent(e.parentElement);if(!t)return null;const i=this.extractDataFromLink(e);return null===i?null:(0,o.Z)((0,o.Z)({},i),{},{link:e,editFlow:t})}selectElementsToOverload(){return Array.from(document.querySelectorAll("[data-bridge-edit-flow] > a")).map((e=>this.extractDataFromElement(e))).filter((e=>null!==e))}}!function(e){e.saved="saved",e.cancel="cancel",e.reload="reload"}(s||(s={})),function(e){e.relaunch="relaunch",e.redirect="redirect"}(c||(c={})),(0,o.Z)((0,o.Z)({},s),c);class u{constructor(e,t,i,r,n){(0,a.Z)(this,"mwWindow",void 0),(0,a.Z)(this,"vue",void 0),(0,a.Z)(this,"app",void 0),(0,a.Z)(this,"dataBridgeConfig",void 0),(0,a.Z)(this,"eventTracker",void 0),this.mwWindow=e,this.vue=t,this.app=i,this.dataBridgeConfig=r,this.eventTracker=n}dispatch(e){const t=function(e,t,i){const r=function(e){r.super.call(this,e)};e.inheritClass(r,e.ui.Dialog),r.static.name="data-bridge",r.static.escapable=!1,r.prototype.initialize=function(){r.super.prototype.initialize.call(this),this.content=new e.ui.PanelLayout({padded:!1,expanded:!1}),this.content.$element.attr("id",i),this.$body.append(this.content.$element)},r.prototype.getBodyHeight=function(){return 448};const n=new r({classes:["wb-db-dialog"],size:"medium"}),o=new e.ui.WindowManager;return t(document.body).append(o.$element),o.addWindows([n]),o.openWindow(n),n}(this.mwWindow.OO,this.mwWindow.$,u.APP_DOM_CONTAINER_ID);!function(e,t,i){e.on(s.saved,(()=>{i.location.reload()})),e.on(s.cancel,(()=>{t.clearWindows().catch((()=>{}))})),e.on(s.reload,(()=>{i.location.reload()})),t.on("closing",((e,i)=>{i.then((()=>{t.destroy()}),(e=>{t.destroy()}))}))}(this.app.launch(this.vue.createMwApp,{containerSelector:"#"+u.APP_DOM_CONTAINER_ID},{pageTitle:this.mwWindow.mw.config.get("wgPageName"),entityId:e.entityId,propertyId:e.propertyId,entityTitle:e.entityTitle,editFlow:e.editFlow,client:{usePublish:this.dataBridgeConfig.usePublish,issueReportingLink:this.dataBridgeConfig.issueReportingLink},originalHref:e.link.href,pageUrl:this.mwWindow.location.href,userName:this.mwWindow.mw.config.get("wgUserName")},this.app.createServices(this.mwWindow,this.dataBridgeConfig.editTags,this.eventTracker)),t.getManager(),this.mwWindow)}}(0,a.Z)(u,"APP_DOM_CONTAINER_ID","data-bridge-container");class h{constructor(e){(0,a.Z)(this,"tracker",void 0),this.tracker=e}increment(e){this.tracker("counter."+e,1)}recordTiming(e,t){this.tracker("timing."+e,t)}}class p{constructor(e,t,i){(0,a.Z)(this,"tracker",void 0),(0,a.Z)(this,"performance",void 0),(0,a.Z)(this,"visibilityApi",void 0),this.tracker=e,this.performance=t,this.visibilityApi=i}startClickDelayTracker(){const e=this.performance.now();return()=>{const t=this.performance.now()-e;this.tracker.recordTiming("clickDelay",t)}}recordTimeToLinkListenersAttached(){if(this.isTabInBackground())return;const e=this.performance.now();if(!this.performance.getEntriesByName||0===this.performance.getEntriesByName("mwStartup").length)return;const t=this.performance.getEntriesByName("mwStartup")[0];this.tracker.recordTiming("timeToLinkListenersAttached",e-t.startTime)}isTabInBackground(){return this.visibilityApi.hidden||this.visibilityApi.msHidden||this.visibilityApi.webkitHidden}}class g{constructor(e,t){(0,a.Z)(this,"tracker",void 0),(0,a.Z)(this,"trackingTopicPrefix",void 0),this.tracker=e,this.trackingTopicPrefix=t}increment(e){this.tracker.increment(`${this.trackingTopicPrefix}.${e}`)}recordTiming(e,t){this.tracker.recordTiming(`${this.trackingTopicPrefix}.${e}`,t)}}const f="wikibase.client.data-bridge.app";var m=(0,n.Z)((function*(){const e=window,t=e.mw.config.get("wbDataBridgeConfig");if(null===t.hrefRegExp)return void e.mw.log.warn("data bridge config incomplete: dataBridgeHrefRegExp missing");const i=new d(t.hrefRegExp).selectElementsToOverload();if(i.length>0){const r=new g(new h(e.mw.track),"MediaWiki.wikibase.client.databridge"),o=e.mw.loader.using([f,"vue","mw.config.values.wbRepo","mediawiki.ForeignApi","mediawiki.api","jquery.uls.data","mediawiki.language"]).then(function(){var i=(0,n.Z)((function*(i){const n=yield i(f),o=yield i("vue");return new u(e,o,n,t,r)}));return function(e){return i.apply(this,arguments)}}()),a=new p(r,window.performance,window.document);i.forEach((e=>{let t=!1;e.link.setAttribute("aria-haspopup","dialog"),e.link.addEventListener("click",function(){var i=(0,n.Z)((function*(i){if(i.altKey||i.ctrlKey||i.shiftKey||i.metaKey)return;if(function(e){e.preventDefault(),e.stopPropagation()}(i),t)return;t=!0;const r=a.startClickDelayTracker();(yield o).dispatch(e),r(),t=!1}));return function(e){return i.apply(this,arguments)}}())})),a.recordTimeToLinkListenersAttached(),yield o}}));"loading"===document.readyState?document.addEventListener("DOMContentLoaded",m):m()},7850:(e,t,i)=>{var r=i(111),n=i(4326),o=i(5112)("match");e.exports=function(e){var t;return r(e)&&(void 0!==(t=e[o])?!!t:"RegExp"==n(e))}},6048:(e,t,i)=>{var r=i(9781),n=i(3353),o=i(3070),a=i(9670),s=i(5656),c=i(1956);t.f=r&&!n?Object.defineProperties:function(e,t){a(e);for(var i,r=s(t),n=c(t),l=n.length,d=0;l>d;)o.f(e,i=n[d++],r[i]);return e}},8006:(e,t,i)=>{var r=i(6324),n=i(748).concat("length","prototype");t.f=Object.getOwnPropertyNames||function(e){return r(e,n)}},4603:(e,t,i)=>{var r=i(9781),n=i(7854),o=i(1702),a=i(4705),s=i(9587),c=i(8880),l=i(3070).f,d=i(8006).f,u=i(7976),h=i(7850),p=i(1340),g=i(7066),f=i(2999),m=i(1320),w=i(7293),v=i(2597),E=i(9909).enforce,y=i(6340),T=i(5112),b=i(9441),k=i(7168),_=T("match"),I=n.RegExp,R=I.prototype,x=n.SyntaxError,D=o(g),O=o(R.exec),P=o("".charAt),N=o("".replace),A=o("".indexOf),Z=o("".slice),S=/^\?<[^\s\d!#%&*+<=>@^][^\s!#%&*+<=>@^]*>/,L=/a/g,X=/a/g,C=new I(L)!==L,F=f.MISSED_STICKY,B=f.UNSUPPORTED_Y,W=r&&(!C||F||b||k||w((function(){return X[_]=!1,I(L)!=L||I(X)==X||"/a/i"!=I(L,"i")})));if(a("RegExp",W)){for(var j=function(e,t){var i,r,n,o,a,l,d=u(R,this),g=h(e),f=void 0===t,m=[],w=e;if(!d&&g&&f&&e.constructor===j)return e;if((g||u(R,e))&&(e=e.source,f&&(t="flags"in w?w.flags:D(w))),e=void 0===e?"":p(e),t=void 0===t?"":p(t),w=e,b&&"dotAll"in L&&(r=!!t&&A(t,"s")>-1)&&(t=N(t,/s/g,"")),i=t,F&&"sticky"in L&&(n=!!t&&A(t,"y")>-1)&&B&&(t=N(t,/y/g,"")),k&&(e=(o=function(e){for(var t,i=e.length,r=0,n="",o=[],a={},s=!1,c=!1,l=0,d="";r<=i;r++){if("\\"===(t=P(e,r)))t+=P(e,++r);else if("]"===t)s=!1;else if(!s)switch(!0){case"["===t:s=!0;break;case"("===t:O(S,Z(e,r+1))&&(r+=2,c=!0),n+=t,l++;continue;case">"===t&&c:if(""===d||v(a,d))throw new x("Invalid capture group name");a[d]=!0,o[o.length]=[d,l],c=!1,d="";continue}c?d+=t:n+=t}return[n,o]}(e))[0],m=o[1]),a=s(I(e,t),d?this:R,j),(r||n||m.length)&&(l=E(a),r&&(l.dotAll=!0,l.raw=j(function(e){for(var t,i=e.length,r=0,n="",o=!1;r<=i;r++)"\\"!==(t=P(e,r))?o||"."!==t?("["===t?o=!0:"]"===t&&(o=!1),n+=t):n+="[\\s\\S]":n+=t+P(e,++r);return n}(e),i)),n&&(l.sticky=!0),m.length&&(l.groups=m)),e!==w)try{c(a,"source",""===w?"(?:)":w)}catch(e){}return a},M=function(e){e in j||l(j,e,{configurable:!0,get:function(){return I[e]},set:function(t){I[e]=t}})},Y=d(I),G=0;Y.length>G;)M(Y[G++]);R.constructor=j,j.prototype=R,m(n,"RegExp",j)}y("RegExp")},8450:(e,t,i)=>{var r=i(7854),n=i(9781),o=i(9441),a=i(4326),s=i(3070).f,c=i(9909).get,l=RegExp.prototype,d=r.TypeError;n&&o&&s(l,"dotAll",{configurable:!0,get:function(){if(this!==l){if("RegExp"===a(this))return!!c(this).dotAll;throw d("Incompatible receiver, RegExp required")}}})},4916:(e,t,i)=>{"use strict";var r=i(2109),n=i(2261);r({target:"RegExp",proto:!0,forced:/./.exec!==n},{exec:n})}},i={};function r(e){var n=i[e];if(void 0!==n)return n.exports;var o=i[e]={exports:{}};return t[e](o,o.exports,r),o.exports}r.m=t,e=[],r.O=(t,i,n,o)=>{if(!i){var a=1/0;for(d=0;d<e.length;d++){for(var[i,n,o]=e[d],s=!0,c=0;c<i.length;c++)(!1&o||a>=o)&&Object.keys(r.O).every((e=>r.O[e](i[c])))?i.splice(c--,1):(s=!1,o<a&&(a=o));if(s){e.splice(d--,1);var l=n();void 0!==l&&(t=l)}}return t}o=o||0;for(var d=e.length;d>0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[i,n,o]},r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e={410:0};r.O.j=t=>0===e[t];var t=(t,i)=>{var n,o,[a,s,c]=i,l=0;if(a.some((t=>0!==e[t]))){for(n in s)r.o(s,n)&&(r.m[n]=s[n]);if(c)var d=c(r)}for(t&&t(i);l<a.length;l++)o=a[l],r.o(e,o)&&e[o]&&e[o][0](),e[o]=0;return r.O(d)},i=self.webpackChunkdata_bridge=self.webpackChunkdata_bridge||[];i.forEach(t.bind(null,0)),i.push=t.bind(null,i.push.bind(i))})();var n=r.O(void 0,[998],(()=>r(1547)));n=r.O(n),module.exports=n})();