tocco-widget-utils 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,6 @@ To embed a widget in the website, just add a `<div>` container and decorate it w
19
19
  #### Attributes
20
20
 
21
21
  - `data-tocco-widget-key` (required): The key of the widget config
22
- - `data-id` (optional): An id to be able to reference events and methods through `window` obj
23
22
 
24
23
  #### Example
25
24
 
@@ -38,14 +37,14 @@ window.toccoEventHandlers = {
38
37
  }
39
38
  ```
40
39
 
41
- Use the `data-id` attribute to define the property name on the `toccoEventHandlers` obj to defined event handlers for each widget. Preferable used if multiple widgets are embedded.
40
+ The widget key is used as property name on the `toccoEventHandlers` obj to attach all event handlers for each widget. Preferable used if multiple widgets are embedded.
42
41
  ```html
43
- <div data-id="login" data-tocco-widget-key="12"></div>
42
+ <div data-tocco-widget-key="12"></div>
44
43
  ```
45
44
 
46
45
  ```js
47
46
  window.toccoEventHandlers = {
48
- login: {
47
+ '12': {
49
48
  loginSuccess: () => {}
50
49
  }
51
50
  }
@@ -55,15 +54,15 @@ window.toccoEventHandlers = {
55
54
  A widget can provide methods which can be invoked to communicate with the widget itself.
56
55
  When a widget gets rendered these methods will be attached to `window.toccoMethods` to provide them to outer scripts.
57
56
 
58
- The `data-id` attribute is used as a property name on the `window.toccoMethods` object. If the `data-id` attribute is not set the methods will not be attached to the `toccoMethods` object.
57
+ The widget key is used as a property name on the `window.toccoMethods` object.
59
58
 
60
59
  #### Example
61
60
  ```html
62
- <div data-id="login" data-tocco-widget-key="12"></div>
61
+ <div data-tocco-widget-key="12"></div>
63
62
  ```
64
63
  ```js
65
64
  // use methods via `window.toccoMethods` object
66
- window.toccoMethods.login.setLocale('fr-CH');
65
+ window.toccoMethods['12'].setLocale('fr-CH');
67
66
  ```
68
67
 
69
68
  ### Theme
@@ -80,17 +79,17 @@ window.toccoTheme = {
80
79
  }
81
80
  ```
82
81
 
83
- ### Widget States
84
- A widget can be in different states. Dependend on the state other html elements can be shown.
82
+ ### Visibitlity Status
83
+ A widget can be in different visibility status. Dependend on the status other html elements can be shown.
85
84
 
86
- In order to show an element dependend on a widget state it has to have two attributes:
85
+ In order to show an element dependend on a visibility status it has to have two attributes:
87
86
  - `data-tocco-widget-ref` to define which widget it should listen to
88
- - `data-tocco-widget-states` to define the states of the widget to show the element as whitespace-separated list
87
+ - `data-tocco-visibility-status` to define the status of the widget to show the element as whitespace-separated list
89
88
 
90
89
  ```html
91
90
  <div data-tocco-widget-key="12"></div>
92
91
 
93
- <div data-tocco-widget-ref="12" data-tocco-widget-states="success">Erfolgreich.</div>
92
+ <div data-tocco-widget-ref="12" data-tocco-visibility-status="success">Erfolgreich.</div>
94
93
 
95
- <div data-tocco-widget-ref="12" data-tocco-widget-states="list detail">...</div>
94
+ <div data-tocco-widget-ref="12" data-tocco-visibility-status="list detail">...</div>
96
95
  ```
package/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.37
2
+ - be able to embed bootstrap script relative
3
+
4
+ 0.1.36
5
+ - remove data-id attribute
6
+
1
7
  0.1.35
2
8
  - rename onStateChange to onVisibilityStatusChange
3
9
 
package/dist/bootstrap.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["tocco-widget-utils"]=e():t["tocco-widget-utils"]=e()}(self,(()=>(()=>{var t={926:t=>{function e(t,e,r,n,o,c,i){try{var a=t[c](i),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,c){var i=t.apply(r,n);function a(t){e(i,o,c,a,u,"next",t)}function u(t){e(i,o,c,a,u,"throw",t)}a(void 0)}))}}},713:t=>{t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}},8:t=>{function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?t.exports=e=function(t){return typeof t}:t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(r)}t.exports=e},757:(t,e,r)=>{t.exports=r(666)},813:t=>{t.exports=function(t,e){return t===e||t!=t&&e!=e}},666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},c=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",a=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,c=Object.create(o.prototype),i=new S(n||[]);return c._invoke=function(t,e,r){var n=p;return function(o,c){if(n===d)throw new Error("Generator is already running");if(n===h){if("throw"===o)throw c;return D()}for(r.method=o,r.arg=c;;){var i=r.delegate;if(i){var a=E(i,r);if(a){if(a===y)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=d;var u=f(t,e,r);if("normal"===u.type){if(n=r.done?h:l,u.arg===y)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=h,r.method="throw",r.arg=u.arg)}}}(t,r,i),c}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p="suspendedStart",l="suspendedYield",d="executing",h="completed",y={};function v(){}function g(){}function b(){}var w={};w[c]=function(){return this};var m=Object.getPrototypeOf,O=m&&m(m(_([])));O&&O!==r&&n.call(O,c)&&(w=O);var j=b.prototype=v.prototype=Object.create(w);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,c,i,a){var u=f(t[o],t,c);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):e.resolve(p).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,a)}))}a(u.arg)}var o;this._invoke=function(t,n){function c(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(c,c):c()}}function E(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var c=o.arg;return c?c.done?(r[t.resultName]=c.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):c:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function _(t){if(t){var r=t[c];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:D}}function D(){return{value:e,done:!0}}return g.prototype=j.constructor=b,b.constructor=g,g.displayName=u(b,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,u(t,a,"GeneratorFunction")),t.prototype=Object.create(j),t},t.awrap=function(t){return{__await:t}},x(P.prototype),P.prototype[i]=function(){return this},t.AsyncIterator=P,t.async=function(e,r,n,o,c){void 0===c&&(c=Promise);var i=new P(s(e,r,n,o),c);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(j),u(j,a,"Generator"),j[c]=function(){return this},j.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return a.type="throw",a.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var c=this.tryEntries.length-1;c>=0;--c){var i=this.tryEntries[c],a=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var c=o;break}}c&&("break"===t||"continue"===t)&&c.tryLoc<=e&&e<=c.finallyLoc&&(c=null);var i=c?c.completion:{};return i.type=t,i.arg=e,c?(this.method="next",this.next=c.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:_(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}},659:t=>{"use strict";t.exports=JSON.parse('{"name":"tocco-widget-utils","version":"0.1.35","description":"","scripts":{"compile:prod":"cd ../../../ && npm run compile:prod -- --package=widget-utils","prepublish":"npm run compile:prod","test":"jest"},"dependencies":{},"devDependencies":{"tocco-util":"*"}}')}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var c=e[n]={exports:{}};return t[n](c,c.exports,r),c.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n);var t=r(926),e=r.n(t),o=r(757),c=r.n(o),i=function(t){return"/js/tocco-".concat(t,"/dist/")},a=function(t,e){var r=t!==e?e:"index";return"".concat(i(t)).concat(r,".js")},u=function(t){return new Promise((function(e,r){var n=document.createElement("script");n.src=t,n.async=!0,n.type="text/javascript",n.onload=function(){e()},n.onerror=function(){r(new Error("Could not load script."))},n.crossorogin=!0;var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o)}))};const s=u,f=a;var p="toccoBackendUrl",l="data-tocco-widget-key",d="data-tocco-visibility-status";const h=function(){var t;window.console&&(t=console).log.apply(t,arguments)},y=function(){if(window.console){var t=console.error||console.log;t.apply(void 0,arguments)}};var v=r(713),g=r.n(v);function b(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function w(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?b(Object(r),!0).forEach((function(e){g()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var m=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new Headers;r.set("Content-Type","application/json");var n=w({headers:r,method:"GET",credentials:"include"},e);return fetch(t,n)},O=function(t){var e=t.ok,r=t.status;return t.json().then((function(t){return{ok:e,status:r,body:t}}))},j="error",x=function(){var t=e()(c().mark((function t(e,r,n){var o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="ERROR MESSAGE: ".concat(n.message," \nSTACK: ").concat(n.stack?n.stack.substring(0,1e3):"-"),i="".concat(r,"\n").concat(o),y(i),t.next=5,E(j,e,i);case 5:case"end":return t.stop()}}),t)})));return function(e,r,n){return t.apply(this,arguments)}}(),P=function(){var t=e()(c().mark((function t(e,r){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return y(r),t.next=3,E(j,e,r);case 3:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),E=function(){var t=e()(c().mark((function t(e,r,n){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,m("".concat(r,"/nice2/log?level=").concat(e,"&message=").concat(encodeURI(n)),{method:"POST"});case 3:t.next=7;break;case 5:t.prev=5,t.t0=t.catch(0);case 7:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(e,r,n){return t.apply(this,arguments)}}(),k=function(t,e,r){try{var n=document.getElementById(e)||function(t){var e=document.createElement("style");return e.id=t,document.head.appendChild(e),e}(e);n.innerHTML=r}catch(e){x(t,"Could not apply global styles.",e)}},L=function(t,e,r){var n=r.map((function(t){return"[".concat("data-tocco-widget-ref",'="').concat(e,'"][').concat(d,'~="').concat(t,'"]')})).join(",\n"),o="".concat(n," {\n display: inherit;\n}");k(t,"".concat("tocco-visibility-status-styles","-").concat(e),o)};const S=function(t){var e=t.backendUrl,r="[".concat(d,"] {display: none;}");k(e,"tocco-initial-visibility-status-styles",r)};var _=r(813),D=r.n(_),T=r(8),N=r.n(T);function C(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function A(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?C(Object(r),!0).forEach((function(e){g()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var G=function(t){return t.getAttribute("data-id")},I=function(){var t=window.toccoTheme;if(t&&"object"===N()(t))return t},M=function(t){return t&&Object.keys(t).length>0&&"function"==typeof t[Object.keys(t)[0]]},U=function(t){var e=window.toccoEventHandlers;if(M(e))return e;if(e){var r=G(t);if(r){var n=e[r];if(M(n))return n}}return{}},R=function(t,e){var r=G(t);r&&(window.toccoMethods=A(A({},window.toccoMethods),{},g()({},r,e)))};function B(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function F(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?B(Object(r),!0).forEach((function(e){g()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):B(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var H=function(t){return t.getAttribute(l)},V=function(t,e,r){var n=e.ok,o=e.status,c=e.body;return n?e:(403===o&&"INVALID_DOMAIN"===(null==c?void 0:c.errorCode)&&P(t,c.message),void(404===o&&P(t,"Widget config '".concat(r,"' not found."))))},z=function(t,e,r){return function(){for(var n=arguments.length,o=new Array(n),c=0;c<n;c++)o[c]=arguments[c];var i=o[0].status;L(t,e,i),"function"==typeof r&&r.apply(void 0,o)}},K=function(){var t=e()(c().mark((function t(e,r,n){var o,i,a,u,p,l,d,h,y,v,g,b;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=H(n),t.next=3,m("".concat(e,"/nice2/rest/widget/configs/").concat(o)).then(O).then((function(t){return V(e,t,o)})).then((function(t){return null==t?void 0:t.body})).catch((function(t){x(e,"Could not fetch widget config '".concat(o,"'."),t)}));case 3:if(!(i=t.sent)){t.next=21;break}return a=i.appName,u=i.packageName,p=i.locale,l=i.config,t.prev=6,t.next=9,s("".concat(r).concat(f(u,a)));case 9:t.next=15;break;case 11:return t.prev=11,t.t0=t.catch(6),x(e,"Could not fetch package 'tocco-".concat(u,"'."),t.t0),t.abrupt("return");case 15:d=U(n),h=F(F({},d),{},{onVisibilityStatusChange:z(e,o,d.onVisibilityStatusChange)}),y=I(),v=F(F(F({backendUrl:e},y?{customTheme:y}:{}),{},{locale:p},l),{},{appContext:{embedType:"widget",widgetConfigKey:o}},h),g="".concat(r,"/js/tocco-").concat(u,"/dist/");try{b=window.reactRegistry.render(a,n,"",v,h,g),R(n,b)}catch(t){x(e,"Could not render app '".concat(a,"'."),t)}case 21:case"end":return t.stop()}}),t,null,[[6,11]])})));return function(e,r,n){return t.apply(this,arguments)}}(),Y=function(t){var e=r(659).version,n=F({version:e},t),o=window.toccoBootstrap;return o?(h("tocco-widget-utils - bootstrap script is already initialized"),!D()(o,n)&&y("More than one bootstrap script with different settings has been found. Add only one bootstrap script per page.","\nInitialized bootstrap script:",o,"\nIgnored bootstrap script:",n),!1):(window.toccoBootstrap=n,h("tocco-widget-utils - v".concat(e," - bootstrap")),!0)},q=function(){var t=e()(c().mark((function t(e){var r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Y(e)){t.next=3;break}return t.abrupt("return");case 3:return r=e.backendUrl,n=e.assetUrl,o=document.querySelectorAll("[".concat(l,"]")),i=Array.prototype.slice.call(o),t.next=8,Promise.all(i.map((function(t){return K(r,n,t)})));case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();const J=q;var W,Q;W=function(t){var e=t.currentScript.getAttribute("src"),r=new URL(e);return r.protocol+"//"+r.host}(document),Q={backendUrl:window[p]?window[p]:W,assetUrl:W},S(Q),document.addEventListener("DOMContentLoaded",e()(c().mark((function t(){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s("".concat(W,"/nice2/javascript/nice2-react.release.js"));case 2:return t.next=4,J(Q);case 4:case"end":return t.stop()}}),t)}))))})(),n})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["tocco-widget-utils"]=e():t["tocco-widget-utils"]=e()}(self,(()=>(()=>{var t={926:t=>{function e(t,e,r,n,o,c,i){try{var a=t[c](i),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,c){var i=t.apply(r,n);function a(t){e(i,o,c,a,u,"next",t)}function u(t){e(i,o,c,a,u,"throw",t)}a(void 0)}))}}},713:t=>{t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}},8:t=>{function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?t.exports=e=function(t){return typeof t}:t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(r)}t.exports=e},757:(t,e,r)=>{t.exports=r(666)},813:t=>{t.exports=function(t,e){return t===e||t!=t&&e!=e}},666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},c=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",a=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,c=Object.create(o.prototype),i=new S(n||[]);return c._invoke=function(t,e,r){var n=p;return function(o,c){if(n===h)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw c;return D()}for(r.method=o,r.arg=c;;){var i=r.delegate;if(i){var a=E(i,r);if(a){if(a===y)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var u=f(t,e,r);if("normal"===u.type){if(n=r.done?d:l,u.arg===y)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=d,r.method="throw",r.arg=u.arg)}}}(t,r,i),c}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p="suspendedStart",l="suspendedYield",h="executing",d="completed",y={};function v(){}function g(){}function w(){}var b={};b[c]=function(){return this};var m=Object.getPrototypeOf,O=m&&m(m(_([])));O&&O!==r&&n.call(O,c)&&(b=O);var j=w.prototype=v.prototype=Object.create(b);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,c,i,a){var u=f(t[o],t,c);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):e.resolve(p).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,a)}))}a(u.arg)}var o;this._invoke=function(t,n){function c(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(c,c):c()}}function E(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var c=o.arg;return c?c.done?(r[t.resultName]=c.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):c:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function _(t){if(t){var r=t[c];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:D}}function D(){return{value:e,done:!0}}return g.prototype=j.constructor=w,w.constructor=g,g.displayName=u(w,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,u(t,a,"GeneratorFunction")),t.prototype=Object.create(j),t},t.awrap=function(t){return{__await:t}},x(P.prototype),P.prototype[i]=function(){return this},t.AsyncIterator=P,t.async=function(e,r,n,o,c){void 0===c&&(c=Promise);var i=new P(s(e,r,n,o),c);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(j),u(j,a,"Generator"),j[c]=function(){return this},j.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return a.type="throw",a.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var c=this.tryEntries.length-1;c>=0;--c){var i=this.tryEntries[c],a=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var c=o;break}}c&&("break"===t||"continue"===t)&&c.tryLoc<=e&&e<=c.finallyLoc&&(c=null);var i=c?c.completion:{};return i.type=t,i.arg=e,c?(this.method="next",this.next=c.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:_(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}},659:t=>{"use strict";t.exports=JSON.parse('{"name":"tocco-widget-utils","version":"0.1.37","description":"","scripts":{"compile:prod":"cd ../../../ && npm run compile:prod -- --package=widget-utils","prepublish":"npm run compile:prod","test":"jest"},"dependencies":{},"devDependencies":{"tocco-util":"*"}}')}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var c=e[n]={exports:{}};return t[n](c,c.exports,r),c.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n);var t=r(926),e=r.n(t),o=r(757),c=r.n(o),i=function(t){return"/js/tocco-".concat(t,"/dist/")},a=function(t,e){var r=t!==e?e:"index";return"".concat(i(t)).concat(r,".js")},u=function(t){return new Promise((function(e,r){var n=document.createElement("script");n.src=t,n.async=!0,n.type="text/javascript",n.onload=function(){e()},n.onerror=function(){r(new Error("Could not load script."))},n.crossorogin=!0;var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o)}))};const s=u,f=a;var p="toccoBackendUrl",l="data-tocco-widget-key",h="data-tocco-visibility-status";const d=function(){var t;window.console&&(t=console).log.apply(t,arguments)},y=function(){if(window.console){var t=console.error||console.log;t.apply(void 0,arguments)}};var v=r(713),g=r.n(v);function w(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function b(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?w(Object(r),!0).forEach((function(e){g()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):w(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var m=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new Headers;r.set("Content-Type","application/json");var n=b({headers:r,method:"GET",credentials:"include"},e);return fetch(t,n)},O=function(t){var e=t.ok,r=t.status;return t.json().then((function(t){return{ok:e,status:r,body:t}}))},j="error",x=function(){var t=e()(c().mark((function t(e,r,n){var o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="ERROR MESSAGE: ".concat(n.message," \nSTACK: ").concat(n.stack?n.stack.substring(0,1e3):"-"),i="".concat(r,"\n").concat(o),y(i),t.next=5,E(j,e,i);case 5:case"end":return t.stop()}}),t)})));return function(e,r,n){return t.apply(this,arguments)}}(),P=function(){var t=e()(c().mark((function t(e,r){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return y(r),t.next=3,E(j,e,r);case 3:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),E=function(){var t=e()(c().mark((function t(e,r,n){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,m("".concat(r,"/nice2/log?level=").concat(e,"&message=").concat(encodeURI(n)),{method:"POST"});case 3:t.next=7;break;case 5:t.prev=5,t.t0=t.catch(0);case 7:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(e,r,n){return t.apply(this,arguments)}}(),k=function(t,e,r){try{var n=document.getElementById(e)||function(t){var e=document.createElement("style");return e.id=t,document.head.appendChild(e),e}(e);n.innerHTML=r}catch(e){x(t,"Could not apply global styles.",e)}},L=function(t,e,r){var n=r.map((function(t){return"[".concat("data-tocco-widget-ref",'="').concat(e,'"][').concat(h,'~="').concat(t,'"]')})).join(",\n"),o="".concat(n," {\n display: inherit;\n}");k(t,"".concat("tocco-visibility-status-styles","-").concat(e),o)};const S=function(t){var e=t.backendUrl,r="[".concat(h,"] {display: none;}");k(e,"tocco-initial-visibility-status-styles",r)};var _=r(813),D=r.n(_),T=r(8),N=r.n(T);function C(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function A(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?C(Object(r),!0).forEach((function(e){g()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var G=function(){var t=window.toccoTheme;if(t&&"object"===N()(t))return t},I=function(t){return t&&Object.keys(t).length>0&&"function"==typeof t[Object.keys(t)[0]]},M=function(t){var e=window.toccoEventHandlers;if(I(e))return e;if(e){var r=e[t];if(I(r))return r}return{}},U=function(t,e){window.toccoMethods=A(A({},window.toccoMethods),{},g()({},t,e))};function R(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function B(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?R(Object(r),!0).forEach((function(e){g()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):R(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var F=function(t){return t.getAttribute(l)},H=function(t,e,r){var n=e.ok,o=e.status,c=e.body;return n?e:(403===o&&"INVALID_DOMAIN"===(null==c?void 0:c.errorCode)&&P(t,c.message),void(404===o&&P(t,"Widget config '".concat(r,"' not found."))))},V=function(t,e,r){return function(){for(var n=arguments.length,o=new Array(n),c=0;c<n;c++)o[c]=arguments[c];var i=o[0].status;L(t,e,i),"function"==typeof r&&r.apply(void 0,o)}},z=function(){var t=e()(c().mark((function t(e,r,n){var o,i,a,u,p,l,h,d,y,v,g,w;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=F(n),t.next=3,m("".concat(e,"/nice2/rest/widget/configs/").concat(o)).then(O).then((function(t){return H(e,t,o)})).then((function(t){return null==t?void 0:t.body})).catch((function(t){x(e,"Could not fetch widget config '".concat(o,"'."),t)}));case 3:if(!(i=t.sent)){t.next=21;break}return a=i.appName,u=i.packageName,p=i.locale,l=i.config,t.prev=6,t.next=9,s("".concat(r).concat(f(u,a)));case 9:t.next=15;break;case 11:return t.prev=11,t.t0=t.catch(6),x(e,"Could not fetch package 'tocco-".concat(u,"'."),t.t0),t.abrupt("return");case 15:h=M(o),d=B(B({},h),{},{onVisibilityStatusChange:V(e,o,h.onVisibilityStatusChange)}),y=G(),v=B(B(B({backendUrl:e},y?{customTheme:y}:{}),{},{locale:p},l),{},{appContext:{embedType:"widget",widgetConfigKey:o}},d),g="".concat(r,"/js/tocco-").concat(u,"/dist/");try{w=window.reactRegistry.render(a,n,"",v,d,g),U(o,w)}catch(t){x(e,"Could not render app '".concat(a,"'."),t)}case 21:case"end":return t.stop()}}),t,null,[[6,11]])})));return function(e,r,n){return t.apply(this,arguments)}}(),K=function(t){var e=r(659).version,n=B({version:e},t),o=window.toccoBootstrap;return o?(d("tocco-widget-utils - bootstrap script is already initialized"),!D()(o,n)&&y("More than one bootstrap script with different settings has been found. Add only one bootstrap script per page.","\nInitialized bootstrap script:",o,"\nIgnored bootstrap script:",n),!1):(window.toccoBootstrap=n,d("tocco-widget-utils - v".concat(e," - bootstrap")),!0)},W=function(){var t=e()(c().mark((function t(e){var r,n,o,i;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(K(e)){t.next=3;break}return t.abrupt("return");case 3:return r=e.backendUrl,n=e.assetUrl,o=document.querySelectorAll("[".concat(l,"]")),i=Array.prototype.slice.call(o),t.next=8,Promise.all(i.map((function(t){return z(r,n,t)})));case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();const Y=W;var q,J;q=function(t){var e=t.currentScript.getAttribute("src");if(e.startsWith("http")){var r=new URL(e);return r.protocol+"//"+r.host}var n=window.location;return n.protocol+"//"+n.host}(document),J={backendUrl:window[p]?window[p]:q,assetUrl:q},S(J),document.addEventListener("DOMContentLoaded",e()(c().mark((function t(){return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s("".concat(q,"/nice2/javascript/nice2-react.release.js"));case 2:return t.next=4,Y(J);case 4:case"end":return t.stop()}}),t)}))))})(),n})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tocco-widget-utils",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "compile:prod": "cd ../../../ && npm run compile:prod -- --package=widget-utils",