@acrolinx/app-sdk
Advanced tools
Comparing version 0.1.1 to 0.1.2
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 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; | ||
"use strict";var e,n;function o(){return window.parent&&window.parent!==window}function r(e){o()?p({command:"acrolinx.sidebar.openWindow",url:e}):window.open(e)}function s(e){p({command:"acrolinx.sidebar.selectRanges",ranges:e})}function t(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 c(){p({command:"acrolinx.sidebar.requestCapabilities"})}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.RequiredAppApiCommand||(exports.RequiredAppApiCommand={})),exports.hasParentWindow=o,exports.openWindow=r,exports.selectRanges=s,exports.replaceRanges=t,exports.configureAddon=a,exports.getAppAccessToken=i,exports.requestCapabilities=c; | ||
},{}],"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)}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; | ||
"use strict";function e(e,t){return!!e&&e.indexOf(t)>=0}function t(t,n){return e(t,n)?{}:void 0}function n(e,t){return!(t.begin>=e.end||t.end<=e.begin)}function r(e,t){throw new Error("Can't handle "+t+" with value "+JSON.stringify(e))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.includes=e,exports.getEmptyObjectIfIncluded=t,exports.isOverlapping=n,exports.exhaustiveSwitchCheck=r; | ||
},{}],"QCba":[function(require,module,exports) { | ||
"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; | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.AppAccessTokenEvent=n.AppAccessTokenEvent,exports.CommonCapabilityAvailability=n.CommonCapabilityAvailability,exports.HttpGetRequest=n.HttpGetRequest,exports.OffsetRange=n.OffsetRange,exports.OffsetRangeWithReplacement=n.OffsetRangeWithReplacement,exports.VisibilityEvent=n.VisibilityEvent;var i,s,r=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"}(i=exports.RequiredCommands||(exports.RequiredCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges",e.visibility="visibility",e.capabilities="capabilities"}(s=exports.RequiredEvents||(exports.RequiredEvents={}));var a={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function i(i){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter,visibility:new t.InternalEventEmitter,capabilities:new t.InternalEventEmitter},this.waitingAppAccessTokenResolvers=[],this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow,getAppAccessToken:function(){return o.getAppAccessToken()}};var p=[];r.includes(i.requiredEvents,s.textExtractedLink)&&p.push(n.ReportType.extractedText);var c=[];r.includes(i.requiredEvents,s.textExtracted)&&c.push(n.ReportType.extractedText),n.configureAddon(e(e(e({},a),i),{requiredReportLinks:p,requiredReportContent:c,requires:i.requiredCommands,requiredEvents:{visibility:r.getEmptyObjectIfIncluded(i.requiredEvents,s.visibility),capabilities:r.getEmptyObjectIfIncluded(i.requiredEvents,s.capabilities)}})),window.addEventListener("message",function(e){var t,n=e.data;if(e.source===window.parent&&(null===(t=n)||void 0===t?void 0:t.type))switch(console.log("Got message from sidebar",e.data.type,e),n.type){case"analysisResult":o.handleAnalysisResultEvent(n);break;case"invalidRanges":o._events.invalidRanges.dispatchEvent(n);break;case"appAccessToken":o.waitingAppAccessTokenResolvers.forEach(function(e){e(n)}),o.waitingAppAccessTokenResolvers=[];break;case"visibility":o._events.visibility.dispatchEvent(n);break;case"capabilities":o._events.capabilities.dispatchEvent(n);break;default:r.exhaustiveSwitchCheck(n,"AppApiEvent")}},!1)}return Object.defineProperty(i.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),i.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,selection:e.selection})},i.prototype.getAppAccessToken=function(){var e=this,t=new Promise(function(t){e.waitingAppAccessTokenResolvers.push(t)});return n.getAppAccessToken(),t},i}();function p(e){return new o(e)}function c(e,t){return e.ranges.some(function(e){return r.isOverlapping(e,t)})}exports.initApi=p,exports.isInvalid=c; | ||
},{"./event-emitter":"QmUd","./raw":"eMvI","./utils":"UnXq"}],"M10p":[function(require,module,exports) { | ||
@@ -10,0 +10,0 @@ "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); |
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 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; | ||
"use strict";var e,n;function o(){return window.parent&&window.parent!==window}function r(e){o()?p({command:"acrolinx.sidebar.openWindow",url:e}):window.open(e)}function s(e){p({command:"acrolinx.sidebar.selectRanges",ranges:e})}function t(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 c(){p({command:"acrolinx.sidebar.requestCapabilities"})}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.RequiredAppApiCommand||(exports.RequiredAppApiCommand={})),exports.hasParentWindow=o,exports.openWindow=r,exports.selectRanges=s,exports.replaceRanges=t,exports.configureAddon=a,exports.getAppAccessToken=i,exports.requestCapabilities=c; | ||
},{}],"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)}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; | ||
"use strict";function e(e,t){return!!e&&e.indexOf(t)>=0}function t(t,n){return e(t,n)?{}:void 0}function n(e,t){return!(t.begin>=e.end||t.end<=e.begin)}function r(e,t){throw new Error("Can't handle "+t+" with value "+JSON.stringify(e))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.includes=e,exports.getEmptyObjectIfIncluded=t,exports.isOverlapping=n,exports.exhaustiveSwitchCheck=r; | ||
},{}],"QCba":[function(require,module,exports) { | ||
"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; | ||
"use strict";var e=this&&this.__assign||function(){return(e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./event-emitter"),n=require("./raw");exports.AppAccessTokenEvent=n.AppAccessTokenEvent,exports.CommonCapabilityAvailability=n.CommonCapabilityAvailability,exports.HttpGetRequest=n.HttpGetRequest,exports.OffsetRange=n.OffsetRange,exports.OffsetRangeWithReplacement=n.OffsetRangeWithReplacement,exports.VisibilityEvent=n.VisibilityEvent;var i,s,r=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"}(i=exports.RequiredCommands||(exports.RequiredCommands={})),function(e){e.textExtracted="textExtracted",e.textExtractedLink="textExtractedLink",e.invalidRanges="invalidRanges",e.visibility="visibility",e.capabilities="capabilities"}(s=exports.RequiredEvents||(exports.RequiredEvents={}));var a={appSignature:exports.DEVELOPMENT_APP_SIGNATURE,title:"Acrolinx App",requiredReportContent:[],requiredReportLinks:[]},o=function(){function i(i){var o=this;this._events={textExtracted:new t.InternalEventEmitter,textExtractedLink:new t.InternalEventEmitter,invalidRanges:new t.InternalEventEmitter,visibility:new t.InternalEventEmitter,capabilities:new t.InternalEventEmitter},this.waitingAppAccessTokenResolvers=[],this._commands={selectRanges:n.selectRanges,replaceRanges:n.replaceRanges,openWindow:n.openWindow,getAppAccessToken:function(){return o.getAppAccessToken()}};var p=[];r.includes(i.requiredEvents,s.textExtractedLink)&&p.push(n.ReportType.extractedText);var c=[];r.includes(i.requiredEvents,s.textExtracted)&&c.push(n.ReportType.extractedText),n.configureAddon(e(e(e({},a),i),{requiredReportLinks:p,requiredReportContent:c,requires:i.requiredCommands,requiredEvents:{visibility:r.getEmptyObjectIfIncluded(i.requiredEvents,s.visibility),capabilities:r.getEmptyObjectIfIncluded(i.requiredEvents,s.capabilities)}})),window.addEventListener("message",function(e){var t,n=e.data;if(e.source===window.parent&&(null===(t=n)||void 0===t?void 0:t.type))switch(console.log("Got message from sidebar",e.data.type,e),n.type){case"analysisResult":o.handleAnalysisResultEvent(n);break;case"invalidRanges":o._events.invalidRanges.dispatchEvent(n);break;case"appAccessToken":o.waitingAppAccessTokenResolvers.forEach(function(e){e(n)}),o.waitingAppAccessTokenResolvers=[];break;case"visibility":o._events.visibility.dispatchEvent(n);break;case"capabilities":o._events.capabilities.dispatchEvent(n);break;default:r.exhaustiveSwitchCheck(n,"AppApiEvent")}},!1)}return Object.defineProperty(i.prototype,"events",{get:function(){return this._events},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"commands",{get:function(){return this._commands},enumerable:!0,configurable:!0}),i.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,selection:e.selection})},i.prototype.getAppAccessToken=function(){var e=this,t=new Promise(function(t){e.waitingAppAccessTokenResolvers.push(t)});return n.getAppAccessToken(),t},i}();function p(e){return new o(e)}function c(e,t){return e.ranges.some(function(e){return r.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 |
import { TypedEventEmitter } from './event-emitter'; | ||
import { AppAccessTokenEvent, AppButtonConfig, HttpGetRequest, OffsetRange, OffsetRangeWithReplacement } from './raw'; | ||
export { OffsetRange, OffsetRangeWithReplacement, AppAccessTokenEvent, HttpGetRequest }; | ||
import { AppAccessTokenEvent, AppButtonConfig, CommonCapabilityAvailability, DocumentSelection, HttpGetRequest, OffsetRange, OffsetRangeWithReplacement, VisibilityEvent } from './raw'; | ||
export { OffsetRange, OffsetRangeWithReplacement, AppAccessTokenEvent, HttpGetRequest, CommonCapabilityAvailability, VisibilityEvent }; | ||
/** | ||
@@ -14,2 +14,7 @@ * @public | ||
text: string; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
selection?: DocumentSelection; | ||
} | ||
@@ -51,3 +56,13 @@ /** | ||
textExtractedLink = "textExtractedLink", | ||
invalidRanges = "invalidRanges" | ||
invalidRanges = "invalidRanges", | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
visibility = "visibility", | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
capabilities = "capabilities" | ||
} | ||
@@ -61,3 +76,19 @@ /** | ||
invalidRanges: TypedEventEmitter<TextRangesExpiredEvent>; | ||
visibility: TypedEventEmitter<VisibilityEvent>; | ||
capabilities: TypedEventEmitter<CapabilitiesEvent>; | ||
} | ||
export interface CapabilitiesEvent { | ||
type: 'capabilities'; | ||
events: { | ||
invalidRanges: CommonCapabilityAvailability; | ||
visibility: CommonCapabilityAvailability; | ||
capabilities: CommonCapabilityAvailability; | ||
}; | ||
commands: { | ||
openWindow: CommonCapabilityAvailability; | ||
requestAppAccessToken: CommonCapabilityAvailability; | ||
selectRanges: CommonCapabilityAvailability; | ||
replaceRanges: CommonCapabilityAvailability; | ||
}; | ||
} | ||
/** | ||
@@ -87,2 +118,7 @@ * @public | ||
button?: AppButtonConfig; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
processSelectionButton?: AppButtonConfig; | ||
requiredEvents: RequiredEvents[]; | ||
@@ -89,0 +125,0 @@ requiredCommands: RequiredCommands[]; |
@@ -54,2 +54,12 @@ "use strict"; | ||
RequiredEvents["invalidRanges"] = "invalidRanges"; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
RequiredEvents["visibility"] = "visibility"; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
RequiredEvents["capabilities"] = "capabilities"; | ||
})(RequiredEvents = exports.RequiredEvents || (exports.RequiredEvents = {})); | ||
@@ -74,3 +84,5 @@ /** | ||
textExtractedLink: new event_emitter_1.InternalEventEmitter(), | ||
invalidRanges: new event_emitter_1.InternalEventEmitter() | ||
invalidRanges: new event_emitter_1.InternalEventEmitter(), | ||
visibility: new event_emitter_1.InternalEventEmitter(), | ||
capabilities: new event_emitter_1.InternalEventEmitter() | ||
}; | ||
@@ -93,9 +105,14 @@ this.waitingAppAccessTokenResolvers = []; | ||
raw_1.configureAddon(__assign(__assign(__assign({}, DEFAULT_CONFIG), config), { requiredReportLinks: requiredReportLinks, | ||
requiredReportContent: requiredReportContent, requires: config.requiredCommands })); | ||
requiredReportContent: requiredReportContent, requires: config.requiredCommands, requiredEvents: { | ||
visibility: utils_1.getEmptyObjectIfIncluded(config.requiredEvents, RequiredEvents.visibility), | ||
capabilities: utils_1.getEmptyObjectIfIncluded(config.requiredEvents, RequiredEvents.capabilities) | ||
} })); | ||
window.addEventListener('message', function (messageEvent) { | ||
console.log('Got message from sidebar', messageEvent.data.type, messageEvent); | ||
var _a; | ||
var eventForApp = messageEvent.data; | ||
if (!eventForApp) { | ||
if (messageEvent.source !== window.parent || !((_a = eventForApp) === null || _a === void 0 ? void 0 : _a.type)) { | ||
// Message is probably not from the Sidebar. Ignore it. | ||
return; | ||
} | ||
console.log('Got message from sidebar', messageEvent.data.type, messageEvent); | ||
switch (eventForApp.type) { | ||
@@ -114,2 +131,8 @@ case 'analysisResult': | ||
break; | ||
case 'visibility': | ||
_this._events.visibility.dispatchEvent(eventForApp); | ||
break; | ||
case 'capabilities': | ||
_this._events.capabilities.dispatchEvent(eventForApp); | ||
break; | ||
default: | ||
@@ -146,3 +169,4 @@ utils_1.exhaustiveSwitchCheck(eventForApp, 'AppApiEvent'); | ||
text: textExtractedReport.content, | ||
languageId: analysisResult.languageId | ||
languageId: analysisResult.languageId, | ||
selection: analysisResult.selection | ||
}); | ||
@@ -153,3 +177,3 @@ } | ||
var _this = this; | ||
var promise = new Promise(function (resolve, _reject) { | ||
var promise = new Promise(function (resolve) { | ||
_this.waitingAppAccessTokenResolvers.push(resolve); | ||
@@ -156,0 +180,0 @@ }); |
@@ -8,6 +8,7 @@ export interface AppButtonConfig { | ||
} | ||
export declare enum AppApiCapability { | ||
export declare enum RequiredAppApiCommand { | ||
selectRanges = "selectRanges", | ||
replaceRanges = "replaceRanges" | ||
} | ||
declare type AppApiEventConfig = {}; | ||
export interface SidebarAddonConfig { | ||
@@ -18,3 +19,12 @@ appSignature: string; | ||
button?: AppButtonConfig; | ||
requires?: AppApiCapability[]; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
processSelectionButton?: AppButtonConfig; | ||
requires?: RequiredAppApiCommand[]; | ||
requiredEvents?: { | ||
visibility?: AppApiEventConfig; | ||
capabilities?: AppApiEventConfig; | ||
}; | ||
requiredReportLinks: readonly ReportType[]; | ||
@@ -33,4 +43,16 @@ requiredReportContent: readonly ReportType[]; | ||
languageId: string; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
selection?: DocumentSelection; | ||
reports: ReportsForAddon; | ||
} | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
export interface DocumentSelection { | ||
ranges: OffsetRange[]; | ||
} | ||
interface InvalidateRangesEvent { | ||
@@ -40,2 +62,28 @@ type: 'invalidRanges'; | ||
} | ||
export interface VisibilityEvent { | ||
type: 'visibility'; | ||
visible: boolean; | ||
} | ||
export interface CommonCapabilityAvailability { | ||
available: boolean; | ||
temporary: boolean; | ||
} | ||
export interface CapabilitiesEventInternal { | ||
type: 'capabilities'; | ||
events: { | ||
appAccessToken: CommonCapabilityAvailability; | ||
analysisResult: CommonCapabilityAvailability; | ||
invalidRanges: CommonCapabilityAvailability; | ||
visibility: CommonCapabilityAvailability; | ||
capabilities: CommonCapabilityAvailability; | ||
}; | ||
commands: { | ||
configureAddon: CommonCapabilityAvailability; | ||
requestCapabilities: CommonCapabilityAvailability; | ||
openWindow: CommonCapabilityAvailability; | ||
requestAppAccessToken: CommonCapabilityAvailability; | ||
selectRanges: CommonCapabilityAvailability; | ||
replaceRanges: CommonCapabilityAvailability; | ||
}; | ||
} | ||
/** | ||
@@ -58,3 +106,3 @@ * @internal | ||
} | ||
export declare type EventForApp = AnalysisResultEvent | InvalidateRangesEvent | AppAccessTokenEvent; | ||
export declare type EventForApp = AnalysisResultEvent | InvalidateRangesEvent | AppAccessTokenEvent | CapabilitiesEventInternal | VisibilityEvent; | ||
/** | ||
@@ -81,3 +129,4 @@ * @public | ||
export declare function getAppAccessToken(): void; | ||
export declare function requestCapabilities(): void; | ||
export {}; | ||
//# sourceMappingURL=raw.d.ts.map |
@@ -22,7 +22,7 @@ "use strict"; | ||
})(ReportType = exports.ReportType || (exports.ReportType = {})); | ||
var AppApiCapability; | ||
(function (AppApiCapability) { | ||
AppApiCapability["selectRanges"] = "selectRanges"; | ||
AppApiCapability["replaceRanges"] = "replaceRanges"; | ||
})(AppApiCapability = exports.AppApiCapability || (exports.AppApiCapability = {})); | ||
var RequiredAppApiCommand; | ||
(function (RequiredAppApiCommand) { | ||
RequiredAppApiCommand["selectRanges"] = "selectRanges"; | ||
RequiredAppApiCommand["replaceRanges"] = "replaceRanges"; | ||
})(RequiredAppApiCommand = exports.RequiredAppApiCommand || (exports.RequiredAppApiCommand = {})); | ||
function hasParentWindow() { | ||
@@ -34,3 +34,3 @@ return window.parent && window.parent !== window; | ||
if (hasParentWindow()) { | ||
window.parent.postMessage({ command: 'acrolinx.sidebar.openWindow', url: url }, '*'); | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.openWindow', url: url }); | ||
} | ||
@@ -58,2 +58,6 @@ else { | ||
exports.getAppAccessToken = getAppAccessToken; | ||
function requestCapabilities() { | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.requestCapabilities' }); | ||
} | ||
exports.requestCapabilities = requestCapabilities; | ||
function postMessageToSidebar(message) { | ||
@@ -60,0 +64,0 @@ if (hasParentWindow()) { |
@@ -23,4 +23,5 @@ /** | ||
export declare function includes<T>(array: T[] | undefined, element: any): boolean; | ||
export declare function getEmptyObjectIfIncluded<T>(array: T[], element: T): {} | undefined; | ||
export declare function isOverlapping(range1: OffsetRange, range2: OffsetRange): boolean; | ||
export declare function exhaustiveSwitchCheck(param: never, name: string): never; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -31,2 +31,6 @@ "use strict"; | ||
exports.includes = includes; | ||
function getEmptyObjectIfIncluded(array, element) { | ||
return includes(array, element) ? {} : undefined; | ||
} | ||
exports.getEmptyObjectIfIncluded = getEmptyObjectIfIncluded; | ||
function isOverlapping(range1, range2) { | ||
@@ -33,0 +37,0 @@ var isNotOverlapping = range2.begin >= range1.end || range2.end <= range1.begin; |
{ | ||
"name": "@acrolinx/app-sdk", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Acrolinx App SDK", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
102
src/index.ts
@@ -21,5 +21,7 @@ /* | ||
AppAccessTokenEvent, | ||
AppApiCapability, | ||
AppButtonConfig, | ||
CapabilitiesEventInternal, | ||
CommonCapabilityAvailability, | ||
configureAddon, | ||
DocumentSelection, | ||
EventForApp, | ||
@@ -33,6 +35,13 @@ getAppAccessToken, | ||
ReportType, | ||
RequiredAppApiCommand, | ||
selectRanges, | ||
SidebarAddonConfig | ||
SidebarAddonConfig, | ||
VisibilityEvent | ||
} from './raw'; | ||
import { exhaustiveSwitchCheck, includes, isOverlapping } from './utils'; | ||
import { | ||
exhaustiveSwitchCheck, | ||
getEmptyObjectIfIncluded, | ||
includes, | ||
isOverlapping | ||
} from './utils'; | ||
@@ -43,3 +52,5 @@ export { | ||
AppAccessTokenEvent, | ||
HttpGetRequest | ||
HttpGetRequest, | ||
CommonCapabilityAvailability, | ||
VisibilityEvent | ||
}; | ||
@@ -59,2 +70,8 @@ | ||
text: string; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
selection?: DocumentSelection; | ||
} | ||
@@ -101,3 +118,15 @@ | ||
textExtractedLink = 'textExtractedLink', | ||
invalidRanges = 'invalidRanges' | ||
invalidRanges = 'invalidRanges', | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
visibility = 'visibility', | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
capabilities = 'capabilities' | ||
} | ||
@@ -122,3 +151,5 @@ | ||
textExtractedLink: new InternalEventEmitter<ExtractedTextLinkEvent>(), | ||
invalidRanges: new InternalEventEmitter<TextRangesExpiredEvent>() | ||
invalidRanges: new InternalEventEmitter<TextRangesExpiredEvent>(), | ||
visibility: new InternalEventEmitter<VisibilityEvent>(), | ||
capabilities: new InternalEventEmitter<CapabilitiesEventInternal>() | ||
}; | ||
@@ -161,3 +192,13 @@ | ||
requiredReportContent, | ||
requires: (config.requiredCommands as unknown) as AppApiCapability[] | ||
requires: (config.requiredCommands as unknown) as RequiredAppApiCommand[], | ||
requiredEvents: { | ||
visibility: getEmptyObjectIfIncluded( | ||
config.requiredEvents, | ||
RequiredEvents.visibility | ||
), | ||
capabilities: getEmptyObjectIfIncluded( | ||
config.requiredEvents, | ||
RequiredEvents.capabilities | ||
) | ||
} | ||
}); | ||
@@ -168,2 +209,9 @@ | ||
messageEvent => { | ||
const eventForApp: EventForApp | undefined = messageEvent.data; | ||
if (messageEvent.source !== window.parent || !eventForApp?.type) { | ||
// Message is probably not from the Sidebar. Ignore it. | ||
return; | ||
} | ||
console.log( | ||
@@ -175,8 +223,2 @@ 'Got message from sidebar', | ||
const eventForApp: EventForApp | undefined = messageEvent.data; | ||
if (!eventForApp) { | ||
return; | ||
} | ||
switch (eventForApp.type) { | ||
@@ -195,2 +237,8 @@ case 'analysisResult': | ||
break; | ||
case 'visibility': | ||
this._events.visibility.dispatchEvent(eventForApp); | ||
break; | ||
case 'capabilities': | ||
this._events.capabilities.dispatchEvent(eventForApp); | ||
break; | ||
default: | ||
@@ -218,3 +266,4 @@ exhaustiveSwitchCheck(eventForApp, 'AppApiEvent'); | ||
text: textExtractedReport.content, | ||
languageId: analysisResult.languageId | ||
languageId: analysisResult.languageId, | ||
selection: analysisResult.selection | ||
}); | ||
@@ -225,3 +274,3 @@ } | ||
private getAppAccessToken(): Promise<AppAccessTokenResult> { | ||
const promise = new Promise<AppAccessTokenResult>((resolve, _reject) => { | ||
const promise = new Promise<AppAccessTokenResult>(resolve => { | ||
this.waitingAppAccessTokenResolvers.push(resolve); | ||
@@ -241,4 +290,20 @@ }); | ||
invalidRanges: TypedEventEmitter<TextRangesExpiredEvent>; | ||
visibility: TypedEventEmitter<VisibilityEvent>; | ||
capabilities: TypedEventEmitter<CapabilitiesEvent>; | ||
} | ||
export interface CapabilitiesEvent { | ||
type: 'capabilities'; | ||
events: { | ||
invalidRanges: CommonCapabilityAvailability; | ||
visibility: CommonCapabilityAvailability; | ||
capabilities: CommonCapabilityAvailability; | ||
}; | ||
commands: { | ||
openWindow: CommonCapabilityAvailability; | ||
requestAppAccessToken: CommonCapabilityAvailability; | ||
selectRanges: CommonCapabilityAvailability; | ||
replaceRanges: CommonCapabilityAvailability; | ||
}; | ||
} | ||
/** | ||
@@ -270,2 +335,9 @@ * @public | ||
button?: AppButtonConfig; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
processSelectionButton?: AppButtonConfig; | ||
requiredEvents: RequiredEvents[]; | ||
@@ -272,0 +344,0 @@ requiredCommands: RequiredCommands[]; |
@@ -26,3 +26,3 @@ /* | ||
export enum AppApiCapability { | ||
export enum RequiredAppApiCommand { | ||
selectRanges = 'selectRanges', | ||
@@ -32,2 +32,4 @@ replaceRanges = 'replaceRanges' | ||
type AppApiEventConfig = {}; | ||
export interface SidebarAddonConfig { | ||
@@ -38,3 +40,14 @@ appSignature: string; | ||
button?: AppButtonConfig; | ||
requires?: AppApiCapability[]; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
processSelectionButton?: AppButtonConfig; | ||
requires?: RequiredAppApiCommand[]; | ||
requiredEvents?: { | ||
visibility?: AppApiEventConfig; | ||
capabilities?: AppApiEventConfig; | ||
}; | ||
requiredReportLinks: readonly ReportType[]; | ||
@@ -56,5 +69,20 @@ requiredReportContent: readonly ReportType[]; | ||
languageId: string; | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
selection?: DocumentSelection; | ||
reports: ReportsForAddon; | ||
} | ||
/** | ||
* Experimental. | ||
* Since Acrolinx 2020.4 | ||
*/ | ||
export interface DocumentSelection { | ||
ranges: OffsetRange[]; | ||
} | ||
interface InvalidateRangesEvent { | ||
@@ -65,2 +93,31 @@ type: 'invalidRanges'; | ||
export interface VisibilityEvent { | ||
type: 'visibility'; | ||
visible: boolean; | ||
} | ||
export interface CommonCapabilityAvailability { | ||
available: boolean; | ||
temporary: boolean; | ||
} | ||
export interface CapabilitiesEventInternal { | ||
type: 'capabilities'; | ||
events: { | ||
appAccessToken: CommonCapabilityAvailability; | ||
analysisResult: CommonCapabilityAvailability; | ||
invalidRanges: CommonCapabilityAvailability; | ||
visibility: CommonCapabilityAvailability; | ||
capabilities: CommonCapabilityAvailability; | ||
}; | ||
commands: { | ||
configureAddon: CommonCapabilityAvailability; | ||
requestCapabilities: CommonCapabilityAvailability; | ||
openWindow: CommonCapabilityAvailability; | ||
requestAppAccessToken: CommonCapabilityAvailability; | ||
selectRanges: CommonCapabilityAvailability; | ||
replaceRanges: CommonCapabilityAvailability; | ||
}; | ||
} | ||
/** | ||
@@ -86,3 +143,5 @@ * @internal | ||
| InvalidateRangesEvent | ||
| AppAccessTokenEvent; | ||
| AppAccessTokenEvent | ||
| CapabilitiesEventInternal | ||
| VisibilityEvent; | ||
@@ -112,6 +171,3 @@ /** | ||
if (hasParentWindow()) { | ||
window.parent.postMessage( | ||
{ command: 'acrolinx.sidebar.openWindow', url }, | ||
'*' | ||
); | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.openWindow', url }); | ||
} else { | ||
@@ -138,2 +194,6 @@ window.open(url); | ||
export function requestCapabilities() { | ||
postMessageToSidebar({ command: 'acrolinx.sidebar.requestCapabilities' }); | ||
} | ||
function postMessageToSidebar<T extends { command: string }>(message: T) { | ||
@@ -140,0 +200,0 @@ if (hasParentWindow()) { |
@@ -33,2 +33,9 @@ /** | ||
export function getEmptyObjectIfIncluded<T>( | ||
array: T[], | ||
element: T | ||
): {} | undefined { | ||
return includes(array, element) ? {} : undefined; | ||
} | ||
export function isOverlapping( | ||
@@ -35,0 +42,0 @@ range1: OffsetRange, |
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
105505
1718