@acrolinx/app-sdk
Advanced tools
Comparing version 0.0.15 to 0.1.1
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; | ||
},{}],"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; | ||
"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 r(e){p({command:"acrolinx.sidebar.selectRanges",ranges:e})}function s(e){p({command:"acrolinx.sidebar.replaceRanges",ranges:e})}function a(e){p({command:"acrolinx.sidebar.configureAddon",config:e})}function i(){p({command:"acrolinx.sidebar.requestAppAccessToken"})}function p(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=r,exports.replaceRanges=s,exports.configureAddon=a,exports.getAppAccessToken=i; | ||
},{}],"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; | ||
"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)}function t(e,n){throw new Error("Can't handle "+n+" with value "+JSON.stringify(e))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.includes=e,exports.isOverlapping=n,exports.exhaustiveSwitchCheck=t; | ||
},{}],"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; | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.AppAccessTokenEvent=n.AppAccessTokenEvent,exports.HttpGetRequest=n.HttpGetRequest,exports.OffsetRange=n.OffsetRange,exports.OffsetRangeWithReplacement=n.OffsetRangeWithReplacement;var s,r,i=require("./utils");exports.DEVELOPMENT_APP_SIGNATURE="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg",function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges",e.openWindow="openWindow",e.getAppAccessToken="getAppAccessToken"}(s=exports.RequiredCommands||(exports.RequiredCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges"}(r=exports.RequiredEvents||(exports.RequiredEvents={}));var a={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function s(s){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter},this.waitingAppAccessTokenResolvers=[],this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow,getAppAccessToken:function(){return o.getAppAccessToken()}};var p=[];i.includes(s.requiredEvents,r.textExtractedLink)&&p.push(n.ReportType.extractedText);var c=[];i.includes(s.requiredEvents,r.textExtracted)&&c.push(n.ReportType.extractedText),n.configureAddon(e(e(e({},a),s),{requiredReportLinks:p,requiredReportContent:c,requires:s.requiredCommands})),window.addEventListener("message",function(e){console.log("Got message from sidebar",e.data.type,e);var t=e.data;if(t)switch(t.type){case"analysisResult":o.handleAnalysisResultEvent(t);break;case"invalidRanges":o._events.invalidRanges.dispatchEvent(t);break;case"appAccessToken":o.waitingAppAccessTokenResolvers.forEach(function(e){e(t)}),o.waitingAppAccessTokenResolvers=[];break;default:i.exhaustiveSwitchCheck(t,"AppApiEvent")}},!1)}return Object.defineProperty(s.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),s.prototype.handleAnalysisResultEvent=function(e){var t=e.reports[n.ReportType.extractedText]||{};t.url&&this._events.textExtractedLink.dispatchEvent({url:t.url,languageId:e.languageId}),"string"==typeof t.content&&this._events.textExtracted.dispatchEvent({text:t.content,languageId:e.languageId})},s.prototype.getAppAccessToken=function(){var e=this,t=new Promise(function(t,n){e.waitingAppAccessTokenResolvers.push(t)});return n.getAppAccessToken(),t},s}();function p(e){return new o(e)}function c(e,t){return e.ranges.some(function(e){return i.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=c; | ||
},{"./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); | ||
"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 u(e,t){return d(e,function(e){return void 0!==e.dataset[t]})}function d(e,t){for(var n=e;n&&n!==document.body;){if(t(n))return n;n=n.parentElement}}function s(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 u=c.value,d=JSON.parse(u.dataset.acrolinxSelectRange);a.isInvalid(e,d)&&(u.classList.add(v),n&&(u.title=n))}}catch(s){r={error:s}}finally{try{c&&!c.done&&(i=l.return)&&i.call(l)}finally{if(r)throw r.error}}})}function m(e){var t=u(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&&(s("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=u(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"]'),u=(l("acrolinx-app-required-commands")||"").split(/, */),d=(l("acrolinx-app-required-events")||"").split(/, *?/),s=a.initApi({title:t||window.location.href,button:{text:l("acrolinx-app-button-text")||"Check",tooltip:l("acrolinx-app-button-tooltip")||""},requiredCommands:u,requiredEvents:f(r([n&&a.RequiredEvents.textExtracted],d))});n&&s.events.textExtracted.addEventListener(function(e){n.value=e.text,n.form.submit()}),o.includes(d,a.RequiredEvents.invalidRanges)&&p(s),o.includes(u,a.RequiredCommands.selectRanges)&&x(s),o.includes(u,a.RequiredCommands.replaceRanges)&&y(s)}window.addEventListener("DOMContentLoaded",g); | ||
},{"./index":"QCba","./raw":"eMvI","./utils":"UnXq"}]},{},["M10p"], null) | ||
//# sourceMappingURL=/acrolinx-app-sdk-auto-form.min.js.map |
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; | ||
},{}],"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; | ||
"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 r(e){p({command:"acrolinx.sidebar.selectRanges",ranges:e})}function s(e){p({command:"acrolinx.sidebar.replaceRanges",ranges:e})}function a(e){p({command:"acrolinx.sidebar.configureAddon",config:e})}function i(){p({command:"acrolinx.sidebar.requestAppAccessToken"})}function p(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=r,exports.replaceRanges=s,exports.configureAddon=a,exports.getAppAccessToken=i; | ||
},{}],"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; | ||
"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)}function t(e,n){throw new Error("Can't handle "+n+" with value "+JSON.stringify(e))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.includes=e,exports.isOverlapping=n,exports.exhaustiveSwitchCheck=t; | ||
},{}],"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; | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.AppAccessTokenEvent=n.AppAccessTokenEvent,exports.HttpGetRequest=n.HttpGetRequest,exports.OffsetRange=n.OffsetRange,exports.OffsetRangeWithReplacement=n.OffsetRangeWithReplacement;var s,r,i=require("./utils");exports.DEVELOPMENT_APP_SIGNATURE="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS2lsbGVyIEFwcCIsImlkIjoiNGVlZDM3NjctMGYzMS00ZDVmLWI2MjktYzg2MWFiM2VkODUyIiwidHlwZSI6IkFQUCIsImlhdCI6MTU2MTE4ODI5M30.zlVJuGITMjAJ2p4nl-qtpj4N0p_8e4tenr-4dkrGdXg",function(e){e.selectRanges="selectRanges",e.replaceRanges="replaceRanges",e.openWindow="openWindow",e.getAppAccessToken="getAppAccessToken"}(s=exports.RequiredCommands||(exports.RequiredCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges"}(r=exports.RequiredEvents||(exports.RequiredEvents={}));var a={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function s(s){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter},this.waitingAppAccessTokenResolvers=[],this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow,getAppAccessToken:function(){return o.getAppAccessToken()}};var p=[];i.includes(s.requiredEvents,r.textExtractedLink)&&p.push(n.ReportType.extractedText);var c=[];i.includes(s.requiredEvents,r.textExtracted)&&c.push(n.ReportType.extractedText),n.configureAddon(e(e(e({},a),s),{requiredReportLinks:p,requiredReportContent:c,requires:s.requiredCommands})),window.addEventListener("message",function(e){console.log("Got message from sidebar",e.data.type,e);var t=e.data;if(t)switch(t.type){case"analysisResult":o.handleAnalysisResultEvent(t);break;case"invalidRanges":o._events.invalidRanges.dispatchEvent(t);break;case"appAccessToken":o.waitingAppAccessTokenResolvers.forEach(function(e){e(t)}),o.waitingAppAccessTokenResolvers=[];break;default:i.exhaustiveSwitchCheck(t,"AppApiEvent")}},!1)}return Object.defineProperty(s.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),s.prototype.handleAnalysisResultEvent=function(e){var t=e.reports[n.ReportType.extractedText]||{};t.url&&this._events.textExtractedLink.dispatchEvent({url:t.url,languageId:e.languageId}),"string"==typeof t.content&&this._events.textExtracted.dispatchEvent({text:t.content,languageId:e.languageId})},s.prototype.getAppAccessToken=function(){var e=this,t=new Promise(function(t,n){e.waitingAppAccessTokenResolvers.push(t)});return n.getAppAccessToken(),t},s}();function p(e){return new o(e)}function c(e,t){return e.ranges.some(function(e){return i.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=c; | ||
},{"./event-emitter":"QmUd","./raw":"eMvI","./utils":"UnXq"}]},{},["QCba"], "acrolinxAppSdk") | ||
//# sourceMappingURL=/acrolinx-app-sdk.min.js.map |
@@ -0,2 +1,21 @@ | ||
/** | ||
* Copyright 2019-present Acrolinx GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, softwareq | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @hidden | ||
* @ignore | ||
* @internal | ||
*/ | ||
export {}; | ||
//# sourceMappingURL=auto-form.d.ts.map |
"use strict"; | ||
/* | ||
/** | ||
* Copyright 2019-present Acrolinx GmbH | ||
@@ -16,2 +16,6 @@ * | ||
* limitations under the License. | ||
* | ||
* @hidden | ||
* @ignore | ||
* @internal | ||
*/ | ||
@@ -63,2 +67,6 @@ var __assign = (this && this.__assign) || function () { | ||
* This module is highly experimental. | ||
* @packageDocumentation | ||
* @hidden | ||
* @ignore | ||
* @internal | ||
*/ | ||
@@ -204,3 +212,3 @@ var index_1 = require("./index"); | ||
requiredEvents: compact(__spread([ | ||
acrolinxExtractedTextField && index_1.ApiEvents.textExtracted | ||
acrolinxExtractedTextField && index_1.RequiredEvents.textExtracted | ||
], requiredEvents)) | ||
@@ -214,9 +222,9 @@ }); | ||
} | ||
if (utils_1.includes(requiredEvents, index_1.ApiEvents.invalidRanges)) { | ||
if (utils_1.includes(requiredEvents, index_1.RequiredEvents.invalidRanges)) { | ||
addInvalidRangesListener(appApi); | ||
} | ||
if (utils_1.includes(requiredCommands, index_1.ApiCommands.selectRanges)) { | ||
if (utils_1.includes(requiredCommands, index_1.RequiredCommands.selectRanges)) { | ||
addClickSelectRangeListener(appApi); | ||
} | ||
if (utils_1.includes(requiredCommands, index_1.ApiCommands.replaceRanges)) { | ||
if (utils_1.includes(requiredCommands, index_1.RequiredCommands.replaceRanges)) { | ||
addClickReplaceRangeListener(appApi); | ||
@@ -223,0 +231,0 @@ } |
import { TypedEventEmitter } from './event-emitter'; | ||
import { AppButtonConfig, OffsetRange, openWindow, replaceRanges, selectRanges } from './raw'; | ||
export { OffsetRange }; | ||
import { AppAccessTokenEvent, AppButtonConfig, HttpGetRequest, OffsetRange, OffsetRangeWithReplacement } from './raw'; | ||
export { OffsetRange, OffsetRangeWithReplacement, AppAccessTokenEvent, HttpGetRequest }; | ||
/** | ||
@@ -31,6 +31,14 @@ * @public | ||
*/ | ||
export declare enum ApiCommands { | ||
export interface AppAccessTokenResult { | ||
validationRequest: HttpGetRequest; | ||
appAccessToken: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum RequiredCommands { | ||
selectRanges = "selectRanges", | ||
replaceRanges = "replaceRanges", | ||
openWindow = "openWindow" | ||
openWindow = "openWindow", | ||
getAppAccessToken = "getAppAccessToken" | ||
} | ||
@@ -40,3 +48,3 @@ /** | ||
*/ | ||
export declare enum ApiEvents { | ||
export declare enum RequiredEvents { | ||
textExtracted = "textExtracted", | ||
@@ -58,5 +66,6 @@ textExtractedLink = "textExtractedLink", | ||
export interface AppCommands { | ||
selectRanges: typeof selectRanges; | ||
replaceRanges: typeof replaceRanges; | ||
openWindow: typeof openWindow; | ||
selectRanges(ranges: OffsetRange[]): void; | ||
replaceRanges(ranges: OffsetRangeWithReplacement[]): void; | ||
openWindow(url: string): void; | ||
getAppAccessToken(): Promise<AppAccessTokenResult>; | ||
} | ||
@@ -66,5 +75,5 @@ /** | ||
*/ | ||
export interface AcrolinxAppApi<C extends keyof AppCommands, E extends keyof AppEvents> { | ||
events: Pick<AppEvents, E>; | ||
commands: Pick<AppCommands, C>; | ||
export interface AcrolinxAppApi { | ||
events: AppEvents; | ||
commands: AppCommands; | ||
} | ||
@@ -74,3 +83,3 @@ /** | ||
*/ | ||
export interface ApiConfig<C extends keyof AppCommands, E extends keyof AppEvents> { | ||
export interface ApiConfig { | ||
title?: string; | ||
@@ -80,4 +89,4 @@ version?: string; | ||
button?: AppButtonConfig; | ||
requiredEvents: E[]; | ||
requiredCommands: C[]; | ||
requiredEvents: RequiredEvents[]; | ||
requiredCommands: RequiredCommands[]; | ||
} | ||
@@ -87,3 +96,3 @@ /** | ||
*/ | ||
export declare function initApi<C extends keyof AppCommands, E extends keyof AppEvents>(conf: ApiConfig<C, E>): AcrolinxAppApi<C, E>; | ||
export declare function initApi(conf: ApiConfig): AcrolinxAppApi; | ||
/** | ||
@@ -90,0 +99,0 @@ * @public |
@@ -39,17 +39,21 @@ "use strict"; | ||
*/ | ||
var ApiCommands; | ||
(function (ApiCommands) { | ||
ApiCommands["selectRanges"] = "selectRanges"; | ||
ApiCommands["replaceRanges"] = "replaceRanges"; | ||
ApiCommands["openWindow"] = "openWindow"; | ||
})(ApiCommands = exports.ApiCommands || (exports.ApiCommands = {})); | ||
var RequiredCommands; | ||
(function (RequiredCommands) { | ||
RequiredCommands["selectRanges"] = "selectRanges"; | ||
RequiredCommands["replaceRanges"] = "replaceRanges"; | ||
RequiredCommands["openWindow"] = "openWindow"; | ||
RequiredCommands["getAppAccessToken"] = "getAppAccessToken"; | ||
})(RequiredCommands = exports.RequiredCommands || (exports.RequiredCommands = {})); | ||
/** | ||
* @public | ||
*/ | ||
var ApiEvents; | ||
(function (ApiEvents) { | ||
ApiEvents["textExtracted"] = "textExtracted"; | ||
ApiEvents["textExtractedLink"] = "textExtractedLink"; | ||
ApiEvents["invalidRanges"] = "invalidRanges"; | ||
})(ApiEvents = exports.ApiEvents || (exports.ApiEvents = {})); | ||
var RequiredEvents; | ||
(function (RequiredEvents) { | ||
RequiredEvents["textExtracted"] = "textExtracted"; | ||
RequiredEvents["textExtractedLink"] = "textExtractedLink"; | ||
RequiredEvents["invalidRanges"] = "invalidRanges"; | ||
})(RequiredEvents = exports.RequiredEvents || (exports.RequiredEvents = {})); | ||
/** | ||
* @internal | ||
*/ | ||
var DEFAULT_CONFIG = { | ||
@@ -61,2 +65,5 @@ appSignature: exports.DEVELOPMENT_APP_SIGNATURE, | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
var AppApiConnection = /** @class */ (function () { | ||
@@ -70,13 +77,15 @@ function AppApiConnection(config) { | ||
}; | ||
this.waitingAppAccessTokenResolvers = []; | ||
this._commands = { | ||
selectRanges: raw_1.selectRanges, | ||
replaceRanges: raw_1.replaceRanges, | ||
openWindow: raw_1.openWindow | ||
openWindow: raw_1.openWindow, | ||
getAppAccessToken: function () { return _this.getAppAccessToken(); } | ||
}; | ||
var requiredReportLinks = []; | ||
if (utils_1.includes(config.requiredEvents, ApiEvents.textExtractedLink)) { | ||
if (utils_1.includes(config.requiredEvents, RequiredEvents.textExtractedLink)) { | ||
requiredReportLinks.push(raw_1.ReportType.extractedText); | ||
} | ||
var requiredReportContent = []; | ||
if (utils_1.includes(config.requiredEvents, ApiEvents.textExtracted)) { | ||
if (utils_1.includes(config.requiredEvents, RequiredEvents.textExtracted)) { | ||
requiredReportContent.push(raw_1.ReportType.extractedText); | ||
@@ -92,22 +101,18 @@ } | ||
} | ||
if (eventForApp.type === 'analysisResult') { | ||
var analysisResult = eventForApp; | ||
var reports = analysisResult.reports; | ||
var textExtractedReport = reports[raw_1.ReportType.extractedText] || {}; | ||
if (textExtractedReport.url) { | ||
_this._events.textExtractedLink.dispatchEvent({ | ||
url: textExtractedReport.url, | ||
languageId: analysisResult.languageId | ||
switch (eventForApp.type) { | ||
case 'analysisResult': | ||
_this.handleAnalysisResultEvent(eventForApp); | ||
break; | ||
case 'invalidRanges': | ||
_this._events.invalidRanges.dispatchEvent(eventForApp); | ||
break; | ||
case 'appAccessToken': | ||
_this.waitingAppAccessTokenResolvers.forEach(function (resolve) { | ||
resolve(eventForApp); | ||
}); | ||
} | ||
if (typeof textExtractedReport.content === 'string') { | ||
_this._events.textExtracted.dispatchEvent({ | ||
text: textExtractedReport.content, | ||
languageId: analysisResult.languageId | ||
}); | ||
} | ||
_this.waitingAppAccessTokenResolvers = []; | ||
break; | ||
default: | ||
utils_1.exhaustiveSwitchCheck(eventForApp, 'AppApiEvent'); | ||
} | ||
else if (eventForApp.type === 'invalidRanges') { | ||
_this._events.invalidRanges.dispatchEvent(eventForApp); | ||
} | ||
}, false); | ||
@@ -129,2 +134,26 @@ } | ||
}); | ||
AppApiConnection.prototype.handleAnalysisResultEvent = function (analysisResult) { | ||
var reports = analysisResult.reports; | ||
var textExtractedReport = reports[raw_1.ReportType.extractedText] || {}; | ||
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 | ||
}); | ||
} | ||
}; | ||
AppApiConnection.prototype.getAppAccessToken = function () { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, _reject) { | ||
_this.waitingAppAccessTokenResolvers.push(resolve); | ||
}); | ||
raw_1.getAppAccessToken(); | ||
return promise; | ||
}; | ||
return AppApiConnection; | ||
@@ -131,0 +160,0 @@ }()); |
@@ -37,6 +37,23 @@ export interface AppButtonConfig { | ||
} | ||
export declare type EventForApp = AnalysisResultEvent | InvalidateRangesEvent; | ||
/** | ||
* @internal | ||
*/ | ||
export interface AppAccessTokenEvent { | ||
type: 'appAccessToken'; | ||
validationRequest: HttpGetRequest; | ||
appAccessToken: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface HttpGetRequest { | ||
url: string; | ||
headers: { | ||
[key: string]: string; | ||
}; | ||
} | ||
export declare type EventForApp = AnalysisResultEvent | InvalidateRangesEvent | AppAccessTokenEvent; | ||
/** | ||
* @public | ||
*/ | ||
export interface OffsetRange { | ||
@@ -46,2 +63,5 @@ begin: number; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export interface OffsetRangeWithReplacement { | ||
@@ -57,3 +77,4 @@ replacement: string; | ||
export declare function configureAddon(config: SidebarAddonConfig): void; | ||
export declare function getAppAccessToken(): void; | ||
export {}; | ||
//# sourceMappingURL=raw.d.ts.map |
@@ -52,2 +52,6 @@ "use strict"; | ||
exports.configureAddon = configureAddon; | ||
function getAppAccessToken() { | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.requestAppAccessToken' }); | ||
} | ||
exports.getAppAccessToken = getAppAccessToken; | ||
function postMessageToSidebar(message) { | ||
@@ -54,0 +58,0 @@ if (hasParentWindow()) { |
@@ -0,4 +1,25 @@ | ||
/** | ||
* Copyright 2019-present Acrolinx GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, softwareq | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { OffsetRange } from './raw'; | ||
/** | ||
* @packageDocumentation | ||
* @internal | ||
*/ | ||
export declare function includes<T>(array: T[] | undefined, element: any): boolean; | ||
export declare function isOverlapping(range1: OffsetRange, range2: OffsetRange): boolean; | ||
export declare function exhaustiveSwitchCheck(param: never, name: string): never; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
/* | ||
/** | ||
* Copyright 2019-present Acrolinx GmbH | ||
@@ -16,4 +16,9 @@ * | ||
* limitations under the License. | ||
* | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @packageDocumentation | ||
* @internal | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -32,2 +37,6 @@ function includes(array, element) { | ||
exports.isOverlapping = isOverlapping; | ||
function exhaustiveSwitchCheck(param, name) { | ||
throw new Error("Can't handle " + name + " with value " + JSON.stringify(param)); | ||
} | ||
exports.exhaustiveSwitchCheck = exhaustiveSwitchCheck; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@acrolinx/app-sdk", | ||
"version": "0.0.15", | ||
"version": "0.1.1", | ||
"description": "Acrolinx App SDK", | ||
@@ -56,3 +56,3 @@ "license": "Apache-2.0", | ||
"ts-jest": "^24.3.0", | ||
"typedoc": "^0.15.6", | ||
"typedoc": "^0.16.9", | ||
"typescript": "^3.7.4" | ||
@@ -59,0 +59,0 @@ }, |
@@ -5,3 +5,3 @@ # Acrolinx App SDK | ||
## Installation | ||
## Installation | ||
```bash | ||
@@ -16,3 +16,3 @@ npm install @acrolinx/app-sdk | ||
```javascript | ||
import {ApiCommands, ApiEvents, DEVELOPMENT_APP_SIGNATURE, initApi} from '@acrolinx/app-sdk'; | ||
import {RequiredCommands, RequiredEvents, DEVELOPMENT_APP_SIGNATURE, initApi} from '@acrolinx/app-sdk'; | ||
@@ -27,4 +27,4 @@ // Initialize the Acrolinx App API | ||
}, | ||
requiredCommands: [ApiCommands.openWindow], | ||
requiredEvents: [ApiEvents.textExtracted], | ||
requiredCommands: [RequiredCommands.openWindow], | ||
requiredEvents: [RequiredEvents.textExtracted], | ||
}); | ||
@@ -42,3 +42,3 @@ | ||
### Plain old JavaScript | ||
If you prefer to code in plain old JavaScript without npm and without a bundler, | ||
If you prefer to code in plain old JavaScript without npm and without a bundler, | ||
you can use the [minified browser bundle](https://unpkg.com/@acrolinx/app-sdk/dist/acrolinx-app-sdk.min.js). | ||
@@ -50,3 +50,3 @@ In this case you can find the SDK in the global namespace *acrolinxAppSdk*. | ||
<script> | ||
var api = acrolinxAppSdk.initApi({.... | ||
var api = acrolinxAppSdk.initApi({.... | ||
</script> | ||
@@ -53,0 +53,0 @@ ``` |
@@ -1,2 +0,2 @@ | ||
/* | ||
/** | ||
* Copyright 2019-present Acrolinx GmbH | ||
@@ -15,2 +15,6 @@ * | ||
* limitations under the License. | ||
* | ||
* @hidden | ||
* @ignore | ||
* @internal | ||
*/ | ||
@@ -20,2 +24,6 @@ | ||
* This module is highly experimental. | ||
* @packageDocumentation | ||
* @hidden | ||
* @ignore | ||
* @internal | ||
*/ | ||
@@ -25,4 +33,4 @@ | ||
AcrolinxAppApi, | ||
ApiCommands, | ||
ApiEvents, | ||
RequiredCommands, | ||
RequiredEvents, | ||
initApi, | ||
@@ -87,5 +95,3 @@ isInvalid, | ||
function addInvalidRangesListener( | ||
appApi: AcrolinxAppApi<ApiCommands, ApiEvents> | ||
) { | ||
function addInvalidRangesListener(appApi: AcrolinxAppApi) { | ||
const invalidRangeTooltip = getMetaValue( | ||
@@ -135,5 +141,3 @@ 'acrolinx-app-invalid-range-tooltip' | ||
function addClickSelectRangeListener( | ||
appApi: AcrolinxAppApi<ApiCommands, ApiEvents> | ||
) { | ||
function addClickSelectRangeListener(appApi: AcrolinxAppApi) { | ||
document.addEventListener('click', ev => { | ||
@@ -154,5 +158,3 @@ const elementWithRange = findAncestorWithValidSelectRange( | ||
function addClickReplaceRangeListener( | ||
appApi: AcrolinxAppApi<ApiCommands, ApiEvents> | ||
) { | ||
function addClickReplaceRangeListener(appApi: AcrolinxAppApi) { | ||
document.addEventListener('click', ev => { | ||
@@ -206,6 +208,6 @@ const elementWithReplaceRange = findAncestorWithData( | ||
}, | ||
requiredCommands: requiredCommands as ApiCommands[], | ||
requiredCommands: requiredCommands as RequiredCommands[], | ||
requiredEvents: compact([ | ||
acrolinxExtractedTextField && ApiEvents.textExtracted, | ||
...(requiredEvents as ApiEvents[]) | ||
acrolinxExtractedTextField && RequiredEvents.textExtracted, | ||
...(requiredEvents as RequiredEvents[]) | ||
]) | ||
@@ -221,11 +223,11 @@ }); | ||
if (includes(requiredEvents, ApiEvents.invalidRanges)) { | ||
if (includes(requiredEvents, RequiredEvents.invalidRanges)) { | ||
addInvalidRangesListener(appApi); | ||
} | ||
if (includes(requiredCommands, ApiCommands.selectRanges)) { | ||
if (includes(requiredCommands, RequiredCommands.selectRanges)) { | ||
addClickSelectRangeListener(appApi); | ||
} | ||
if (includes(requiredCommands, ApiCommands.replaceRanges)) { | ||
if (includes(requiredCommands, RequiredCommands.replaceRanges)) { | ||
addClickReplaceRangeListener(appApi); | ||
@@ -232,0 +234,0 @@ } |
150
src/index.ts
@@ -20,6 +20,11 @@ /* | ||
AnalysisResultEvent, | ||
AppAccessTokenEvent, | ||
AppApiCapability, | ||
AppButtonConfig, | ||
configureAddon, | ||
EventForApp, | ||
getAppAccessToken, | ||
HttpGetRequest, | ||
OffsetRange, | ||
OffsetRangeWithReplacement, | ||
openWindow, | ||
@@ -31,5 +36,10 @@ replaceRanges, | ||
} from './raw'; | ||
import { includes, isOverlapping } from './utils'; | ||
import { exhaustiveSwitchCheck, includes, isOverlapping } from './utils'; | ||
export { OffsetRange }; | ||
export { | ||
OffsetRange, | ||
OffsetRangeWithReplacement, | ||
AppAccessTokenEvent, | ||
HttpGetRequest | ||
}; | ||
@@ -68,6 +78,15 @@ /** | ||
*/ | ||
export enum ApiCommands { | ||
export interface AppAccessTokenResult { | ||
validationRequest: HttpGetRequest; | ||
appAccessToken: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export enum RequiredCommands { | ||
selectRanges = 'selectRanges', | ||
replaceRanges = 'replaceRanges', | ||
openWindow = 'openWindow' | ||
openWindow = 'openWindow', | ||
getAppAccessToken = 'getAppAccessToken' | ||
} | ||
@@ -78,3 +97,3 @@ | ||
*/ | ||
export enum ApiEvents { | ||
export enum RequiredEvents { | ||
textExtracted = 'textExtracted', | ||
@@ -85,2 +104,5 @@ textExtractedLink = 'textExtractedLink', | ||
/** | ||
* @internal | ||
*/ | ||
const DEFAULT_CONFIG: SidebarAddonConfig = { | ||
@@ -93,6 +115,6 @@ appSignature: DEVELOPMENT_APP_SIGNATURE, | ||
class AppApiConnection< | ||
C extends keyof AppCommands = keyof AppCommands, | ||
E extends keyof AppEvents = keyof AppEvents | ||
> implements AcrolinxAppApi<C, E> { | ||
/** | ||
* @internal | ||
*/ | ||
class AppApiConnection { | ||
private readonly _events = { | ||
@@ -104,19 +126,24 @@ textExtracted: new InternalEventEmitter<ExtractedTextEvent>(), | ||
private waitingAppAccessTokenResolvers: Array< | ||
(token: AppAccessTokenResult) => void | ||
> = []; | ||
private readonly _commands: AppCommands = { | ||
selectRanges, | ||
replaceRanges, | ||
openWindow | ||
openWindow, | ||
getAppAccessToken: () => this.getAppAccessToken() | ||
}; | ||
get events(): Pick<AppEvents, E> { | ||
get events(): AppEvents { | ||
return this._events; | ||
} | ||
get commands(): Pick<AppCommands, C> { | ||
get commands(): AppCommands { | ||
return this._commands; | ||
} | ||
constructor(config: ApiConfig<C, E>) { | ||
constructor(config: ApiConfig) { | ||
const requiredReportLinks = []; | ||
if (includes(config.requiredEvents, ApiEvents.textExtractedLink)) { | ||
if (includes(config.requiredEvents, RequiredEvents.textExtractedLink)) { | ||
requiredReportLinks.push(ReportType.extractedText); | ||
@@ -126,3 +153,3 @@ } | ||
const requiredReportContent = []; | ||
if (includes(config.requiredEvents, ApiEvents.textExtracted)) { | ||
if (includes(config.requiredEvents, RequiredEvents.textExtracted)) { | ||
requiredReportContent.push(ReportType.extractedText); | ||
@@ -136,3 +163,3 @@ } | ||
requiredReportContent, | ||
requires: config.requiredCommands as AppApiCapability[] | ||
requires: (config.requiredCommands as unknown) as AppApiCapability[] | ||
}); | ||
@@ -149,3 +176,3 @@ | ||
const eventForApp = messageEvent.data; | ||
const eventForApp: EventForApp | undefined = messageEvent.data; | ||
@@ -156,22 +183,17 @@ if (!eventForApp) { | ||
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 | ||
switch (eventForApp.type) { | ||
case 'analysisResult': | ||
this.handleAnalysisResultEvent(eventForApp); | ||
break; | ||
case 'invalidRanges': | ||
this._events.invalidRanges.dispatchEvent(eventForApp); | ||
break; | ||
case 'appAccessToken': | ||
this.waitingAppAccessTokenResolvers.forEach(resolve => { | ||
resolve(eventForApp); | ||
}); | ||
} | ||
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); | ||
this.waitingAppAccessTokenResolvers = []; | ||
break; | ||
default: | ||
exhaustiveSwitchCheck(eventForApp, 'AppApiEvent'); | ||
} | ||
@@ -182,2 +204,29 @@ }, | ||
} | ||
private handleAnalysisResultEvent(analysisResult: AnalysisResultEvent) { | ||
const reports = analysisResult.reports; | ||
const textExtractedReport = reports[ReportType.extractedText] || {}; | ||
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 | ||
}); | ||
} | ||
} | ||
private getAppAccessToken(): Promise<AppAccessTokenResult> { | ||
const promise = new Promise<AppAccessTokenResult>((resolve, _reject) => { | ||
this.waitingAppAccessTokenResolvers.push(resolve); | ||
}); | ||
getAppAccessToken(); | ||
return promise; | ||
} | ||
} | ||
@@ -198,5 +247,6 @@ | ||
export interface AppCommands { | ||
selectRanges: typeof selectRanges; | ||
replaceRanges: typeof replaceRanges; | ||
openWindow: typeof openWindow; | ||
selectRanges(ranges: OffsetRange[]): void; | ||
replaceRanges(ranges: OffsetRangeWithReplacement[]): void; | ||
openWindow(url: string): void; | ||
getAppAccessToken(): Promise<AppAccessTokenResult>; | ||
} | ||
@@ -207,8 +257,5 @@ | ||
*/ | ||
export interface AcrolinxAppApi< | ||
C extends keyof AppCommands, | ||
E extends keyof AppEvents | ||
> { | ||
events: Pick<AppEvents, E>; | ||
commands: Pick<AppCommands, C>; | ||
export interface AcrolinxAppApi { | ||
events: AppEvents; | ||
commands: AppCommands; | ||
} | ||
@@ -219,6 +266,3 @@ | ||
*/ | ||
export interface ApiConfig< | ||
C extends keyof AppCommands, | ||
E extends keyof AppEvents | ||
> { | ||
export interface ApiConfig { | ||
title?: string; | ||
@@ -228,4 +272,4 @@ version?: string; | ||
button?: AppButtonConfig; | ||
requiredEvents: E[]; | ||
requiredCommands: C[]; | ||
requiredEvents: RequiredEvents[]; | ||
requiredCommands: RequiredCommands[]; | ||
} | ||
@@ -236,5 +280,3 @@ | ||
*/ | ||
export function initApi<C extends keyof AppCommands, E extends keyof AppEvents>( | ||
conf: ApiConfig<C, E> | ||
): AcrolinxAppApi<C, E> { | ||
export function initApi(conf: ApiConfig): AcrolinxAppApi { | ||
return new AppApiConnection(conf); | ||
@@ -241,0 +283,0 @@ } |
@@ -61,3 +61,10 @@ /* | ||
export type EventForApp = AnalysisResultEvent | InvalidateRangesEvent; | ||
/** | ||
* @internal | ||
*/ | ||
export interface AppAccessTokenEvent { | ||
type: 'appAccessToken'; | ||
validationRequest: HttpGetRequest; | ||
appAccessToken: string; | ||
} | ||
@@ -67,2 +74,15 @@ /** | ||
*/ | ||
export interface HttpGetRequest { | ||
url: string; | ||
headers: { [key: string]: string }; | ||
} | ||
export type EventForApp = | ||
| AnalysisResultEvent | ||
| InvalidateRangesEvent | ||
| AppAccessTokenEvent; | ||
/** | ||
* @public | ||
*/ | ||
export interface OffsetRange { | ||
@@ -73,2 +93,5 @@ begin: number; | ||
/** | ||
* @public | ||
*/ | ||
export interface OffsetRangeWithReplacement { | ||
@@ -107,2 +130,6 @@ replacement: string; | ||
export function getAppAccessToken() { | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.requestAppAccessToken' }); | ||
} | ||
function postMessageToSidebar<T extends { command: string }>(message: T) { | ||
@@ -109,0 +136,0 @@ if (hasParentWindow()) { |
@@ -1,2 +0,2 @@ | ||
/* | ||
/** | ||
* Copyright 2019-present Acrolinx GmbH | ||
@@ -15,2 +15,3 @@ * | ||
* limitations under the License. | ||
* | ||
*/ | ||
@@ -20,2 +21,7 @@ | ||
/** | ||
* @packageDocumentation | ||
* @internal | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -37,1 +43,5 @@ export function includes<T>(array: T[] | undefined, element: any): boolean { | ||
} | ||
export function exhaustiveSwitchCheck(param: never, name: string): never { | ||
throw new Error(`Can't handle ${name} with value ${JSON.stringify(param)}`); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
93913
1471