@transitive-sdk/utils-web 0.6.0 → 0.6.2

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/client.js CHANGED
@@ -1,6 +1,9 @@
1
1
 
2
2
  // It is OK to use paths outside of this package because webpack will bundle them
3
3
  export * from '../common/common.js';
4
+ import MS from '../common/MqttSync.js';
5
+
6
+ export const MqttSync = MS;
4
7
 
5
8
  export const decodeJWT = (jwt) => JSON.parse(atob(jwt.split('.')[1]));
6
9
 
package/dist/utils-web.js CHANGED
@@ -1 +1 @@
1
- (()=>{var e={890:(e,t,n)=>{"use strict";function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}var c=n(362),u=c.DataCache,s=c.mqttParsePayload,l=c.pathMatch,f=c.topicToPath,p=c.pathToTopic,h=c.toFlatObject,d=c.getLogger,b=c.mergeVersions,y=c.parseMQTTTopic,v=c.isSubTopicOf,g=c.versionCompare,m=c.encodeTopicElement,w=n(517),O=d("MqttSync"),S="$SYS/broker/uptime",E=function(){},k=function(e){return e.endsWith("/#")?e:e.endsWith("/")?e.concat("#"):e.concat("/#")},T=function(e){return e.replace(/\/\//g,"/")},C=function(){function e(t){var n=this,r=t.mqttClient,o=t.onChange,a=t.ignoreRetain,c=t.migrate,l=t.onReady,h=t.sliceTopic;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"data",new u),i(this,"subscribedPaths",{}),i(this,"publishedPaths",{}),i(this,"publishedMessages",{}),i(this,"publishQueue",new Map),i(this,"heartbeatWaitersOnce",[]),i(this,"heartbeats",0),i(this,"beforeDisconnectHooks",[]),this.mqtt=r,this.mqtt.on("message",(function(e,t,r){var i=t&&t.toString();if(O.debug("got message",e,i.slice(0,180),i.length>180?"... (".concat(i.length," bytes)"):"",r.retain),e==S)n.heartbeats>0&&(n.heartbeatWaitersOnce.forEach((function(e){return e()})),n.heartbeatWaitersOnce=[]),1==n.heartbeats&&!c&&l&&l(),n.heartbeats++;else if(r.retain||a){O.debug("processing message",e),h&&(e=p(f(e).slice(h)));var u=s(t);if(n.isPublished(e))n.publishedMessages[e]=u,n.data.update(e,u,{external:!0});else if(n.isSubscribed(e)){O.debug("applying received update",e);var d=n.data.update(e,u);o&&Object.keys(d).length>0&&o(d)}}})),this.mqtt.subscribe(S,{rap:!0},O.debug),(null==c?void 0:c.length)>0&&this.migrate(c,(function(){O.debug("done migrating",l),l&&n.waitForHeartbeatOnce(l)}))}var t,n;return t=e,n=[{key:"publishAtLevel",value:function(e,t,n){var r=this;O.debug("publishingAtLevel ".concat(n),e,t),n>0?w.forEach(t,(function(t,o){var i="".concat(e,"/").concat(m(o));O.debug("publishing ".concat(i)),r.publishAtLevel(i,t,n-1)})):this.mqtt.publish(e,JSON.stringify(t),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result",e)}))}},{key:"migrate",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=e.length;if(0!=r){var o=function(){return 0==--r&&n&&n()};e.forEach((function(e){var n=e.topic,r=e.newVersion,i=e.transform,a=void 0===i?void 0:i,c=e.flat,u=void 0!==c&&c,s=e.level,l=void 0===s?0:s;O.debug("migrating",n,r);var d=y(n),v=d.organization,m=d.device,S=d.capability,E=d.sub,k="/".concat(v,"/").concat(m,"/").concat(S),C=0==E.length?"/#":p(E),j="".concat(k,"/+").concat(C);t.subscribe(j,(function(e){if(e)return O.warn("Error during migration",e),void o();t.waitForHeartbeatOnce((function(){O.debug("got heartbeat",n,j);var e=t.data.getByTopic(k);if(!e)return t.unsubscribe(j),void o();var i=b(e,C,{maxVersion:r}),c=w.get(i,f(C)),s=a?a(c):c,d=T("".concat(k,"/").concat(r,"/").concat(C));if(O.debug("publishing merged",d),u){var y=h(s),v=f(d);w.forEach(y,(function(e,n){var r=p(v.concat(f(n)));t.mqtt.publish(r,JSON.stringify(e),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result for ".concat(n),e)}))}))}else t.publishAtLevel(d,s,l);t.unsubscribe(j),t.waitForHeartbeatOnce((function(){var n=Object.keys(e).filter((function(e){return g(e,r)<0})).map((function(e){return T("".concat(k,"/").concat(e,"/").concat(C))}));O.debug({prefixesToClear:n}),t.clear(n),o()}))}))}))}))}else n&&n()}},{key:"clear",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=[],i=function(t){e.forEach((function(e){return l("".concat(e,"/#"),t)&&(!r.filter||r.filter(t))&&o.push(t)}))};this.mqtt.on("message",i),e.forEach((function(e){"string"==typeof e?t.mqtt.subscribe("".concat(e,"/#")):O.warn("Ignoring",e,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;this.waitForHeartbeatOnce((function(){t.mqtt.removeListener("message",i),e.forEach((function(e){return t.mqtt.unsubscribe("".concat(e,"/#"))}));var r=o.length;O.debug("clearing ".concat(r," retained messages from ").concat(e)),o.forEach((function(e){t.mqtt.publish(e,a,{retain:!0})})),n&&n(r)}))}},{key:"waitForHeartbeatOnce",value:function(e){var t=this;setTimeout((function(){return t.heartbeatWaitersOnce.push(e)}),1)}},{key:"isSubscribed",value:function(e){return Object.keys(this.subscribedPaths).some((function(t){return l(t,e)}))}},{key:"isPublished",value:function(e){var t=this;return Object.keys(this.publishedPaths).some((function(n){return l(n,e)&&!t.publishedPaths[n].atomic}))}},{key:"subscribe",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:E;if(e=k(e),this.subscribedPaths[e])return O.debug("already subscribed to",e),void n();this.mqtt.subscribe(e,{rap:!0},(function(r,o){O.debug("subscribe",e,"granted:",o),o&&o.some((function(t){return t.topic==e&&t.qos<128}))?(t.subscribedPaths[e]=1,n(null)):n("not permitted to subscribe to topic ".concat(e,", ").concat(JSON.stringify(o)))}))}},{key:"unsubscribe",value:function(e){this.subscribedPaths[e]&&(this.mqtt.unsubscribe(e),delete this.subscribedPaths[e])}},{key:"_actuallyPublish",value:function(e,t){return this.mqtt.connected?(O.debug("actually publishing",e),this.mqtt.publish(e,null==t?null:JSON.stringify(t),{retain:!0}),!0):(O.warn("not connected, not publishing",e),!1)}},{key:"_processQueue_rec",value:function(e){var t=this;if(this.publishQueue.size>0){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(this.publishQueue.entries().next().value,2),o=n[0],i=n[1];this._actuallyPublish(o,i)?(this.publishQueue.delete(o),this._processQueue_rec(e)):setTimeout((function(){return t._processQueue_rec(e)}),5e3)}else e()}},{key:"_processQueue",value:function(){var e=this;this._processing||(this._processing=!0,this._processQueue_rec((function(){return e._processing=!1})))}},{key:"setThrottle",value:function(e){this._processQueueThrottled=w.throttle(this._processQueue.bind(this),e)}},{key:"clearThrottle",value:function(){delete this._processQueueThrottled}},{key:"addToQueue",value:function(e,t){this.publishQueue.set(e,t)}},{key:"_enqueue",value:function(e,t){var n;O.debug("enqueuing",e),this.addToQueue(e,t),this._processQueueThrottled?this._processQueueThrottled():this._processQueue(),null==t?delete this.publishedMessages[e]:this.publishedMessages[e]="object"==a(n=t)?JSON.parse(JSON.stringify(n)):n}},{key:"publish",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{atomic:!1};return e=k(e),!w.isEqual(this.publishedPaths[e],n)&&(this.publishedPaths[e]=n,n.atomic?(this.data.subscribePath(e,(function(n,r,o,i){if(null==i||!i.external){O.debug("processing change (atomic)",r,e);var a=e.slice(0,e.length-2),c=p(f(r).slice(0,f(a).length));t._enqueue(c,t.data.getByTopic(c))}})),!0):(this.mqtt.subscribe(e),void this.data.subscribePath(e,(function(e,n,r,o){if(null==o||!o.external)return O.debug("processing change",n),w.each(t.publishedMessages,(function(e,r){if(O.trace("oldKey",r),r==n)return!0;if(v(r,n)&&t._enqueue(r,null),v(n,r)){t._enqueue(r,null);var o=h(e);w.each(o,(function(e,n){var o="".concat(r).concat(n);t._enqueue(o,e)}))}})),t._enqueue(n,e),!0}))))}},{key:"beforeDisconnect",value:function(){var e=this;this.beforeDisconnectHooks.forEach((function(t){return t(e)}))}},{key:"onBeforeDisconnect",value:function(e){this.beforeDisconnectHooks.push(e)}}],n&&o(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports=C},362:(e,t,n)=>{function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}function a(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,u(e,t,"get"))}function c(e,t,n){return function(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}(e,u(e,t,"set"),n),n}function u(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=n(13),f={get:n(712),set:n(298),unset:n(305),forEach:n(848),map:n(707),isEmpty:n(699),eq:n(113),isPlainObject:n(452),merge:n(831)},p=n(316),h=n(22),d=n(499);p.setAll=function(e){return Object.values(p.getLoggers()).forEach((function(t){return t.setLevel(e)}))};var b={warn:h.yellow,error:h.red,info:h.green,debug:h.gray},y=p.methodFactory;p.methodFactory=function(e,t,n){var r=y(e,t,n);if("undefined"!=typeof window){var o="".concat(n," ").concat(e);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(o,"]")].concat(t))}}var i,a="".concat(n," ").concat(b[i=e]?b[i](i):i);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(h.blue((new Date).toISOString())," ").concat(a,"]")].concat(t))}};var v=p.getLogger,g=function e(t,n){if(n&&0!=n.length){f.unset(t,n);var r=n.slice(0,-1),o=0==r.length?t:f.get(t,r);return f.isEmpty(o)?e(t,r):n}},m=function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return f.forEach(t,(function(t,o){var i=n.concat(String(o));(f.isPlainObject(t)||t instanceof Array)&&null!==t?e(t,i,r):r[k(i)]=t})),r},w=function e(t,n){if(0!=n.length){var r=n[0];if(r)for(var o in t)o==r||"*"==r||r.startsWith("+")?e(t[o],n.slice(1)):delete t[o]}},O=function e(t,n,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(0!=n.length&&"#"!=n[0]){var a=n[0];if(a)for(var c in t)if(c==a||"*"==a||a.startsWith("+")){var u=a.startsWith("+")&&a.length>1?Object.assign({},i,s({},a.slice(1),c)):i;e(t[c],n.slice(1),r,o.concat([c]),u)}}else r(t,o,i)},S=function(e){return e.replace(/%/g,"%25").replace(/\//g,"%2F")},E=function(e){return e.replace(/%25/g,"%").replace(/%2F/g,"/")},k=function(e){return"/".concat(e.map((function(e){return e.startsWith("+")?"+":e})).map(S).join("/"))},T=function(e){var t=e.split("/").map(E);return t.length>0&&0==t[0].length&&t.shift(),t.length>0&&0==t.at(-1).length&&t.pop(),t},C=function(e,t){return function e(t,n){if(0==t.length)return!0;if("#"==t[0][0])return!0;if(0==n.length)return!0;if(t[0]==n[0])return e(t.slice(1),n.slice(1));if("+"==t[0][0]){var r=e(t.slice(1),n.slice(1));return r&&Object.assign(s({},t[0].slice(1),n[0]),r)}return!1}(T(e),T(t))},j=function e(t,n){return 0==t.length||t[0]==n[0]&&e(t.slice(1),n.slice(1))},P=new WeakMap,q=new WeakMap,x=new WeakMap,_=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),i(this,P,{writable:!0,value:{}}),i(this,q,{writable:!0,value:[]}),i(this,x,{writable:!0,value:[]}),c(this,P,t)}var t,n;return t=e,n=[{key:"updateFromArray",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=f.get(a(this,P),e);if(null==t){if(null==r)return{};g(a(this,P),e)}else{if(f.eq(r,t))return{};f.set(a(this,P),e,t)}var o,i=k(e),c=s({},i,t);if(t instanceof Object){var u=m(t);o={},f.forEach(u,(function(e,t){o["".concat(i).concat(t)]=e}))}else o=c;return a(this,q).forEach((function(e){return e(c,n)})),a(this,x).forEach((function(e){return e(o,n)})),o}},{key:"update",value:function(e,t,n){if("string"==typeof e)return this.updateFromTopic(e,t,n);if(e instanceof Array)return this.updateFromArray(e,t,n);throw new Error("unrecognized path expression")}},{key:"updateFromTopic",value:function(e,t,n){return this.updateFromArray(T(e),t,n)}},{key:"updateFromModifier",value:function(e,t){var n=this;return f.map(e,(function(e,r){return n.updateFromTopic(r,e,t)}))}},{key:"subscribe",value:function(e){e instanceof Function?a(this,q).push(e):console.warn("DataCache.subscribe expects a function as argument. Did you mean to use subscribePath?")}},{key:"subscribePath",value:function(e,t){a(this,q).push((function(n,r){f.forEach(n,(function(n,o){var i=C(e,o);i&&t(n,o,i,r)}))}))}},{key:"subscribePathFlat",value:function(e,t){a(this,x).push((function(n,r){f.forEach(n,(function(n,o){var i=C(e,o);i&&t(n,o,i,r)}))}))}},{key:"unsubscribe",value:function(e){c(this,q,a(this,q).filter((function(t){return t!=e})))}},{key:"get",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return 0==e.length?a(this,P):f.get(a(this,P),e)}},{key:"getByTopic",value:function(e){return this.get(T(e))}},{key:"filter",value:function(e){var t=JSON.parse(JSON.stringify(this.get()));return w(t,e),t}},{key:"filterByTopic",value:function(e){return this.filter(T(e))}},{key:"forMatch",value:function(e,t){var n=T(e);this.forPathMatch(n,t)}},{key:"forPathMatch",value:function(e,t){O(this.get(),e,t)}}],n&&o(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),A=function(e,t){return function e(t,n){return 0==n.length&&0==t.length||!(0==n.length&&t.length>0)&&("#"==n[0]||!(n.length>0&&0==t.length)&&("+"==n[0]||n[0]==t[0])&&e(t.slice(1),n.slice(1)))}(T(e),T(t))},M=l;e.exports={parseMQTTUsername:function(e){var t=e.split(":");return{organization:t[0],client:t[1],sub:t.slice(2)}},parseMQTTTopic:function(e){var t=T(e);return{organization:t[0],device:t[1],capabilityScope:t[2],capabilityName:t[3],capability:"".concat(t[2],"/").concat(t[3]),version:t[4],sub:t.slice(5)}},updateObject:function(e,t){return f.forEach(t,(function(t,n){var r=T(n);null==t?g(e,r):f.set(e,r,t)})),e},DataCache:_,pathToTopic:k,topicToPath:T,toFlatObject:m,mqttTopicMatch:A,pathMatch:C,mqttParsePayload:function(e){return 0==e.length?null:JSON.parse(e.toString("utf-8"))},getRandomId:function(){return Math.random().toString(36).slice(2)},versionCompare:M,loglevel:p,getLogger:v,mergeVersions:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e)return t?f.set({},t,e):e;var r=Object.keys(e).filter((function(e){return(!n.maxVersion||M(e,n.maxVersion)<=0)&&(!n.minVersion||M(n.minVersion,e)<=0)})).sort(M),o={},i=t&&T(t);return r.forEach((function(t){var n=i?f.get(e[t],i):e[t];f.merge(o,n)})),i?f.set({},i,o):o},mqttClearRetained:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,o=[],i=function(e){t.forEach((function(t){return A(e,"".concat(t,"/#"))&&o.push(e)}))};e.on("message",i),t.forEach((function(t){"string"==typeof t?e.subscribe("".concat(t,"/#")):console.warn("Ignoring",t,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;setTimeout((function(){e.removeListener("message",i),t.forEach((function(t){return e.unsubscribe("".concat(t,"/#"))}));var r=o.length;console.log("clearing ".concat(r," retained messages from ").concat(t)),o.forEach((function(t){e.publish(t,a,{retain:!0})})),n&&n(r)}),r)},isSubTopicOf:function(e,t){var n=T(t),r=T(e);return j(n,r)&&n.length<r.length},clone:function(e){return JSON.parse(JSON.stringify(e))},setFromPath:function e(t,n,r){if(0==n.length)return t;var o=n.shift();0==n.length?t[o]=r:(t[o]||(t[o]={}),e(t[o],n,r))},forMatchIterator:O,encodeTopicElement:S,decodeTopicElement:E,constants:d,visit:function e(t,n,r){var o;t&&(r(t),null===(o=t[n])||void 0===o||o.forEach((function(t){return e(t,n,r)})))}}},499:e=>{e.exports={rosReleases:{kinetic:{rosVersion:1,ubuntuCodename:"xenial"},melodic:{rosVersion:1,ubuntuCodename:"bionic"},noetic:{rosVersion:1,ubuntuCodename:"focal"},rolling:{rosVersion:2},humble:{rosVersion:2},galactic:{rosVersion:2},foxy:{rosVersion:2},eloquent:{rosVersion:2},dashing:{rosVersion:2}}}},368:(e,t,n)=>{"use strict";n.r(t),n.d(t,{decodeJWT:()=>i,fetchJson:()=>c,parseCookie:()=>a});var r=n(362),o={};for(const e in r)["default","decodeJWT","parseCookie","fetchJson"].indexOf(e)<0&&(o[e]=()=>r[e]);n.d(t,o);var i=function(e){return JSON.parse(atob(e.split(".")[1]))},a=function(e){return e.split(";").map((function(e){return e.split("=")})).reduce((function(e,t){return e[decodeURIComponent(t[0].trim())]=t[1]&&decodeURIComponent(t[1].trim()),e}),{})},c=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};fetch(e,{method:n.method||(n.body?"post":"get"),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer",body:n.body?JSON.stringify(n.body):void 0}).then((function(t){if(!t.ok)throw new Error("fetching ".concat(e," failed: ").concat(t.status," ").concat(t.statusText));return t.json()})).then((function(e){return t(null,e)})).catch((function(e){return t("error: ".concat(e))}))}},442:(e,t,n)=>{"use strict";n.d(t,{H:()=>p});var r=n(689),o=n.n(r),i=n(368);const a=require("mqtt-browser");var c=n.n(a);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var l=n(890),f=(0,i.getLogger)("utils-web/hooks"),p=function(e){var t=e.jwt,n=e.id,a=e.mqttUrl,s=u((0,r.useState)("connecting"),2),p=s[0],h=s[1],d=u((0,r.useState)(),2),b=d[0],y=d[1],v=u((0,r.useState)({}),2),g=v[0],m=v[1];return(0,r.useEffect)((function(){var e=(0,i.decodeJWT)(t),r=c().connect(a,{username:JSON.stringify({id:n,payload:e}),password:t});return r.on("connect",(function(){f.debug("connected");var e=new l({mqttClient:r,ignoreRetain:!0});y(e),h("connected"),e.data.subscribe((function(){return m((0,i.clone)(e.data.get()))}))})),r.on("error",(function(e){f.error(e),h("error: ".concat(e))})),function(){f.info("cleaning up useMQTTSync"),b&&b.beforeDisconnect?(b.beforeDisconnect(),b.waitForHeartbeatOnce((function(){return r.end()}))):r.end()}}),[t,n]),{status:p,ready:"connected"==p,StatusComponent:function(){return o().createElement("div",null,p)},mqttSync:b,data:g}}},335:e=>{function t(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}e.exports=function(e){if(!e.attributes)return{};var r,o,i,a={},c=(i=e.attributes,function(e){if(Array.isArray(e))return n(e)}(i)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(i)||t(i)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}({},e.name,e.value)})),u=function(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=t(e))){r&&(e=r);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){u=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}(c);try{for(u.s();!(o=u.n()).done;){r=o.value;var s=Object.keys(r)[0];a[s.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))]=r[s]}}catch(e){u.e(e)}finally{u.f()}return a}},899:(e,t,n)=>{e.exports=function(){try{return n(962).styleElements}catch(e){return[]}}},271:(e,t,n)=>{function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}function u(e){var t=p();return function(){var n,r=d(e);if(t){var o=d(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}function s(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){var t="function"==typeof Map?new Map:void 0;return l=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return f(e,arguments,d(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),h(r,e)},l(e)}function f(e,t,n){return f=p()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&h(o,n.prototype),o},f.apply(null,arguments)}function p(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function h(e,t){return h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},h(e,t)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}var b=n(689),y=n(405),v=n(430),g=n(899),m=n(335);n(622),n(268),e.exports={create:function(e,t){var n,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],s={attachedCallback:"webComponentAttached",connectedCallback:"webComponentConnected",disconnectedCallback:"webComponentDisconnected",attributeChangedCallback:"webComponentAttributeChanged",adoptedCallback:"webComponentAdopted"};function f(e){n.webComponentConstructed&&n.webComponentConstructed.apply(n,[e])}function p(e,t){var r=t||[],o=s[e];o&&n&&n[o]&&n[o].apply(n,r)}var h=function(t){c(l,t);var s=u(l);function l(){return o(this,l),s.apply(this,arguments)}return a(l,[{key:"connectedCallback",value:function(){var t=this,o=t;if(r){var i=t.attachShadow({mode:"open"});o=document.createElement("div"),g().forEach((function(e){i.appendChild(e.cloneNode(i))})),i.appendChild(o),v(i)}y.render(b.cloneElement(e,m(t)),o,(function(){n=this,f(t),p("connectedCallback")}))}},{key:"disconnectedCallback",value:function(){p("disconnectedCallback")}},{key:"attributeChangedCallback",value:function(e,t,n,r){p("attributeChangedCallback",[e,t,n,r])}},{key:"adoptedCallback",value:function(e,t){p("adoptedCallback",[e,t])}}],[{key:"observedAttributes",get:function(){return i}}]),l}(l(HTMLElement));customElements.define(t,h)}}},11:(e,t,n)=>{"use strict";n.d(t,{EK:()=>T,ZM:()=>C,U5:()=>k,B7:()=>P,eZ:()=>q});var r=n(689),o=n.n(r);const i=require("react-bootstrap");var a=n(271),c=n.n(a);function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function s(){return s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(this,arguments)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function p(e,t,n){return t&&f(e.prototype,t),n&&f(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function h(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function b(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=g(e);if(t){var o=g(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return y(this,n)}}function y(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return v(e)}function v(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function w(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return O(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}n(368);var S={badge:{width:"4em"},code:{color:"#700",borderLeft:"3px solid #aaa",padding:"0.5em 0px 0.5em 2em",backgroundColor:"#f0f0f0",borderRadius:"4px",marginTop:"0.5em"},inlineCode:{color:"#700",margin:"0px 0.5em 0px 0.5em"}},E=[o().createElement(i.Badge,{bg:"success",style:S.badge},"OK"),o().createElement(i.Badge,{bg:"warning",style:S.badge},"Warn"),o().createElement(i.Badge,{bg:"danger",style:S.badge},"Error"),o().createElement(i.Badge,{bg:"secondary",style:S.badge},"Stale")],k=function(e){var t=e.level;return E[t]||o().createElement("span",null,t)},T=function(e){var t=e.children;return o().createElement("pre",{style:S.code},t)},C=function(e){var t=e.children;return o().createElement("tt",{style:S.inlineCode},t)},j={},P=function(e){var t=e.duration,n=e.onTimeout,a=e.onStart,c=e.setOnDisconnect,u=e.children;t=t||60;var s=w((0,r.useState)(t),2),l=s[0],f=s[1],p=w((0,r.useState)(!1),2),h=p[0],d=p[1],b=(0,r.useMemo)((function(){return Math.random().toString(36).slice(2)}),[]),y=function(){console.log("stopping timer for",b),n&&setTimeout(n,1),clearInterval(j[b]),j[b]=null,d(!1)};(0,r.useEffect)((function(){var e;l>0&&!h&&(e=j[b],console.log(e,j,l),!e&&l>0&&(d(!0),j[b]=setInterval((function(){return f((function(e){if(--e>0)return e;y()}))}),1e3),a&&setTimeout(a,1)))}),[l]),(0,r.useEffect)((function(){return y}),[]),c&&c((function(){y()}));var v=function(){return f(t)};return l>0?o().createElement("div",null,o().Children.map(u,(function(e){return o().cloneElement(e,{resetTimer:v})})),l<.5*t&&o().createElement("div",null,"Timeout in: ",l," seconds")):o().createElement("div",null,"Timed out. ",o().createElement(i.Button,{onClick:v},"Resume"))},q=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"0.0.0",i=function(n){h(a,n);var i=b(a);function a(){var e;l(this,a);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return m(v(e=i.call.apply(i,[this].concat(n))),"onDisconnect",null),m(v(e),"state",{}),e}return p(a,[{key:"setOnDisconnect",value:function(e){this.onDisconnect=e}},{key:"webComponentDisconnected",value:function(){this.onDisconnect&&this.onDisconnect(),this.setState({_disconnected:!0})}},{key:"webComponentAttributeChanged",value:function(e,t,n){var r=this.state;r[e]=n,this.setState(r)}},{key:"render",value:function(){return o().createElement("div",{id:"cap-".concat(t,"-").concat(r)},o().createElement("style",null,'@import url("https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css");'),!this.state._disconnected&&o().createElement(e,s({},this.state,this.props,{setOnDisconnect:this.setOnDisconnect.bind(this)})))}}]),a}(o().Component);c().create(o().createElement(i,null),t,!1,n)}},268:e=>{"use strict";e.exports=require("@webcomponents/custom-elements")},622:e=>{"use strict";e.exports=require("@webcomponents/shadydom")},22:e=>{"use strict";e.exports=require("chalk")},517:e=>{"use strict";e.exports=require("lodash")},848:e=>{"use strict";e.exports=require("lodash/forEach")},712:e=>{"use strict";e.exports=require("lodash/get")},699:e=>{"use strict";e.exports=require("lodash/isEmpty")},113:e=>{"use strict";e.exports=require("lodash/isEqual")},452:e=>{"use strict";e.exports=require("lodash/isPlainObject")},707:e=>{"use strict";e.exports=require("lodash/map")},831:e=>{"use strict";e.exports=require("lodash/merge")},298:e=>{"use strict";e.exports=require("lodash/set")},305:e=>{"use strict";e.exports=require("lodash/unset")},316:e=>{"use strict";e.exports=require("loglevel")},689:e=>{"use strict";e.exports=require("react")},405:e=>{"use strict";e.exports=require("react-dom")},430:e=>{"use strict";e.exports=require("react-shadow-dom-retarget-events")},962:e=>{"use strict";e.exports=require("react-web-component-style-loader/exports")},13:e=>{"use strict";e.exports=require("semver/functions/compare")}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{Code:()=>e.EK,InlineCode:()=>e.ZM,LevelBadge:()=>e.U5,Timer:()=>e.B7,createWebComponent:()=>e.eZ,useMqttSync:()=>t.H});var e=n(11),t=n(442),o=n(368),i={};for(const e in o)["default","Code","InlineCode","LevelBadge","Timer","createWebComponent","useMqttSync"].indexOf(e)<0&&(i[e]=()=>o[e]);n.d(r,i)})();var o=exports;for(var i in r)o[i]=r[i];r.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
1
+ (()=>{var e={890:(e,t,n)=>{"use strict";function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}var c=n(362),u=c.DataCache,s=c.mqttParsePayload,l=c.pathMatch,f=c.topicToPath,h=c.pathToTopic,p=c.toFlatObject,d=c.getLogger,b=c.mergeVersions,y=c.parseMQTTTopic,v=c.isSubTopicOf,g=c.versionCompare,m=c.encodeTopicElement,w=n(517),O=d("MqttSync"),S="$SYS/broker/uptime",E=function(){},k=function(e){return e.endsWith("/#")?e:e.endsWith("/")?e.concat("#"):e.concat("/#")},C=function(e){return e.replace(/\/\//g,"/")},T=function(){function e(t){var n=this,r=t.mqttClient,o=t.onChange,a=t.ignoreRetain,c=t.migrate,l=t.onReady,p=t.sliceTopic;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"data",new u),i(this,"subscribedPaths",{}),i(this,"publishedPaths",{}),i(this,"publishedMessages",{}),i(this,"publishQueue",new Map),i(this,"heartbeatWaitersOnce",[]),i(this,"heartbeats",0),i(this,"beforeDisconnectHooks",[]),this.mqtt=r,this.mqtt.on("message",(function(e,t,r){var i=t&&t.toString();if(O.debug("got message",e,i.slice(0,180),i.length>180?"... (".concat(i.length," bytes)"):"",r.retain),e==S)n.heartbeats>0&&(n.heartbeatWaitersOnce.forEach((function(e){return e()})),n.heartbeatWaitersOnce=[]),1==n.heartbeats&&!c&&l&&l(),n.heartbeats++;else if(r.retain||a){O.debug("processing message",e),p&&(e=h(f(e).slice(p)));var u=s(t);if(n.isPublished(e))n.publishedMessages[e]=u,n.data.update(e,u,{external:!0});else if(n.isSubscribed(e)){O.debug("applying received update",e);var d=n.data.update(e,u);o&&Object.keys(d).length>0&&o(d)}}})),this.mqtt.subscribe(S,{rap:!0},O.debug),(null==c?void 0:c.length)>0&&this.migrate(c,(function(){O.debug("done migrating",l),l&&n.waitForHeartbeatOnce(l)}))}var t,n;return t=e,n=[{key:"publishAtLevel",value:function(e,t,n){var r=this;O.debug("publishingAtLevel ".concat(n),e,t),n>0?w.forEach(t,(function(t,o){var i="".concat(e,"/").concat(m(o));O.debug("publishing ".concat(i)),r.publishAtLevel(i,t,n-1)})):this.mqtt.publish(e,JSON.stringify(t),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result",e)}))}},{key:"migrate",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=e.length;if(0!=r){var o=function(){return 0==--r&&n&&n()};e.forEach((function(e){var n=e.topic,r=e.newVersion,i=e.transform,a=void 0===i?void 0:i,c=e.flat,u=void 0!==c&&c,s=e.level,l=void 0===s?0:s;O.debug("migrating",n,r);var d=y(n),v=d.organization,m=d.device,S=d.capability,E=d.sub,k="/".concat(v,"/").concat(m,"/").concat(S),T=0==E.length?"/#":h(E),j="".concat(k,"/+").concat(T);t.subscribe(j,(function(e){if(e)return O.warn("Error during migration",e),void o();t.waitForHeartbeatOnce((function(){O.debug("got heartbeat",n,j);var e=t.data.getByTopic(k);if(!e)return t.unsubscribe(j),void o();var i=b(e,T,{maxVersion:r}),c=w.get(i,f(T)),s=a?a(c):c,d=C("".concat(k,"/").concat(r,"/").concat(T));if(O.debug("publishing merged",d),u){var y=p(s),v=f(d);w.forEach(y,(function(e,n){var r=h(v.concat(f(n)));t.mqtt.publish(r,JSON.stringify(e),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result for ".concat(n),e)}))}))}else t.publishAtLevel(d,s,l);t.unsubscribe(j),t.waitForHeartbeatOnce((function(){var n=Object.keys(e).filter((function(e){return g(e,r)<0})).map((function(e){return C("".concat(k,"/").concat(e,"/").concat(T))}));O.debug({prefixesToClear:n}),t.clear(n),o()}))}))}))}))}else n&&n()}},{key:"clear",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=[],i=function(t){e.forEach((function(e){return l("".concat(e,"/#"),t)&&(!r.filter||r.filter(t))&&o.push(t)}))};this.mqtt.on("message",i),e.forEach((function(e){"string"==typeof e?t.mqtt.subscribe("".concat(e,"/#")):O.warn("Ignoring",e,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;this.waitForHeartbeatOnce((function(){t.mqtt.removeListener("message",i),e.forEach((function(e){return t.mqtt.unsubscribe("".concat(e,"/#"))}));var r=o.length;O.debug("clearing ".concat(r," retained messages from ").concat(e)),o.forEach((function(e){t.mqtt.publish(e,a,{retain:!0})})),n&&n(r)}))}},{key:"waitForHeartbeatOnce",value:function(e){var t=this;setTimeout((function(){return t.heartbeatWaitersOnce.push(e)}),1)}},{key:"isSubscribed",value:function(e){return Object.keys(this.subscribedPaths).some((function(t){return l(t,e)}))}},{key:"isPublished",value:function(e){var t=this;return Object.keys(this.publishedPaths).some((function(n){return l(n,e)&&!t.publishedPaths[n].atomic}))}},{key:"subscribe",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:E;if(e=k(e),this.subscribedPaths[e])return O.debug("already subscribed to",e),void n();this.mqtt.subscribe(e,{rap:!0},(function(r,o){O.debug("subscribe",e,"granted:",o),o&&o.some((function(t){return t.topic==e&&t.qos<128}))?(t.subscribedPaths[e]=1,n(null)):n("not permitted to subscribe to topic ".concat(e,", ").concat(JSON.stringify(o)))}))}},{key:"unsubscribe",value:function(e){this.subscribedPaths[e]&&(this.mqtt.unsubscribe(e),delete this.subscribedPaths[e])}},{key:"_actuallyPublish",value:function(e,t){return this.mqtt.connected?(O.debug("actually publishing",e),this.mqtt.publish(e,null==t?null:JSON.stringify(t),{retain:!0}),!0):(O.warn("not connected, not publishing",e),!1)}},{key:"_processQueue_rec",value:function(e){var t=this;if(this.publishQueue.size>0){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(this.publishQueue.entries().next().value,2),o=n[0],i=n[1];this._actuallyPublish(o,i)?(this.publishQueue.delete(o),this._processQueue_rec(e)):setTimeout((function(){return t._processQueue_rec(e)}),5e3)}else e()}},{key:"_processQueue",value:function(){var e=this;this._processing||(this._processing=!0,this._processQueue_rec((function(){return e._processing=!1})))}},{key:"setThrottle",value:function(e){this._processQueueThrottled=w.throttle(this._processQueue.bind(this),e)}},{key:"clearThrottle",value:function(){delete this._processQueueThrottled}},{key:"addToQueue",value:function(e,t){this.publishQueue.set(e,t)}},{key:"_enqueue",value:function(e,t){var n;O.debug("enqueuing",e),this.addToQueue(e,t),this._processQueueThrottled?this._processQueueThrottled():this._processQueue(),null==t?delete this.publishedMessages[e]:this.publishedMessages[e]="object"==a(n=t)?JSON.parse(JSON.stringify(n)):n}},{key:"publish",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{atomic:!1};return e=k(e),!w.isEqual(this.publishedPaths[e],n)&&(this.publishedPaths[e]=n,n.atomic?(this.data.subscribePath(e,(function(n,r,o,i){if(null==i||!i.external){O.debug("processing change (atomic)",r,e);var a=e.slice(0,e.length-2),c=h(f(r).slice(0,f(a).length));t._enqueue(c,t.data.getByTopic(c))}})),!0):(this.mqtt.subscribe(e),void this.data.subscribePath(e,(function(e,n,r,o){if(null==o||!o.external)return O.debug("processing change",n),w.each(t.publishedMessages,(function(e,r){if(O.trace("oldKey",r),r==n)return!0;if(v(r,n)&&t._enqueue(r,null),v(n,r)){t._enqueue(r,null);var o=p(e);w.each(o,(function(e,n){var o="".concat(r).concat(n);t._enqueue(o,e)}))}})),t._enqueue(n,e),!0}))))}},{key:"beforeDisconnect",value:function(){var e=this;this.beforeDisconnectHooks.forEach((function(t){return t(e)}))}},{key:"onBeforeDisconnect",value:function(e){this.beforeDisconnectHooks.push(e)}}],n&&o(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports=T},362:(e,t,n)=>{function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}function a(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,u(e,t,"get"))}function c(e,t,n){return function(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}(e,u(e,t,"set"),n),n}function u(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=n(13),f={get:n(712),set:n(298),unset:n(305),forEach:n(848),map:n(707),isEmpty:n(699),eq:n(113),isPlainObject:n(452),merge:n(831)},h=n(316),p=n(22),d=n(499);h.setAll=function(e){return Object.values(h.getLoggers()).forEach((function(t){return t.setLevel(e)}))};var b={warn:p.yellow,error:p.red,info:p.green,debug:p.gray},y=h.methodFactory;h.methodFactory=function(e,t,n){var r=y(e,t,n);if("undefined"!=typeof window){var o="".concat(n," ").concat(e);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(o,"]")].concat(t))}}var i,a="".concat(n," ").concat(b[i=e]?b[i](i):i);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(p.blue((new Date).toISOString())," ").concat(a,"]")].concat(t))}};var v=h.getLogger,g=function e(t,n){if(n&&0!=n.length){f.unset(t,n);var r=n.slice(0,-1),o=0==r.length?t:f.get(t,r);return f.isEmpty(o)?e(t,r):n}},m=function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return f.forEach(t,(function(t,o){var i=n.concat(String(o));(f.isPlainObject(t)||t instanceof Array)&&null!==t?e(t,i,r):r[k(i)]=t})),r},w=function e(t,n){if(0!=n.length){var r=n[0];if(r)for(var o in t)o==r||"*"==r||r.startsWith("+")?e(t[o],n.slice(1)):delete t[o]}},O=function e(t,n,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(0!=n.length&&"#"!=n[0]){var a=n[0];if(a)for(var c in t)if(c==a||"*"==a||a.startsWith("+")){var u=a.startsWith("+")&&a.length>1?Object.assign({},i,s({},a.slice(1),c)):i;e(t[c],n.slice(1),r,o.concat([c]),u)}}else r(t,o,i)},S=function(e){return e.replace(/%/g,"%25").replace(/\//g,"%2F")},E=function(e){return e.replace(/%25/g,"%").replace(/%2F/g,"/")},k=function(e){return"/".concat(e.map((function(e){return e.startsWith("+")?"+":e})).map(S).join("/"))},C=function(e){var t=e.split("/").map(E);return t.length>0&&0==t[0].length&&t.shift(),t.length>0&&0==t.at(-1).length&&t.pop(),t},T=function(e,t){return function e(t,n){if(0==t.length)return!0;if("#"==t[0][0])return!0;if(0==n.length)return!0;if(t[0]==n[0])return e(t.slice(1),n.slice(1));if("+"==t[0][0]){var r=e(t.slice(1),n.slice(1));return r&&Object.assign(s({},t[0].slice(1),n[0]),r)}return!1}(C(e),C(t))},j=function e(t,n){return 0==t.length||t[0]==n[0]&&e(t.slice(1),n.slice(1))},x=new WeakMap,P=new WeakMap,q=new WeakMap,_=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),i(this,x,{writable:!0,value:{}}),i(this,P,{writable:!0,value:[]}),i(this,q,{writable:!0,value:[]}),c(this,x,t)}var t,n;return t=e,n=[{key:"updateFromArray",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=f.get(a(this,x),e);if(null==t){if(null==r)return{};g(a(this,x),e)}else{if(f.eq(r,t))return{};f.set(a(this,x),e,t)}var o,i=k(e),c=s({},i,t);if(t instanceof Object){var u=m(t);o={},f.forEach(u,(function(e,t){o["".concat(i).concat(t)]=e}))}else o=c;return a(this,P).forEach((function(e){return e(c,n)})),a(this,q).forEach((function(e){return e(o,n)})),o}},{key:"update",value:function(e,t,n){if("string"==typeof e)return this.updateFromTopic(e,t,n);if(e instanceof Array)return this.updateFromArray(e,t,n);throw new Error("unrecognized path expression")}},{key:"updateFromTopic",value:function(e,t,n){return this.updateFromArray(C(e),t,n)}},{key:"updateFromModifier",value:function(e,t){var n=this;return f.map(e,(function(e,r){return n.updateFromTopic(r,e,t)}))}},{key:"subscribe",value:function(e){e instanceof Function?a(this,P).push(e):console.warn("DataCache.subscribe expects a function as argument. Did you mean to use subscribePath?")}},{key:"subscribePath",value:function(e,t){a(this,P).push((function(n,r){f.forEach(n,(function(n,o){var i=T(e,o);i&&t(n,o,i,r)}))}))}},{key:"subscribePathFlat",value:function(e,t){a(this,q).push((function(n,r){f.forEach(n,(function(n,o){var i=T(e,o);i&&t(n,o,i,r)}))}))}},{key:"unsubscribe",value:function(e){c(this,P,a(this,P).filter((function(t){return t!=e})))}},{key:"get",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return 0==e.length?a(this,x):f.get(a(this,x),e)}},{key:"getByTopic",value:function(e){return this.get(C(e))}},{key:"filter",value:function(e){var t=JSON.parse(JSON.stringify(this.get()));return w(t,e),t}},{key:"filterByTopic",value:function(e){return this.filter(C(e))}},{key:"forMatch",value:function(e,t){var n=C(e);this.forPathMatch(n,t)}},{key:"forPathMatch",value:function(e,t){O(this.get(),e,t)}}],n&&o(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),A=function(e,t){return function e(t,n){return 0==n.length&&0==t.length||!(0==n.length&&t.length>0)&&("#"==n[0]||!(n.length>0&&0==t.length)&&("+"==n[0]||n[0]==t[0])&&e(t.slice(1),n.slice(1)))}(C(e),C(t))},M=l;e.exports={parseMQTTUsername:function(e){var t=e.split(":");return{organization:t[0],client:t[1],sub:t.slice(2)}},parseMQTTTopic:function(e){var t=C(e);return{organization:t[0],device:t[1],capabilityScope:t[2],capabilityName:t[3],capability:"".concat(t[2],"/").concat(t[3]),version:t[4],sub:t.slice(5)}},updateObject:function(e,t){return f.forEach(t,(function(t,n){var r=C(n);null==t?g(e,r):f.set(e,r,t)})),e},DataCache:_,pathToTopic:k,topicToPath:C,toFlatObject:m,mqttTopicMatch:A,pathMatch:T,mqttParsePayload:function(e){return 0==e.length?null:JSON.parse(e.toString("utf-8"))},getRandomId:function(){return Math.random().toString(36).slice(2)},versionCompare:M,loglevel:h,getLogger:v,mergeVersions:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e)return t?f.set({},t,e):e;var r=Object.keys(e).filter((function(e){return(!n.maxVersion||M(e,n.maxVersion)<=0)&&(!n.minVersion||M(n.minVersion,e)<=0)})).sort(M),o={},i=t&&C(t);return r.forEach((function(t){var n=i?f.get(e[t],i):e[t];f.merge(o,n)})),i?f.set({},i,o):o},mqttClearRetained:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,o=[],i=function(e){t.forEach((function(t){return A(e,"".concat(t,"/#"))&&o.push(e)}))};e.on("message",i),t.forEach((function(t){"string"==typeof t?e.subscribe("".concat(t,"/#")):console.warn("Ignoring",t,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;setTimeout((function(){e.removeListener("message",i),t.forEach((function(t){return e.unsubscribe("".concat(t,"/#"))}));var r=o.length;console.log("clearing ".concat(r," retained messages from ").concat(t)),o.forEach((function(t){e.publish(t,a,{retain:!0})})),n&&n(r)}),r)},isSubTopicOf:function(e,t){var n=C(t),r=C(e);return j(n,r)&&n.length<r.length},clone:function(e){return JSON.parse(JSON.stringify(e))},setFromPath:function e(t,n,r){if(0==n.length)return t;var o=n.shift();0==n.length?t[o]=r:(t[o]||(t[o]={}),e(t[o],n,r))},forMatchIterator:O,encodeTopicElement:S,decodeTopicElement:E,constants:d,visit:function e(t,n,r){var o;t&&(r(t),null===(o=t[n])||void 0===o||o.forEach((function(t){return e(t,n,r)})))}}},499:e=>{e.exports={rosReleases:{kinetic:{rosVersion:1,ubuntuCodename:"xenial"},melodic:{rosVersion:1,ubuntuCodename:"bionic"},noetic:{rosVersion:1,ubuntuCodename:"focal"},rolling:{rosVersion:2},humble:{rosVersion:2},galactic:{rosVersion:2},foxy:{rosVersion:2},eloquent:{rosVersion:2},dashing:{rosVersion:2}}}},368:(e,t,n)=>{"use strict";n.r(t),n.d(t,{MqttSync:()=>a,decodeJWT:()=>c,fetchJson:()=>s,parseCookie:()=>u});var r=n(362),o={};for(const e in r)["default","MqttSync","decodeJWT","parseCookie","fetchJson"].indexOf(e)<0&&(o[e]=()=>r[e]);n.d(t,o);var i=n(890),a=n.n(i)(),c=function(e){return JSON.parse(atob(e.split(".")[1]))},u=function(e){return e.split(";").map((function(e){return e.split("=")})).reduce((function(e,t){return e[decodeURIComponent(t[0].trim())]=t[1]&&decodeURIComponent(t[1].trim()),e}),{})},s=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};fetch(e,{method:n.method||(n.body?"post":"get"),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer",body:n.body?JSON.stringify(n.body):void 0}).then((function(t){if(!t.ok)throw new Error("fetching ".concat(e," failed: ").concat(t.status," ").concat(t.statusText));return t.json()})).then((function(e){return t(null,e)})).catch((function(e){return t("error: ".concat(e))}))}},442:(e,t,n)=>{"use strict";n.d(t,{H:()=>h});var r=n(689),o=n.n(r),i=n(368);const a=require("mqtt-browser");var c=n.n(a);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var l=n(890),f=(0,i.getLogger)("utils-web/hooks"),h=function(e){var t=e.jwt,n=e.id,a=e.mqttUrl,s=u((0,r.useState)("connecting"),2),h=s[0],p=s[1],d=u((0,r.useState)(),2),b=d[0],y=d[1],v=u((0,r.useState)({}),2),g=v[0],m=v[1];return(0,r.useEffect)((function(){var e=(0,i.decodeJWT)(t),r=c().connect(a,{username:JSON.stringify({id:n,payload:e}),password:t});return r.on("connect",(function(){f.debug("connected");var e=new l({mqttClient:r,ignoreRetain:!0});y(e),p("connected"),e.data.subscribe((function(){return m((0,i.clone)(e.data.get()))}))})),r.on("error",(function(e){f.error(e),p("error: ".concat(e))})),function(){f.info("cleaning up useMQTTSync"),b&&b.beforeDisconnect?(b.beforeDisconnect(),b.waitForHeartbeatOnce((function(){return r.end()}))):r.end()}}),[t,n]),{status:h,ready:"connected"==h,StatusComponent:function(){return o().createElement("div",null,h)},mqttSync:b,data:g}}},335:e=>{function t(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}e.exports=function(e){if(!e.attributes)return{};var r,o,i,a={},c=(i=e.attributes,function(e){if(Array.isArray(e))return n(e)}(i)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(i)||t(i)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}({},e.name,e.value)})),u=function(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=t(e))){r&&(e=r);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){u=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}(c);try{for(u.s();!(o=u.n()).done;){r=o.value;var s=Object.keys(r)[0];a[s.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))]=r[s]}}catch(e){u.e(e)}finally{u.f()}return a}},899:(e,t,n)=>{e.exports=function(){try{return n(962).styleElements}catch(e){return[]}}},271:(e,t,n)=>{function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&p(e,t)}function u(e){var t=h();return function(){var n,r=d(e);if(t){var o=d(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}function s(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){var t="function"==typeof Map?new Map:void 0;return l=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return f(e,arguments,d(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),p(r,e)},l(e)}function f(e,t,n){return f=h()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&p(o,n.prototype),o},f.apply(null,arguments)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function p(e,t){return p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},p(e,t)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}var b=n(689),y=n(405),v=n(430),g=n(899),m=n(335);n(622),n(268),e.exports={create:function(e,t){var n,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],s={attachedCallback:"webComponentAttached",connectedCallback:"webComponentConnected",disconnectedCallback:"webComponentDisconnected",attributeChangedCallback:"webComponentAttributeChanged",adoptedCallback:"webComponentAdopted"};function f(e){n.webComponentConstructed&&n.webComponentConstructed.apply(n,[e])}function h(e,t){var r=t||[],o=s[e];o&&n&&n[o]&&n[o].apply(n,r)}var p=function(t){c(l,t);var s=u(l);function l(){return o(this,l),s.apply(this,arguments)}return a(l,[{key:"connectedCallback",value:function(){var t=this,o=t;if(r){var i=t.attachShadow({mode:"open"});o=document.createElement("div"),g().forEach((function(e){i.appendChild(e.cloneNode(i))})),i.appendChild(o),v(i)}y.render(b.cloneElement(e,m(t)),o,(function(){n=this,f(t),h("connectedCallback")}))}},{key:"disconnectedCallback",value:function(){h("disconnectedCallback")}},{key:"attributeChangedCallback",value:function(e,t,n,r){h("attributeChangedCallback",[e,t,n,r])}},{key:"adoptedCallback",value:function(e,t){h("adoptedCallback",[e,t])}}],[{key:"observedAttributes",get:function(){return i}}]),l}(l(HTMLElement));customElements.define(t,p)}}},11:(e,t,n)=>{"use strict";n.d(t,{EK:()=>C,SV:()=>q,ZM:()=>T,U5:()=>k,B7:()=>P,ax:()=>x,eZ:()=>_});var r=n(689),o=n.n(r);const i=require("react-bootstrap");var a=n(271),c=n.n(a);function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function s(){return s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(this,arguments)}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function p(e,t,n){return t&&h(e.prototype,t),n&&h(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&b(e,t)}function b(e,t){return b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},b(e,t)}function y(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=m(e);if(t){var o=m(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return v(this,n)}}function v(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return g(e)}function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function w(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return O(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}n(368);var S={badge:{width:"4em"},code:{color:"#700",borderLeft:"3px solid #aaa",padding:"0.5em 0px 0.5em 2em",backgroundColor:"#f0f0f0",borderRadius:"4px",marginTop:"0.5em"},inlineCode:{color:"#700",margin:"0px 0.5em 0px 0.5em"}},E=[o().createElement(i.Badge,{bg:"success",style:S.badge},"OK"),o().createElement(i.Badge,{bg:"warning",style:S.badge},"Warn"),o().createElement(i.Badge,{bg:"danger",style:S.badge},"Error"),o().createElement(i.Badge,{bg:"secondary",style:S.badge},"Stale")],k=function(e){var t=e.level;return E[t]||o().createElement("span",null,t)},C=function(e){var t=e.children;return o().createElement("pre",{style:S.code},t)},T=function(e){var t=e.children;return o().createElement("tt",{style:S.inlineCode},t)},j={},x=o().createContext({}),P=function(e){var t=e.duration,n=e.onTimeout,a=e.onStart,c=e.setOnDisconnect,u=e.children;t=t||60;var s=w((0,r.useState)(t),2),l=s[0],f=s[1],h=w((0,r.useState)(!1),2),p=h[0],d=h[1],b=(0,r.useMemo)((function(){return Math.random().toString(36).slice(2)}),[]),y=function(){console.log("stopping timer for",b),n&&setTimeout(n,1),clearInterval(j[b]),j[b]=null,d(!1)};(0,r.useEffect)((function(){var e;l>0&&!p&&(e=j[b],console.log(e,j,l),!e&&l>0&&(d(!0),j[b]=setInterval((function(){return f((function(e){if(--e>0)return e;y()}))}),1e3),a&&setTimeout(a,1)))}),[l]),(0,r.useEffect)((function(){return y}),[]),c&&c((function(){y()}));var v=function(){return f(t)};return o().createElement(x.Provider,{value:{reset:v,duration:t,timer:l}},l>0?o().createElement("div",null,u,l<60&&o().createElement("div",null,"Timeout in: ",l," seconds")):o().createElement("div",null,"Timed out. ",o().createElement(i.Button,{onClick:v},"Resume")))},q=function(e){d(n,e);var t=y(n);function n(e){var r;return f(this,n),(r=t.call(this,e)).state={hasError:!1},r}return p(n,[{key:"componentDidCatch",value:function(e,t){console.warn("ErrorBoundary caught:",e,t)}},{key:"render",value:function(){return this.state.hasError?o().createElement("div",null,this.props.message||"Something went wrong here."):this.props.children}}],[{key:"getDerivedStateFromError",value:function(e){return{hasError:!0}}}]),n}(o().Component),_=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"0.0.0",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},a=function(n){d(c,n);var a=y(c);function c(){var e;f(this,c);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return l(g(e=a.call.apply(a,[this].concat(n))),"onDisconnect",null),l(g(e),"state",{}),e}return p(c,[{key:"setOnDisconnect",value:function(e){this.onDisconnect=e}},{key:"webComponentDisconnected",value:function(){this.onDisconnect&&this.onDisconnect(),this.setState({_disconnected:!0})}},{key:"webComponentAttributeChanged",value:function(e,t,n){var r=this.state;r[e]=n,this.setState(r)}},{key:"render",value:function(){var n=i.stylesheets||["https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"];return o().createElement("div",{id:"cap-".concat(t,"-").concat(r)},o().createElement("style",null,n.map((function(e){return"@import url(".concat(e,");")}))),!this.state._disconnected&&o().createElement(e,s({},this.state,this.props,{setOnDisconnect:this.setOnDisconnect.bind(this)})))}}]),c}(o().Component);c().create(o().createElement(a,null),t,!1,n)}},268:e=>{"use strict";e.exports=require("@webcomponents/custom-elements")},622:e=>{"use strict";e.exports=require("@webcomponents/shadydom")},22:e=>{"use strict";e.exports=require("chalk")},517:e=>{"use strict";e.exports=require("lodash")},848:e=>{"use strict";e.exports=require("lodash/forEach")},712:e=>{"use strict";e.exports=require("lodash/get")},699:e=>{"use strict";e.exports=require("lodash/isEmpty")},113:e=>{"use strict";e.exports=require("lodash/isEqual")},452:e=>{"use strict";e.exports=require("lodash/isPlainObject")},707:e=>{"use strict";e.exports=require("lodash/map")},831:e=>{"use strict";e.exports=require("lodash/merge")},298:e=>{"use strict";e.exports=require("lodash/set")},305:e=>{"use strict";e.exports=require("lodash/unset")},316:e=>{"use strict";e.exports=require("loglevel")},689:e=>{"use strict";e.exports=require("react")},405:e=>{"use strict";e.exports=require("react-dom")},430:e=>{"use strict";e.exports=require("react-shadow-dom-retarget-events")},962:e=>{"use strict";e.exports=require("react-web-component-style-loader/exports")},13:e=>{"use strict";e.exports=require("semver/functions/compare")}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{Code:()=>e.EK,ErrorBoundary:()=>e.SV,InlineCode:()=>e.ZM,LevelBadge:()=>e.U5,Timer:()=>e.B7,TimerContext:()=>e.ax,createWebComponent:()=>e.eZ,useMqttSync:()=>t.H});var e=n(11),t=n(442),o=n(368),i={};for(const e in o)["default","Code","ErrorBoundary","InlineCode","LevelBadge","Timer","TimerContext","createWebComponent","useMqttSync"].indexOf(e)<0&&(i[e]=()=>o[e]);n.d(r,i)})();var o=exports;for(var i in r)o[i]=r[i];r.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/utils-web",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Web utils for the Transitive framework",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "author": {
package/shared.jsx CHANGED
@@ -45,6 +45,7 @@ export const InlineCode = ({children}) => <tt style={styles.inlineCode}>
45
45
 
46
46
  const intervals = {};
47
47
 
48
+ export const TimerContext = React.createContext({});
48
49
  export const Timer = ({duration, onTimeout, onStart, setOnDisconnect, children}) => {
49
50
  duration = duration || 60;
50
51
  const [timer, setTimer] = useState(duration);
@@ -87,29 +88,53 @@ export const Timer = ({duration, onTimeout, onStart, setOnDisconnect, children})
87
88
  stop()
88
89
  });
89
90
 
90
- const resetTimer = () => setTimer(duration);
91
+ const reset = () => setTimer(duration);
92
+
93
+ return <TimerContext.Provider value={{reset, duration, timer}}>
94
+ {timer > 0 ? <div>
95
+ {children}
96
+ {timer < 60 && <div>Timeout in: {timer} seconds</div>}
97
+ </div> :
98
+ <div>Timed out. <Button onClick={reset}>
99
+ Resume
100
+ </Button>
101
+ </div>}
102
+ </TimerContext.Provider>;
103
+ };
91
104
 
92
- return timer > 0 ?
93
- <div>
94
- { /** Inject prop into children to reset timer */
95
- React.Children.map(children, (child) =>
96
- React.cloneElement(child, {resetTimer})
97
- )
98
- }
99
- {timer < duration * 0.5 && <div>Timeout in: {timer} seconds</div>}
100
- </div>
101
- :
102
- <div>Timed out. <Button onClick={resetTimer}>
103
- Resume
104
- </Button>
105
- </div>;
105
+ /** A simple error boundary. Usage:
106
+ <ErrorBoundary message="Something went wrong">
107
+ <SomeFlakyComponent />
108
+ </ErrorBoundary>
109
+ */
110
+ export class ErrorBoundary extends React.Component {
111
+ constructor(props) {
112
+ super(props);
113
+ this.state = { hasError: false };
114
+ }
115
+
116
+ static getDerivedStateFromError(error) {
117
+ return { hasError: true };
118
+ }
119
+
120
+ componentDidCatch(error, errorInfo) {
121
+ console.warn('ErrorBoundary caught:', error, errorInfo);
122
+ }
123
+
124
+ render() {
125
+ return (this.state.hasError ?
126
+ <div>{this.props.message || 'Something went wrong here.'}</div> :
127
+ this.props.children);
128
+ }
106
129
  };
107
130
 
108
131
 
109
132
  /** Create a WebComponent from the given react component and name that is
110
133
  reactive to the given attributes (if any). */
111
- export const createWebComponent =
112
- (Component, name, reactiveAttributes = [], version = '0.0.0') => {
134
+ export const createWebComponent = (Component, name,
135
+ reactiveAttributes = [],
136
+ version = '0.0.0',
137
+ options = {}) => {
113
138
 
114
139
  class Wrapper extends React.Component {
115
140
 
@@ -131,12 +156,11 @@ export const createWebComponent =
131
156
  this.setState({_disconnected: true});
132
157
  }
133
158
 
134
- /**
135
- Note this relies on the changed made in
136
- github:amay0048/react-web-component#780950800e2962f45f0f029be618bb8b84610c89
137
- that we used in our copy.
138
- TODO: move this into our copy, i.e., do it internally to react-web-component
139
- and update props.
159
+ /** Note this relies on the changed made in
160
+ github:amay0048/react-web-component#780950800e2962f45f0f029be618bb8b84610c89
161
+ that we used in our copy.
162
+ TODO: move this into our copy, i.e., do it internally to react-web-component
163
+ and update props.
140
164
  */
141
165
  webComponentAttributeChanged(name, oldValue, newValue) {
142
166
  // console.log('webComponentAttributeChanged', name, oldValue, newValue, this.props, this.state);
@@ -146,10 +170,13 @@ export const createWebComponent =
146
170
  }
147
171
 
148
172
  render() {
149
- // @import url("https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css");
173
+ const stylesheets = options.stylesheets || [
174
+ 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css'
175
+ ];
176
+
150
177
  return <div id={`cap-${name}-${version}`}>
151
178
  <style>
152
- @import url("https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css");
179
+ {stylesheets.map(url => `@import url(${url});`)}
153
180
  </style>
154
181
  {!this.state._disconnected &&
155
182
  <Component