@acrolinx/app-sdk
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -1,12 +0,12 @@ | ||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"//Qm":[function(require,module,exports) { | ||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"QmUd":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){function t(){this.listener=[]}return t.prototype.addEventListener=function(t){this.listener.push(t)},t.prototype.removeEventListener=function(t){this.listener=this.listener.filter(function(e){return e!==t})},t.prototype.dispatchEvent=function(t){this.listener.forEach(function(e){e(t)})},t}();exports.InternalEventEmitter=t; | ||
},{}],"/eMv":[function(require,module,exports) { | ||
},{}],"eMvI":[function(require,module,exports) { | ||
"use strict";var e,n;function o(){return window.parent&&window.parent!==window}function t(e){o()?window.parent.postMessage({command:"acrolinx.sidebar.openWindow",url:e},"*"):window.open(e)}function a(e){i({command:"acrolinx.sidebar.selectRanges",ranges:e})}function r(e){i({command:"acrolinx.sidebar.replaceRanges",ranges:e})}function s(e){i({command:"acrolinx.sidebar.configureAddon",config:e})}function i(e){o()?window.parent.postMessage(e,"*"):console.warn("Missing parent window with sidebar.",e)}Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.extractedText="extractedText"}(e=exports.ReportType||(exports.ReportType={})),function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges"}(n=exports.AppApiCapability||(exports.AppApiCapability={})),exports.hasParentWindow=o,exports.openWindow=t,exports.selectRanges=a,exports.replaceRanges=r,exports.configureAddon=s; | ||
},{}],"UnXq":[function(require,module,exports) { | ||
"use strict";function e(e,n){return!!e&&e.indexOf(n)>=0}function n(e,n){return!(n.begin>=e.end||n.end<=e.begin)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.includes=e,exports.isOverlapping=n; | ||
},{}],"7QCb":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.OffsetRange=n.OffsetRange;var r,i,a=require("./utils");exports.DEVELOPMENT_APP_SIGNATURE="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg",function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges",e.openWindow="openWindow"}(r=exports.ApiCommands||(exports.ApiCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges"}(i=exports.ApiEvents||(exports.ApiEvents={}));var s={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function r(r){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter},this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow};var p=[];a.includes(r.requiredEvents,i.textExtractedLink)&&p.push(n.ReportType.extractedText);var d=[];a.includes(r.requiredEvents,i.textExtracted)&&d.push(n.ReportType.extractedText),n.configureAddon(e({},s,r,{requiredReportLinks:p,requiredReportContent:d,requires:r.requiredCommands})),window.addEventListener("message",function(e){console.log("Got message from sidebar",e.data.type,e);var t=e.data;if(t)if("analysisResult"===t.type){var r=t,i=r.reports[n.ReportType.extractedText]||{};i.url&&o._events.textExtractedLink.dispatchEvent({url:i.url,languageId:r.languageId}),"string"==typeof i.content&&o._events.textExtracted.dispatchEvent({text:i.content,languageId:r.languageId})}else"invalidRanges"===t.type&&o._events.invalidRanges.dispatchEvent(t)},!1)}return Object.defineProperty(r.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),r}();function p(e){return new o(e)}function d(e,t){return e.ranges.some(function(e){return a.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=d; | ||
},{"./event-emitter":"//Qm","./raw":"/eMv","./utils":"UnXq"}],"M10p":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},t=this&&this.__values||function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}},n=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,i=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)o.push(r.value)}catch(l){a={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(a)throw a.error}}return o},r=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(n(arguments[t]));return e};Object.defineProperty(exports,"__esModule",{value:!0});var a=require("./index"),i=require("./raw"),o=require("./utils");function l(e){var t=document.querySelector("meta[name="+e+"]");return t&&t.content}function c(){var e,n,r=document.querySelectorAll('[data-acrolinx="hide"]');try{for(var a=t(r),i=a.next();!i.done;i=a.next()){i.value.style.display="none"}}catch(o){e={error:o}}finally{try{i&&!i.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}}function s(e,t){return u(e,function(e){return void 0!==e.dataset[t]})}function u(e,t){for(var n=e;n&&n!==document.body;){if(t(n))return n;n=n.parentElement}}function d(e){var n,r;try{for(var a=t(document.getElementsByClassName(e)),i=a.next();!i.done;i=a.next()){i.value.classList.remove(e)}}catch(o){n={error:o}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}function f(e){return e.filter(function(e){return e})}var v="acrolinx-invalid-range";function p(e){var n=l("acrolinx-app-invalid-range-tooltip");e.events.invalidRanges.addEventListener(function(e){var r,i,o=document.querySelectorAll("[data-acrolinx-select-range]");try{for(var l=t(o),c=l.next();!c.done;c=l.next()){var s=c.value,u=JSON.parse(s.dataset.acrolinxSelectRange);a.isInvalid(e,u)&&(s.classList.add(v),n&&(s.title=n))}}catch(d){r={error:d}}finally{try{c&&!c.done&&(i=l.return)&&i.call(l)}finally{if(r)throw r.error}}})}function x(e){var t=s(e,"acrolinxSelectRange");if(t&&!t.classList.contains(v)){var n=t.dataset.acrolinxSelectRange;return{element:t,range:JSON.parse(n)}}}function m(e){document.addEventListener("click",function(t){var n=x(t.target);n&&(d("acrolinx-selected-range"),n.element.classList.add("acrolinx-selected-range"),e.commands.selectRanges([n.range]))})}function y(t){document.addEventListener("click",function(n){var r=s(n.target,"acrolinxReplaceRange");if(r){var a=r.dataset.acrolinxReplaceRange,i=x(r);i&&(i.element.classList.add("acrolinx-replaced-range"),t.commands.replaceRanges([e({},i.range,{replacement:a})]))}})}function g(){i.hasParentWindow()&&c();var e=document.querySelector("title"),t=l("acrolinx-app-title")||e&&e.innerText,n=document.querySelector('[data-acrolinx="extractedText"]'),s=(l("acrolinx-app-required-commands")||"").split(/, */),u=(l("acrolinx-app-required-events")||"").split(/, *?/),d=a.initApi({title:t||window.location.href,button:{text:l("acrolinx-app-button-text")||"Check",tooltip:l("acrolinx-app-button-tooltip")||""},requiredCommands:s,requiredEvents:f(r([n&&a.ApiEvents.textExtracted],u))});n&&d.events.textExtracted.addEventListener(function(e){n.value=e.text,n.form.submit()}),o.includes(u,a.ApiEvents.invalidRanges)&&p(d),o.includes(s,a.ApiCommands.selectRanges)&&m(d),o.includes(s,a.ApiCommands.replaceRanges)&&y(d)}window.addEventListener("DOMContentLoaded",g); | ||
},{"./index":"7QCb","./raw":"/eMv","./utils":"UnXq"}]},{},["M10p"], null) | ||
},{}],"QCba":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.OffsetRange=n.OffsetRange;var r,i,a=require("./utils");exports.DEVELOPMENT_APP_SIGNATURE="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg",function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges",e.openWindow="openWindow"}(r=exports.ApiCommands||(exports.ApiCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges"}(i=exports.ApiEvents||(exports.ApiEvents={}));var s={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function r(r){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter},this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow};var p=[];a.includes(r.requiredEvents,i.textExtractedLink)&&p.push(n.ReportType.extractedText);var d=[];a.includes(r.requiredEvents,i.textExtracted)&&d.push(n.ReportType.extractedText),n.configureAddon(e(e(e({},s),r),{requiredReportLinks:p,requiredReportContent:d,requires:r.requiredCommands})),window.addEventListener("message",function(e){console.log("Got message from sidebar",e.data.type,e);var t=e.data;if(t)if("analysisResult"===t.type){var r=t,i=r.reports[n.ReportType.extractedText]||{};i.url&&o._events.textExtractedLink.dispatchEvent({url:i.url,languageId:r.languageId}),"string"==typeof i.content&&o._events.textExtracted.dispatchEvent({text:i.content,languageId:r.languageId})}else"invalidRanges"===t.type&&o._events.invalidRanges.dispatchEvent(t)},!1)}return Object.defineProperty(r.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),r}();function p(e){return new o(e)}function d(e,t){return e.ranges.some(function(e){return a.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=d; | ||
},{"./event-emitter":"QmUd","./raw":"eMvI","./utils":"UnXq"}],"M10p":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},t=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},n=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,i=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)o.push(r.value)}catch(l){a={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(a)throw a.error}}return o},r=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(n(arguments[t]));return e};Object.defineProperty(exports,"__esModule",{value:!0});var a=require("./index"),i=require("./raw"),o=require("./utils");function l(e){var t=document.querySelector("meta[name="+e+"]");return t&&t.content}function c(){var e,n,r=document.querySelectorAll('[data-acrolinx="hide"]');try{for(var a=t(r),i=a.next();!i.done;i=a.next()){i.value.style.display="none"}}catch(o){e={error:o}}finally{try{i&&!i.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}}function s(e,t){return u(e,function(e){return void 0!==e.dataset[t]})}function u(e,t){for(var n=e;n&&n!==document.body;){if(t(n))return n;n=n.parentElement}}function d(e){var n,r;try{for(var a=t(document.getElementsByClassName(e)),i=a.next();!i.done;i=a.next()){i.value.classList.remove(e)}}catch(o){n={error:o}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}function f(e){return e.filter(function(e){return e})}var v="acrolinx-invalid-range";function p(e){var n=l("acrolinx-app-invalid-range-tooltip");e.events.invalidRanges.addEventListener(function(e){var r,i,o=document.querySelectorAll("[data-acrolinx-select-range]");try{for(var l=t(o),c=l.next();!c.done;c=l.next()){var s=c.value,u=JSON.parse(s.dataset.acrolinxSelectRange);a.isInvalid(e,u)&&(s.classList.add(v),n&&(s.title=n))}}catch(d){r={error:d}}finally{try{c&&!c.done&&(i=l.return)&&i.call(l)}finally{if(r)throw r.error}}})}function m(e){var t=s(e,"acrolinxSelectRange");if(t&&!t.classList.contains(v)){var n=t.dataset.acrolinxSelectRange;return{element:t,range:JSON.parse(n)}}}function x(e){document.addEventListener("click",function(t){var n=m(t.target);n&&(d("acrolinx-selected-range"),n.element.classList.add("acrolinx-selected-range"),e.commands.selectRanges([n.range]))})}function y(t){document.addEventListener("click",function(n){var r=s(n.target,"acrolinxReplaceRange");if(r){var a=r.dataset.acrolinxReplaceRange,i=m(r);i&&(i.element.classList.add("acrolinx-replaced-range"),t.commands.replaceRanges([e(e({},i.range),{replacement:a})]))}})}function g(){i.hasParentWindow()&&c();var e=document.querySelector("title"),t=l("acrolinx-app-title")||e&&e.innerText,n=document.querySelector('[data-acrolinx="extractedText"]'),s=(l("acrolinx-app-required-commands")||"").split(/, */),u=(l("acrolinx-app-required-events")||"").split(/, *?/),d=a.initApi({title:t||window.location.href,button:{text:l("acrolinx-app-button-text")||"Check",tooltip:l("acrolinx-app-button-tooltip")||""},requiredCommands:s,requiredEvents:f(r([n&&a.ApiEvents.textExtracted],u))});n&&d.events.textExtracted.addEventListener(function(e){n.value=e.text,n.form.submit()}),o.includes(u,a.ApiEvents.invalidRanges)&&p(d),o.includes(s,a.ApiCommands.selectRanges)&&x(d),o.includes(s,a.ApiCommands.replaceRanges)&&y(d)}window.addEventListener("DOMContentLoaded",g); | ||
},{"./index":"QCba","./raw":"eMvI","./utils":"UnXq"}]},{},["M10p"], null) | ||
//# sourceMappingURL=/acrolinx-app-sdk-auto-form.min.js.map |
@@ -1,10 +0,10 @@ | ||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"//Qm":[function(require,module,exports) { | ||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"QmUd":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){function t(){this.listener=[]}return t.prototype.addEventListener=function(t){this.listener.push(t)},t.prototype.removeEventListener=function(t){this.listener=this.listener.filter(function(e){return e!==t})},t.prototype.dispatchEvent=function(t){this.listener.forEach(function(e){e(t)})},t}();exports.InternalEventEmitter=t; | ||
},{}],"/eMv":[function(require,module,exports) { | ||
},{}],"eMvI":[function(require,module,exports) { | ||
"use strict";var e,n;function o(){return window.parent&&window.parent!==window}function t(e){o()?window.parent.postMessage({command:"acrolinx.sidebar.openWindow",url:e},"*"):window.open(e)}function a(e){i({command:"acrolinx.sidebar.selectRanges",ranges:e})}function r(e){i({command:"acrolinx.sidebar.replaceRanges",ranges:e})}function s(e){i({command:"acrolinx.sidebar.configureAddon",config:e})}function i(e){o()?window.parent.postMessage(e,"*"):console.warn("Missing parent window with sidebar.",e)}Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.extractedText="extractedText"}(e=exports.ReportType||(exports.ReportType={})),function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges"}(n=exports.AppApiCapability||(exports.AppApiCapability={})),exports.hasParentWindow=o,exports.openWindow=t,exports.selectRanges=a,exports.replaceRanges=r,exports.configureAddon=s; | ||
},{}],"UnXq":[function(require,module,exports) { | ||
"use strict";function e(e,n){return!!e&&e.indexOf(n)>=0}function n(e,n){return!(n.begin>=e.end||n.end<=e.begin)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.includes=e,exports.isOverlapping=n; | ||
},{}],"7QCb":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.OffsetRange=n.OffsetRange;var r,i,a=require("./utils");exports.DEVELOPMENT_APP_SIGNATURE="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg",function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges",e.openWindow="openWindow"}(r=exports.ApiCommands||(exports.ApiCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges"}(i=exports.ApiEvents||(exports.ApiEvents={}));var s={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function r(r){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter},this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow};var p=[];a.includes(r.requiredEvents,i.textExtractedLink)&&p.push(n.ReportType.extractedText);var d=[];a.includes(r.requiredEvents,i.textExtracted)&&d.push(n.ReportType.extractedText),n.configureAddon(e({},s,r,{requiredReportLinks:p,requiredReportContent:d,requires:r.requiredCommands})),window.addEventListener("message",function(e){console.log("Got message from sidebar",e.data.type,e);var t=e.data;if(t)if("analysisResult"===t.type){var r=t,i=r.reports[n.ReportType.extractedText]||{};i.url&&o._events.textExtractedLink.dispatchEvent({url:i.url,languageId:r.languageId}),"string"==typeof i.content&&o._events.textExtracted.dispatchEvent({text:i.content,languageId:r.languageId})}else"invalidRanges"===t.type&&o._events.invalidRanges.dispatchEvent(t)},!1)}return Object.defineProperty(r.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),r}();function p(e){return new o(e)}function d(e,t){return e.ranges.some(function(e){return a.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=d; | ||
},{"./event-emitter":"//Qm","./raw":"/eMv","./utils":"UnXq"}]},{},["7QCb"], "acrolinxAppSdk") | ||
},{}],"QCba":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.OffsetRange=n.OffsetRange;var r,i,a=require("./utils");exports.DEVELOPMENT_APP_SIGNATURE="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg",function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges",e.openWindow="openWindow"}(r=exports.ApiCommands||(exports.ApiCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges"}(i=exports.ApiEvents||(exports.ApiEvents={}));var s={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function r(r){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter},this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow};var p=[];a.includes(r.requiredEvents,i.textExtractedLink)&&p.push(n.ReportType.extractedText);var d=[];a.includes(r.requiredEvents,i.textExtracted)&&d.push(n.ReportType.extractedText),n.configureAddon(e(e(e({},s),r),{requiredReportLinks:p,requiredReportContent:d,requires:r.requiredCommands})),window.addEventListener("message",function(e){console.log("Got message from sidebar",e.data.type,e);var t=e.data;if(t)if("analysisResult"===t.type){var r=t,i=r.reports[n.ReportType.extractedText]||{};i.url&&o._events.textExtractedLink.dispatchEvent({url:i.url,languageId:r.languageId}),"string"==typeof i.content&&o._events.textExtracted.dispatchEvent({text:i.content,languageId:r.languageId})}else"invalidRanges"===t.type&&o._events.invalidRanges.dispatchEvent(t)},!1)}return Object.defineProperty(r.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),r}();function p(e){return new o(e)}function d(e,t){return e.ranges.some(function(e){return a.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=d; | ||
},{"./event-emitter":"QmUd","./raw":"eMvI","./utils":"UnXq"}]},{},["QCba"], "acrolinxAppSdk") | ||
//# sourceMappingURL=/acrolinx-app-sdk.min.js.map |
export {}; | ||
//# sourceMappingURL=auto-form.d.ts.map |
@@ -28,6 +28,6 @@ "use strict"; | ||
}; | ||
var __values = (this && this.__values) || function (o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
@@ -38,2 +38,3 @@ if (o && i >= o.length) o = void 0; | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
@@ -67,2 +68,3 @@ var __read = (this && this.__read) || function (o, n) { | ||
var utils_1 = require("./utils"); | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
function getMetaValue(name) { | ||
@@ -150,7 +152,11 @@ var metaEl = document.querySelector("meta[name=" + name + "]"); | ||
var elementWithSelectRange = findAncestorWithData(startElement, 'acrolinxSelectRange'); | ||
if (!elementWithSelectRange || elementWithSelectRange.classList.contains(INVALID_RANGE_CLASS_NAME)) { | ||
if (!elementWithSelectRange || | ||
elementWithSelectRange.classList.contains(INVALID_RANGE_CLASS_NAME)) { | ||
return; | ||
} | ||
var offsetRangeString = elementWithSelectRange.dataset.acrolinxSelectRange; | ||
return { element: elementWithSelectRange, range: JSON.parse(offsetRangeString) }; | ||
return { | ||
element: elementWithSelectRange, | ||
range: JSON.parse(offsetRangeString) | ||
}; | ||
} | ||
@@ -180,3 +186,3 @@ function addClickSelectRangeListener(appApi) { | ||
elementWithRange.element.classList.add('acrolinx-replaced-range'); | ||
appApi.commands.replaceRanges([__assign({}, elementWithRange.range, { replacement: replacement })]); | ||
appApi.commands.replaceRanges([__assign(__assign({}, elementWithRange.range), { replacement: replacement })]); | ||
}); | ||
@@ -202,3 +208,3 @@ } | ||
acrolinxExtractedTextField && index_1.ApiEvents.textExtracted | ||
], requiredEvents)), | ||
], requiredEvents)) | ||
}); | ||
@@ -205,0 +211,0 @@ if (acrolinxExtractedTextField) { |
@@ -13,1 +13,2 @@ declare type TypedEventListener<T> = (event: T) => void; | ||
export {}; | ||
//# sourceMappingURL=event-emitter.d.ts.map |
import { TypedEventEmitter } from './event-emitter'; | ||
import { AppButtonConfig, OffsetRange, openWindow, replaceRanges, selectRanges } from './raw'; | ||
export { OffsetRange }; | ||
/** | ||
* @public | ||
*/ | ||
export declare const DEVELOPMENT_APP_SIGNATURE = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg"; | ||
/** | ||
* @public | ||
*/ | ||
export interface ExtractedTextEvent { | ||
@@ -9,2 +15,5 @@ languageId: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface ExtractedTextLinkEvent { | ||
@@ -14,5 +23,11 @@ languageId: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface TextRangesExpiredEvent { | ||
ranges: OffsetRange[]; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum ApiCommands { | ||
@@ -23,2 +38,5 @@ selectRanges = "selectRanges", | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum ApiEvents { | ||
@@ -29,3 +47,6 @@ textExtracted = "textExtracted", | ||
} | ||
interface AppEvents { | ||
/** | ||
* @public | ||
*/ | ||
export interface AppEvents { | ||
textExtracted: TypedEventEmitter<ExtractedTextEvent>; | ||
@@ -35,3 +56,6 @@ textExtractedLink: TypedEventEmitter<ExtractedTextLinkEvent>; | ||
} | ||
interface AppCommands { | ||
/** | ||
* @public | ||
*/ | ||
export interface AppCommands { | ||
selectRanges: typeof selectRanges; | ||
@@ -41,2 +65,5 @@ replaceRanges: typeof replaceRanges; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface AcrolinxAppApi<C extends keyof AppCommands, E extends keyof AppEvents> { | ||
@@ -46,2 +73,5 @@ events: Pick<AppEvents, E>; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface ApiConfig<C extends keyof AppCommands, E extends keyof AppEvents> { | ||
@@ -54,3 +84,10 @@ title?: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare function initApi<C extends keyof AppCommands, E extends keyof AppEvents>(conf: ApiConfig<C, E>): AcrolinxAppApi<C, E>; | ||
/** | ||
* @public | ||
*/ | ||
export declare function isInvalid(event: TextRangesExpiredEvent, range: OffsetRange): boolean; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -32,4 +32,9 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
// tslint:disable-next-line:max-line-length | ||
/** | ||
* @public | ||
*/ | ||
exports.DEVELOPMENT_APP_SIGNATURE = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg'; | ||
/** | ||
* @public | ||
*/ | ||
var ApiCommands; | ||
@@ -41,2 +46,5 @@ (function (ApiCommands) { | ||
})(ApiCommands = exports.ApiCommands || (exports.ApiCommands = {})); | ||
/** | ||
* @public | ||
*/ | ||
var ApiEvents; | ||
@@ -52,3 +60,3 @@ (function (ApiEvents) { | ||
requiredReportContent: [], | ||
requiredReportLinks: [], | ||
requiredReportLinks: [] | ||
}; | ||
@@ -76,3 +84,4 @@ var AppApiConnection = /** @class */ (function () { | ||
} | ||
raw_1.configureAddon(__assign({}, DEFAULT_CONFIG, (config), { requiredReportLinks: requiredReportLinks, requiredReportContent: requiredReportContent, requires: config.requiredCommands })); | ||
raw_1.configureAddon(__assign(__assign(__assign({}, DEFAULT_CONFIG), config), { requiredReportLinks: requiredReportLinks, | ||
requiredReportContent: requiredReportContent, requires: config.requiredCommands })); | ||
window.addEventListener('message', function (messageEvent) { | ||
@@ -122,2 +131,5 @@ console.log('Got message from sidebar', messageEvent.data.type, messageEvent); | ||
}()); | ||
/** | ||
* @public | ||
*/ | ||
function initApi(conf) { | ||
@@ -127,2 +139,5 @@ return new AppApiConnection(conf); | ||
exports.initApi = initApi; | ||
/** | ||
* @public | ||
*/ | ||
function isInvalid(event, range) { | ||
@@ -129,0 +144,0 @@ return event.ranges.some(function (inValidRange) { return utils_1.isOverlapping(inValidRange, range); }); |
@@ -37,2 +37,5 @@ export interface AppButtonConfig { | ||
export declare type EventForApp = AnalysisResultEvent | InvalidateRangesEvent; | ||
/** | ||
* @public | ||
*/ | ||
export interface OffsetRange { | ||
@@ -53,1 +56,2 @@ begin: number; | ||
export {}; | ||
//# sourceMappingURL=raw.d.ts.map |
import { OffsetRange } from './raw'; | ||
export declare function includes<T>(array: T[] | undefined, element: any): boolean; | ||
export declare function isOverlapping(range1: OffsetRange, range2: OffsetRange): boolean; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -18,2 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function includes(array, element) { | ||
@@ -27,3 +28,3 @@ if (!array) { | ||
function isOverlapping(range1, range2) { | ||
var isNotOverlapping = (range2.begin >= range1.end || range2.end <= range1.begin); | ||
var isNotOverlapping = range2.begin >= range1.end || range2.end <= range1.begin; | ||
return !isNotOverlapping; | ||
@@ -30,0 +31,0 @@ } |
{ | ||
"name": "@acrolinx/app-sdk", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Acrolinx App SDK", | ||
@@ -24,3 +24,3 @@ "license": "Apache-2.0", | ||
"scripts": { | ||
"ci": "npm run build && npm run tslint && npm run testCoverage && npm run testMarkdown", | ||
"ci": "npm run build && npm run lint && npm run testCoverage && npm run testMarkdown", | ||
"clean": "rm -rf dist tmp .cache", | ||
@@ -36,17 +36,25 @@ "build": "tsc && npm run buildBrowserBundle && npm run buildAutoForm", | ||
"tsc": "tsc", | ||
"tslint": "tslint -p tsconfig.json -t stylish", | ||
"tslintFix": "tslint --fix -p tsconfig.json -t stylish" | ||
"lint": "eslint . --ext .js,.ts -f unix", | ||
"prettier": "prettier --write \"{src,test}/**/*.ts\"", | ||
"gendoc": "tsc && api-extractor run --local --verbose && api-documenter markdown --input-folder tmp --output-folder docs/api", | ||
"typedoc": "typedoc" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.13", | ||
"@types/node": "^10.14.9", | ||
"jest": "^24.8.0", | ||
"jest-junit": "^6.4.0", | ||
"markdown-doctest": "^0.9.1", | ||
"parcel": "^1.12.3", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "5.17.0", | ||
"tslint-no-circular-imports": "^0.7.0", | ||
"tslint-sonarts": "^1.9.0", | ||
"typescript": "^3.5.1" | ||
"@microsoft/api-documenter": "^7.7.2", | ||
"@microsoft/api-extractor": "^7.7.0", | ||
"@types/jest": "^24.0.25", | ||
"@typescript-eslint/eslint-plugin": "^2.14.0", | ||
"@typescript-eslint/parser": "^2.14.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-plugin-import": "^2.19.1", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"jest": "^24.9.0", | ||
"jest-junit": "^10.0.0", | ||
"markdown-doctest": "^1.0.0", | ||
"parcel": "^1.12.4", | ||
"prettier": "1.19.1", | ||
"ts-jest": "^24.2.0", | ||
"typedoc": "^0.15.6", | ||
"typescript": "^3.7.4" | ||
}, | ||
@@ -76,4 +84,5 @@ "jest": { | ||
"jest-junit": { | ||
"output": "tmp/junit.xml" | ||
"outputDirectory": "tmp", | ||
"outputName": "junit.xml" | ||
} | ||
} |
@@ -17,3 +17,2 @@ /* | ||
/** | ||
@@ -23,6 +22,15 @@ * This module is highly experimental. | ||
import {AcrolinxAppApi, ApiCommands, ApiEvents, initApi, isInvalid, OffsetRange} from './index'; | ||
import {hasParentWindow} from './raw'; | ||
import {includes} from './utils'; | ||
import { | ||
AcrolinxAppApi, | ||
ApiCommands, | ||
ApiEvents, | ||
initApi, | ||
isInvalid, | ||
OffsetRange | ||
} from './index'; | ||
import { hasParentWindow } from './raw'; | ||
import { includes } from './utils'; | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
function getMetaValue(name: string) { | ||
@@ -34,3 +42,5 @@ const metaEl = document.querySelector<HTMLMetaElement>(`meta[name=${name}]`); | ||
function hideElements() { | ||
const elementsToHide = document.querySelectorAll<HTMLElement>('[data-acrolinx="hide"]'); | ||
const elementsToHide = document.querySelectorAll<HTMLElement>( | ||
'[data-acrolinx="hide"]' | ||
); | ||
for (const el of elementsToHide) { | ||
@@ -41,8 +51,17 @@ el.style.display = 'none'; | ||
function findAncestorWithData(startElement: HTMLElement, dataAttribute: string): HTMLElement | undefined { | ||
return findAncestor(startElement, el => el.dataset[dataAttribute] !== undefined); | ||
function findAncestorWithData( | ||
startElement: HTMLElement, | ||
dataAttribute: string | ||
): HTMLElement | undefined { | ||
return findAncestor( | ||
startElement, | ||
el => el.dataset[dataAttribute] !== undefined | ||
); | ||
} | ||
function findAncestor(startElement: HTMLElement, condition: (el: HTMLElement) => boolean): HTMLElement | undefined { | ||
let el = startElement; | ||
function findAncestor( | ||
startElement: HTMLElement, | ||
condition: (el: HTMLElement) => boolean | ||
): HTMLElement | undefined { | ||
let el: HTMLElement | null = startElement; | ||
while (el && el !== document.body) { | ||
@@ -52,3 +71,3 @@ if (condition(el)) { | ||
} | ||
el = el.parentElement!; | ||
el = el.parentElement; | ||
} | ||
@@ -70,6 +89,12 @@ return undefined; | ||
function addInvalidRangesListener(appApi: AcrolinxAppApi<ApiCommands, ApiEvents>) { | ||
const invalidRangeTooltip = getMetaValue('acrolinx-app-invalid-range-tooltip'); | ||
appApi.events.invalidRanges.addEventListener((invalidRangesEvent) => { | ||
const selectRangesElements = document.querySelectorAll<HTMLElement>('[data-acrolinx-select-range]'); | ||
function addInvalidRangesListener( | ||
appApi: AcrolinxAppApi<ApiCommands, ApiEvents> | ||
) { | ||
const invalidRangeTooltip = getMetaValue( | ||
'acrolinx-app-invalid-range-tooltip' | ||
); | ||
appApi.events.invalidRanges.addEventListener(invalidRangesEvent => { | ||
const selectRangesElements = document.querySelectorAll<HTMLElement>( | ||
'[data-acrolinx-select-range]' | ||
); | ||
for (const el of selectRangesElements) { | ||
@@ -92,14 +117,29 @@ const offsetRange = JSON.parse(el.dataset.acrolinxSelectRange!); | ||
function findAncestorWithValidSelectRange(startElement: HTMLElement): ElementWithRange | undefined { | ||
const elementWithSelectRange = findAncestorWithData(startElement, 'acrolinxSelectRange'); | ||
if (!elementWithSelectRange || elementWithSelectRange.classList.contains(INVALID_RANGE_CLASS_NAME)) { | ||
function findAncestorWithValidSelectRange( | ||
startElement: HTMLElement | ||
): ElementWithRange | undefined { | ||
const elementWithSelectRange = findAncestorWithData( | ||
startElement, | ||
'acrolinxSelectRange' | ||
); | ||
if ( | ||
!elementWithSelectRange || | ||
elementWithSelectRange.classList.contains(INVALID_RANGE_CLASS_NAME) | ||
) { | ||
return; | ||
} | ||
const offsetRangeString = elementWithSelectRange.dataset.acrolinxSelectRange!; | ||
return {element: elementWithSelectRange, range: JSON.parse(offsetRangeString)}; | ||
return { | ||
element: elementWithSelectRange, | ||
range: JSON.parse(offsetRangeString) | ||
}; | ||
} | ||
function addClickSelectRangeListener(appApi: AcrolinxAppApi<ApiCommands, ApiEvents>) { | ||
document.addEventListener('click', (ev) => { | ||
const elementWithRange = findAncestorWithValidSelectRange(ev.target as HTMLElement); | ||
function addClickSelectRangeListener( | ||
appApi: AcrolinxAppApi<ApiCommands, ApiEvents> | ||
) { | ||
document.addEventListener('click', ev => { | ||
const elementWithRange = findAncestorWithValidSelectRange( | ||
ev.target as HTMLElement | ||
); | ||
if (!elementWithRange) { | ||
@@ -116,5 +156,10 @@ return; | ||
function addClickReplaceRangeListener(appApi: AcrolinxAppApi<ApiCommands, ApiEvents>) { | ||
document.addEventListener('click', (ev) => { | ||
const elementWithReplaceRange = findAncestorWithData(ev.target as HTMLElement, 'acrolinxReplaceRange'); | ||
function addClickReplaceRangeListener( | ||
appApi: AcrolinxAppApi<ApiCommands, ApiEvents> | ||
) { | ||
document.addEventListener('click', ev => { | ||
const elementWithReplaceRange = findAncestorWithData( | ||
ev.target as HTMLElement, | ||
'acrolinxReplaceRange' | ||
); | ||
if (!elementWithReplaceRange) { | ||
@@ -126,3 +171,5 @@ return; | ||
const elementWithRange = findAncestorWithValidSelectRange(elementWithReplaceRange); | ||
const elementWithRange = findAncestorWithValidSelectRange( | ||
elementWithReplaceRange | ||
); | ||
if (!elementWithRange) { | ||
@@ -134,3 +181,3 @@ return; | ||
appApi.commands.replaceRanges([{...elementWithRange.range, replacement}]); | ||
appApi.commands.replaceRanges([{ ...elementWithRange.range, replacement }]); | ||
}); | ||
@@ -145,7 +192,14 @@ } | ||
const title = document.querySelector('title'); | ||
const appTitle = getMetaValue('acrolinx-app-title') || (title && title.innerText); | ||
const acrolinxExtractedTextField = document.querySelector<HTMLTextAreaElement>('[data-acrolinx="extractedText"]'); | ||
const appTitle = | ||
getMetaValue('acrolinx-app-title') || (title && title.innerText); | ||
const acrolinxExtractedTextField = document.querySelector< | ||
HTMLTextAreaElement | ||
>('[data-acrolinx="extractedText"]'); | ||
const requiredCommands = (getMetaValue('acrolinx-app-required-commands') || '').split(/, */); | ||
const requiredEvents = (getMetaValue('acrolinx-app-required-events') || '').split(/, *?/); | ||
const requiredCommands = ( | ||
getMetaValue('acrolinx-app-required-commands') || '' | ||
).split(/, */); | ||
const requiredEvents = ( | ||
getMetaValue('acrolinx-app-required-events') || '' | ||
).split(/, *?/); | ||
const appApi = initApi({ | ||
@@ -161,3 +215,3 @@ title: appTitle || window.location.href, | ||
...(requiredEvents as ApiEvents[]) | ||
]), | ||
]) | ||
}); | ||
@@ -167,6 +221,5 @@ | ||
appApi.events.textExtracted.addEventListener(event => { | ||
acrolinxExtractedTextField.value = event.text; | ||
acrolinxExtractedTextField.form!.submit(); | ||
} | ||
); | ||
acrolinxExtractedTextField.value = event.text; | ||
acrolinxExtractedTextField.form!.submit(); | ||
}); | ||
} | ||
@@ -188,2 +241,1 @@ | ||
window.addEventListener('DOMContentLoaded', initAcrolinxAppAutoForm); | ||
@@ -36,3 +36,3 @@ /* | ||
public dispatchEvent(event: T) { | ||
this.listener.forEach((listener) => { | ||
this.listener.forEach(listener => { | ||
listener(event); | ||
@@ -42,2 +42,1 @@ }); | ||
} | ||
149
src/index.ts
@@ -17,8 +17,10 @@ /* | ||
import {InternalEventEmitter, TypedEventEmitter} from './event-emitter'; | ||
import { InternalEventEmitter, TypedEventEmitter } from './event-emitter'; | ||
import { | ||
AnalysisResultEvent, AppApiCapability, | ||
AnalysisResultEvent, | ||
AppApiCapability, | ||
AppButtonConfig, | ||
configureAddon, | ||
OffsetRange, openWindow, | ||
OffsetRange, | ||
openWindow, | ||
replaceRanges, | ||
@@ -29,10 +31,15 @@ ReportType, | ||
} from './raw'; | ||
import {includes, isOverlapping} from './utils'; | ||
import { includes, isOverlapping } from './utils'; | ||
export {OffsetRange}; | ||
export { OffsetRange }; | ||
// tslint:disable-next-line:max-line-length | ||
export const DEVELOPMENT_APP_SIGNATURE = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg'; | ||
/** | ||
* @public | ||
*/ | ||
export const DEVELOPMENT_APP_SIGNATURE = | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg'; | ||
/** | ||
* @public | ||
*/ | ||
export interface ExtractedTextEvent { | ||
@@ -43,2 +50,5 @@ languageId: string; | ||
/** | ||
* @public | ||
*/ | ||
export interface ExtractedTextLinkEvent { | ||
@@ -49,2 +59,5 @@ languageId: string; | ||
/** | ||
* @public | ||
*/ | ||
export interface TextRangesExpiredEvent { | ||
@@ -54,2 +67,5 @@ ranges: OffsetRange[]; | ||
/** | ||
* @public | ||
*/ | ||
export enum ApiCommands { | ||
@@ -61,2 +77,5 @@ selectRanges = 'selectRanges', | ||
/** | ||
* @public | ||
*/ | ||
export enum ApiEvents { | ||
@@ -68,3 +87,2 @@ textExtracted = 'textExtracted', | ||
const DEFAULT_CONFIG: SidebarAddonConfig = { | ||
@@ -74,9 +92,9 @@ appSignature: DEVELOPMENT_APP_SIGNATURE, | ||
requiredReportContent: [], | ||
requiredReportLinks: [], | ||
requiredReportLinks: [] | ||
}; | ||
class AppApiConnection<C extends keyof AppCommands = keyof AppCommands, | ||
E extends keyof AppEvents = keyof AppEvents> | ||
implements AcrolinxAppApi<C, E> { | ||
class AppApiConnection< | ||
C extends keyof AppCommands = keyof AppCommands, | ||
E extends keyof AppEvents = keyof AppEvents | ||
> implements AcrolinxAppApi<C, E> { | ||
private readonly _events = { | ||
@@ -114,42 +132,55 @@ textExtracted: new InternalEventEmitter<ExtractedTextEvent>(), | ||
configureAddon({ | ||
...DEFAULT_CONFIG, ...(config), | ||
requiredReportLinks, requiredReportContent, | ||
...DEFAULT_CONFIG, | ||
...config, | ||
requiredReportLinks, | ||
requiredReportContent, | ||
requires: config.requiredCommands as AppApiCapability[] | ||
}); | ||
window.addEventListener('message', messageEvent => { | ||
console.log('Got message from sidebar', messageEvent.data.type, messageEvent); | ||
window.addEventListener( | ||
'message', | ||
messageEvent => { | ||
console.log( | ||
'Got message from sidebar', | ||
messageEvent.data.type, | ||
messageEvent | ||
); | ||
const eventForApp = messageEvent.data; | ||
const eventForApp = messageEvent.data; | ||
if (!eventForApp) { | ||
return; | ||
} | ||
if (!eventForApp) { | ||
return; | ||
} | ||
if (eventForApp.type === 'analysisResult') { | ||
const analysisResult: AnalysisResultEvent = eventForApp; | ||
const reports = analysisResult.reports; | ||
const textExtractedReport = reports[ReportType.extractedText] || {}; | ||
if (eventForApp.type === 'analysisResult') { | ||
const analysisResult: AnalysisResultEvent = eventForApp; | ||
const reports = analysisResult.reports; | ||
const textExtractedReport = reports[ReportType.extractedText] || {}; | ||
if (textExtractedReport.url) { | ||
this._events.textExtractedLink.dispatchEvent({ | ||
url: textExtractedReport.url, | ||
languageId: analysisResult.languageId | ||
}); | ||
} | ||
if (textExtractedReport.url) { | ||
this._events.textExtractedLink.dispatchEvent({ | ||
url: textExtractedReport.url, | ||
languageId: analysisResult.languageId | ||
}); | ||
} | ||
if (typeof textExtractedReport.content === 'string') { | ||
this._events.textExtracted.dispatchEvent({ | ||
text: textExtractedReport.content, | ||
languageId: analysisResult.languageId | ||
}); | ||
if (typeof textExtractedReport.content === 'string') { | ||
this._events.textExtracted.dispatchEvent({ | ||
text: textExtractedReport.content, | ||
languageId: analysisResult.languageId | ||
}); | ||
} | ||
} else if (eventForApp.type === 'invalidRanges') { | ||
this._events.invalidRanges.dispatchEvent(eventForApp); | ||
} | ||
} else if (eventForApp.type === 'invalidRanges') { | ||
this._events.invalidRanges.dispatchEvent(eventForApp); | ||
} | ||
}, false); | ||
}, | ||
false | ||
); | ||
} | ||
} | ||
interface AppEvents { | ||
/** | ||
* @public | ||
*/ | ||
export interface AppEvents { | ||
textExtracted: TypedEventEmitter<ExtractedTextEvent>; | ||
@@ -160,3 +191,6 @@ textExtractedLink: TypedEventEmitter<ExtractedTextLinkEvent>; | ||
interface AppCommands { | ||
/** | ||
* @public | ||
*/ | ||
export interface AppCommands { | ||
selectRanges: typeof selectRanges; | ||
@@ -167,3 +201,9 @@ replaceRanges: typeof replaceRanges; | ||
export interface AcrolinxAppApi<C extends keyof AppCommands, E extends keyof AppEvents> { | ||
/** | ||
* @public | ||
*/ | ||
export interface AcrolinxAppApi< | ||
C extends keyof AppCommands, | ||
E extends keyof AppEvents | ||
> { | ||
events: Pick<AppEvents, E>; | ||
@@ -173,3 +213,9 @@ commands: Pick<AppCommands, C>; | ||
export interface ApiConfig<C extends keyof AppCommands, E extends keyof AppEvents> { | ||
/** | ||
* @public | ||
*/ | ||
export interface ApiConfig< | ||
C extends keyof AppCommands, | ||
E extends keyof AppEvents | ||
> { | ||
title?: string; | ||
@@ -182,4 +228,7 @@ appSignature?: string; | ||
/** | ||
* @public | ||
*/ | ||
export function initApi<C extends keyof AppCommands, E extends keyof AppEvents>( | ||
conf: ApiConfig<C, E>, | ||
conf: ApiConfig<C, E> | ||
): AcrolinxAppApi<C, E> { | ||
@@ -189,4 +238,10 @@ return new AppApiConnection(conf); | ||
export function isInvalid(event: TextRangesExpiredEvent, range: OffsetRange): boolean { | ||
/** | ||
* @public | ||
*/ | ||
export function isInvalid( | ||
event: TextRangesExpiredEvent, | ||
range: OffsetRange | ||
): boolean { | ||
return event.ranges.some(inValidRange => isOverlapping(inValidRange, range)); | ||
} |
@@ -62,3 +62,5 @@ /* | ||
/** | ||
* @public | ||
*/ | ||
export interface OffsetRange { | ||
@@ -81,3 +83,6 @@ begin: number; | ||
if (hasParentWindow()) { | ||
window.parent.postMessage({command: 'acrolinx.sidebar.openWindow', url}, '*'); | ||
window.parent.postMessage( | ||
{ command: 'acrolinx.sidebar.openWindow', url }, | ||
'*' | ||
); | ||
} else { | ||
@@ -89,11 +94,11 @@ window.open(url); | ||
export function selectRanges(ranges: OffsetRange[]) { | ||
postMessageToSidebar({command: 'acrolinx.sidebar.selectRanges', ranges}); | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.selectRanges', ranges }); | ||
} | ||
export function replaceRanges(ranges: OffsetRangeWithReplacement[]) { | ||
postMessageToSidebar({command: 'acrolinx.sidebar.replaceRanges', ranges}); | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.replaceRanges', ranges }); | ||
} | ||
export function configureAddon(config: SidebarAddonConfig) { | ||
postMessageToSidebar({command: 'acrolinx.sidebar.configureAddon', config}); | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.configureAddon', config }); | ||
} | ||
@@ -100,0 +105,0 @@ |
@@ -17,4 +17,5 @@ /* | ||
import {OffsetRange} from './raw'; | ||
import { OffsetRange } from './raw'; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function includes<T>(array: T[] | undefined, element: any): boolean { | ||
@@ -27,5 +28,9 @@ if (!array) { | ||
export function isOverlapping(range1: OffsetRange, range2: OffsetRange): boolean { | ||
const isNotOverlapping = (range2.begin >= range1.end || range2.end <= range1.begin); | ||
export function isOverlapping( | ||
range1: OffsetRange, | ||
range2: OffsetRange | ||
): boolean { | ||
const isNotOverlapping = | ||
range2.begin >= range1.end || range2.end <= range1.begin; | ||
return !isNotOverlapping; | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85369
30
1267
17