@transitive-sdk/utils-web 0.3.0

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 ADDED
@@ -0,0 +1,40 @@
1
+
2
+ // It is OK to use paths outside of this package because webpack will bundle them
3
+ export * from '../common/common.js';
4
+
5
+ export const decodeJWT = (jwt) => JSON.parse(atob(jwt.split('.')[1]));
6
+
7
+ /** parse document cookies */
8
+ export const parseCookie = str =>
9
+ str.split(';')
10
+ .map(v => v.split('='))
11
+ .reduce((acc, v) => {
12
+ acc[decodeURIComponent(v[0].trim())] =
13
+ v[1] && decodeURIComponent(v[1].trim());
14
+ return acc;
15
+ }, {});
16
+
17
+ /* get or post (if body given) json */
18
+ export const fetchJson = (url, callback, options = {}) => {
19
+ fetch(url, {
20
+ method: options.method || (options.body ? 'post' : 'get'),
21
+ mode: 'cors',
22
+ cache: 'no-cache',
23
+ // Maybe we'll need this (when embedding)?
24
+ // credentials: 'same-origin', // include, *same-origin, omit
25
+ headers: {
26
+ 'Content-Type': 'application/json'
27
+ },
28
+ redirect: 'follow',
29
+ referrerPolicy: 'no-referrer',
30
+ body: options.body ? JSON.stringify(options.body) : undefined
31
+ }).then(res => {
32
+ if (!res.ok) {
33
+ throw new Error(`fetching ${url} failed: ${res.status} ${res.statusText}`)
34
+ }
35
+ return res.json();
36
+ }).then(data => callback(null, data))
37
+ .catch((error) => callback(`error: ${error}`));
38
+ };
39
+
40
+ export const whoami = '@transitive-robotics/utils-web';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _shared = require("./shared.jsx");
8
+
9
+ Object.keys(_shared).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _shared[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _shared[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _hooks = require("./hooks.jsx");
21
+
22
+ Object.keys(_hooks).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _hooks[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _hooks[key];
29
+ }
30
+ });
31
+ });
@@ -0,0 +1 @@
1
+ (()=>{var e={890:(e,t,n)=>{"use strict";function r(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 o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){return i="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},i(e)}var u=n(362),a=u.DataCache,c=u.mqttParsePayload,s=u.pathMatch,l=u.topicToPath,f=u.pathToTopic,p=u.toFlatObject,d=u.getLogger,h=n(517),b=d(e.id||"MqttSync"),y="$SYS/broker/uptime",v=function(){},m=function(e){return e.endsWith("/#")?e:e.endsWith("/")?e.concat("#"):e.concat("/#")},g=function(){function e(t){var n=this,r=t.mqttClient,i=t.onChange,u=t.ignoreRetain;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"data",new a),o(this,"subscribedPaths",{}),o(this,"publishedPaths",{}),o(this,"publishedMessages",{}),o(this,"publishQueue",[]),o(this,"heartbeatWaitersOnce",[]),this.mqtt=r,this.mqtt.on("message",(function(e,t,r){if(b.debug("got message",e,t&&t.toString(),r.retain),e==y)n.initialHeartbeat?(n.heartbeatWaitersOnce.forEach((function(e){return e()})),n.heartbeatWaitersOnce=[]):n.initialHeartbeat=!0;else if(r.retain||u){b.debug("processing message",e,t&&t.toString());var o=c(t);if(n.isPublished(e))n.publishedMessages[e]=o;else if(n.isSubscribed(e)){b.debug("applying received update",e,o);var a=n.data.update(e,o);i&&Object.keys(a).length>0&&i(a)}}})),this.mqtt.subscribe(y,{rap:!0},b.debug)}var t,n;return t=e,n=[{key:"waitForHeartbeatOnce",value:function(e){this.heartbeatWaitersOnce.push(e)}},{key:"isSubscribed",value:function(e){return Object.keys(this.subscribedPaths).some((function(t){return s(t,e)}))}},{key:"isPublished",value:function(e){var t=this;return Object.keys(this.publishedPaths).some((function(n){return s(n,e)&&!t.publishedPaths[n].atomic}))}},{key:"subscribe",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v;if(e=m(e),this.subscribedPaths[e])return b.debug("already subscribed to",e),void n();this.mqtt.subscribe(e,{rap:!0},(function(r,o){b.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))}))}},{key:"_actuallyPublish",value:function(e,t){var n=this;return b.debug("actually publishing",e,t),new Promise((function(r,o){return n.mqtt.publish(e,null==t?null:JSON.stringify(t),{retain:!0},(function(e){e?o(e):r()}))}))}},{key:"_processQueue_rec",value:function(e){var t=this;if(this.publishQueue.length>0){var n=this.publishQueue.shift(),r=n.topic,o=n.value;this._actuallyPublish(r,o).then((function(){return t._processQueue_rec(e)}))}else e()}},{key:"_processQueue",value:function(){var e=this;this._processing||(this._processing=!0,this._processQueue_rec((function(){return e._processing=!1})))}},{key:"_enqueue",value:function(e,t){var n;b.debug("enqueuing",e,t),this.publishQueue.push({topic:e,value:t}),this._processQueue(),null==t?delete this.publishedMessages[e]:this.publishedMessages[e]="object"==i(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=m(e),!h.isEqual(this.publishedPaths[e],n)&&(this.publishedPaths[e]=n,n.atomic?(this.data.subscribePath(e,(function(n,r,o){b.debug("processing change (atomic)",r,n,e);var i=e.slice(0,e.length-2),u=f(l(r).slice(0,l(i).length));t._enqueue(u,t.data.getByTopic(u))})),!0):(this.mqtt.subscribe(e),void this.data.subscribePath(e,(function(e,n){return b.debug("processing change",n,e),h.each(t.publishedMessages,(function(e,r){if(b.trace("oldKey",r),r==n)return!0;if(r.startsWith(n)&&t._enqueue(r,null),n.startsWith(r)){t._enqueue(r,null);var o=p(e);h.each(o,(function(e,n){var o="".concat(r).concat(n);t._enqueue(o,e)}))}})),t._enqueue(n,e),!0}))))}}],n&&r(t.prototype,n),e}();e.exports=g},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 u(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,c(e,t,"get"))}function a(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,c(e,t,"set"),n),n}function c(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)},p=n(316);p.setAll=function(e){return Object.values(p.getLoggers()).forEach((function(t){return t.setLevel(e)}))};var d=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}},h=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[y(i)]=t})),r},b=function e(t,n){if(0!=n.length){var r=n[0];if(r)for(var o in t)o!=r&&"*"!=r&&"+"!=r?delete t[o]:e(t[o],n.slice(1))}},y=function(e){return"/".concat(e.map((function(e){return e.startsWith("+")?"+":e})).join("/"))},v=function(e){var t=e.split("/");return t.length>0&&0==t[0].length&&t.shift(),t.length>0&&0==t[t.length-1].length&&t.pop(),t},m=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}(e.split("/"),t.split("/"))},g=new WeakMap,w=new WeakMap,S=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),i(this,g,{writable:!0,value:{}}),i(this,w,{writable:!0,value:[]}),a(this,g,t)}var t,n;return t=e,n=[{key:"updateFromArray",value:function(e,t){var n=f.get(u(this,g),e);if(null==t){if(null==n)return{};d(u(this,g),e)}else{if(f.eq(n,t))return{};f.set(u(this,g),e,t)}var r=h(s({},e.join("/"),t)),o=y(e);return u(this,w).forEach((function(e){return e(s({},o,t))})),r}},{key:"update",value:function(e,t){if("string"==typeof e)return this.updateFromTopic(e,t);if(e instanceof Array)return this.updateFromArray(e,t);throw new Error("unrecognized path expression")}},{key:"updateFromTopic",value:function(e,t){return this.updateFromArray(v(e),t)}},{key:"updateFromModifier",value:function(e){var t=this;return f.map(e,(function(e,n){return t.updateFromTopic(n,e)}))}},{key:"subscribe",value:function(e){u(this,w).push(e)}},{key:"subscribePath",value:function(e,t){u(this,w).push((function(n){f.forEach(n,(function(n,r){var o=m(e,r);o&&t(n,r,o)}))}))}},{key:"unsubscribe",value:function(e){a(this,w,u(this,w).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?u(this,g):f.get(u(this,g),e)}},{key:"getByTopic",value:function(e){return this.get(v(e))}},{key:"filter",value:function(e){var t=JSON.parse(JSON.stringify(this.get()));return b(t,e),t}}],n&&o(t.prototype,n),e}(),O=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=e.split("/");return{organization:t[1],device:t[2],capabilityScope:t[3],capabilityName:t[4],capability:"".concat(t[3],"/").concat(t[4]),version:t[5],sub:t.slice(6)}},updateObject:function(e,t){return f.forEach(t,(function(t,n){var r=n.split("/").slice(1);null==t?d(e,r):f.set(e,r,t)})),e},DataCache:S,pathToTopic:y,topicToPath:v,toFlatObject:h,mqttTopicMatch: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)))}(e.split("/"),t.split("/"))},pathMatch:m,mqttParsePayload:function(e){return 0==e.length?null:JSON.parse(e.toString("utf-8"))},getRandomId:function(){return Math.random().toString(36).slice(2)},versionCompare:O,loglevel:p,getLogger:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"?",t=String(e).split("/").slice(-1)[0],n=p.getLogger(t),r=n.methodFactory;return n.methodFactory=function(e,n,o){var i=r(e,n,o);if(r.patched)return i;r.patched=!0;var u="[".concat(t,", ").concat(e,"]");return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return i.apply(void 0,[u].concat(t))}},n}}},368:(e,t,n)=>{"use strict";n.r(t),n.d(t,{decodeJWT:()=>i,parseCookie:()=>u,fetchJson:()=>a,whoami:()=>c});var r=n(362),o={};for(const e in r)["default","decodeJWT","parseCookie","fetchJson","whoami"].indexOf(e)<0&&(o[e]=()=>r[e]);n.d(t,o);var i=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}),{})},a=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))}))},c="@transitive-robotics/utils-web"},442:(e,t,n)=>{"use strict";n.d(t,{H:()=>p});var r=n(689),o=n.n(r),i=n(368);const u=require("mqtt-browser");var a=n.n(u);function c(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=[],u=!0,a=!1;try{for(n=n.call(e);!(u=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);u=!0);}catch(e){a=!0,o=e}finally{try{u||null==n.return||n.return()}finally{if(a)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,u=e.mqttUrl,s=c((0,r.useState)("connecting"),2),p=s[0],d=s[1],h=c((0,r.useState)(),2),b=h[0],y=h[1],v=c((0,r.useState)({}),2),m=v[0],g=v[1];return(0,r.useEffect)((function(){var e=(0,i.decodeJWT)(t),r=a().connect(u,{username:JSON.stringify({id:n,payload:e}),password:t});return r.on("connect",(function(){f.debug("connected");var e=new l({mqttClient:r,onChange:function(){g(JSON.parse(JSON.stringify(e.data.get())))},ignoreRetain:!0});y(e),d("connected")})),r.on("error",(function(e){f.error(e),d("error: ".concat(e))})),function(){f.info("cleaning up useMQTTSync"),r.end()}}),[t,n]),{status:p,ready:"connected"==p,StatusComponent:function(){return o().createElement("div",null,p)},mqttSync:b,data:m}}},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,u={},a=(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)})),c=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 u,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,u=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw u}}}}(a);try{for(c.s();!(o=c.n()).done;){r=o.value;var s=Object.keys(r)[0];u[s.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))]=r[s]}}catch(e){c.e(e)}finally{c.f()}return u}},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 u(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function a(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}}),t&&d(e,t)}function c(e){var t=p();return function(){var n,r=h(e);if(t){var o=h(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,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(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&&d(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 d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}var b=n(689),y=n(405),v=n(430),m=n(899),g=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 d=function(t){a(l,t);var s=c(l);function l(){return o(this,l),s.apply(this,arguments)}return u(l,[{key:"connectedCallback",value:function(){var t=this,o=t;if(r){var i=t.attachShadow({mode:"open"});o=document.createElement("div"),m().forEach((function(e){i.appendChild(e.cloneNode(i))})),i.appendChild(o),v(i)}y.render(b.cloneElement(e,g(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,d)}}},11:(e,t,n)=>{"use strict";n.d(t,{EK:()=>j,ZM:()=>k,U5:()=>E,B7:()=>P,eZ:()=>q});var r=n(689),o=n.n(r);const i=require("react-bootstrap");var u=n(271),a=n.n(u);function c(e){return c="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},c(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),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}}),t&&h(e,t)}function h(e,t){return h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},h(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=m(e);if(t){var o=m(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"===c(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 m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function g(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=[],u=!0,a=!1;try{for(n=n.call(e);!(u=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);u=!0);}catch(e){a=!0,o=e}finally{try{u||null==n.return||n.return()}finally{if(a)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}n(368);var O={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"}},C=[o().createElement(i.Badge,{bg:"success",style:O.badge},"OK"),o().createElement(i.Badge,{bg:"warning",style:O.badge},"Warn"),o().createElement(i.Badge,{bg:"danger",style:O.badge},"Error"),o().createElement(i.Badge,{bg:"secondary",style:O.badge},"Stale")],E=function(e){var t=e.level;return C[t]||o().createElement("span",null,t)},j=function(e){var t=e.children;return o().createElement("pre",{style:O.code},t)},k=function(e){var t=e.children;return o().createElement("tt",{style:O.inlineCode},t)},T={},P=function(e){var t=e.duration,n=e.onTimeout,u=e.onStart,a=e.setOnDisconnect,c=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),d=p[0],h=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(T[b]),T[b]=null,h(!1)};(0,r.useEffect)((function(){var e;l>0&&!d&&(e=T[b],console.log(e,T,l),!e&&l>0&&(h(!0),T[b]=setInterval((function(){return f((function(e){if(--e>0)return e;y()}))}),1e3),u&&setTimeout(u,1)))}),[l]),(0,r.useEffect)((function(){return y}),[]),a&&a((function(){y()}));var v=function(){return f(t)};return l>0?o().createElement("div",null,o().Children.map(c,(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=function(t){d(r,t);var n=b(r);function r(){var e;l(this,r);for(var t=arguments.length,o=new Array(t),i=0;i<t;i++)o[i]=arguments[i];return g(v(e=n.call.apply(n,[this].concat(o))),"onDisconnect",null),g(v(e),"state",{}),e}return p(r,[{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",null,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)})))}}]),r}(o().Component);a().create(o().createElement(r,null),t,!1,n)}},268:e=>{"use strict";e.exports=require("@webcomponents/custom-elements")},622:e=>{"use strict";e.exports=require("@webcomponents/shadydom")},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")},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]={id: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})})();
package/hooks.jsx ADDED
@@ -0,0 +1,53 @@
1
+ import React, { useState, useEffect, useMemo } from 'react';
2
+ import { decodeJWT, getLogger } from './client';
3
+ // import MqttSync from '../MqttSync';
4
+ const MqttSync = require('../common/MqttSync');
5
+ import mqtt from 'mqtt-browser';
6
+ const log = getLogger('utils-web/hooks');
7
+
8
+
9
+ /** hook for using MqttSync in react */
10
+ export const useMqttSync = ({jwt, id, mqttUrl}) => {
11
+ const [status, setStatus] = useState('connecting');
12
+ const [mqttSync, setMqttSync] = useState();
13
+ const [data, setData] = useState({});
14
+
15
+ useEffect(() => {
16
+ const payload = decodeJWT(jwt);
17
+ const client = mqtt.connect(mqttUrl, {
18
+ username: JSON.stringify({id, payload}),
19
+ password: jwt
20
+ });
21
+ client.on('connect', () => {
22
+ log.debug('connected');
23
+ const mqttSyncClient = new MqttSync({
24
+ mqttClient: client,
25
+ onChange: () => {
26
+ // log.debug('onChange', mqttSyncClient.data.get());
27
+ // Note: need to clone the object to force a reaction
28
+ setData(JSON.parse(JSON.stringify(mqttSyncClient.data.get())));
29
+ },
30
+ ignoreRetain: true
31
+ });
32
+ setMqttSync(mqttSyncClient);
33
+ setStatus('connected');
34
+ });
35
+ client.on('error', (error) => {
36
+ log.error(error);
37
+ setStatus(`error: ${error}`);
38
+ });
39
+
40
+ return () => {
41
+ log.info('cleaning up useMQTTSync');
42
+ client.end();
43
+ };
44
+ }, [jwt, id]);
45
+
46
+ return {
47
+ status,
48
+ ready: status == 'connected',
49
+ StatusComponent: () => <div>{status}</div>,
50
+ mqttSync, // Note: mqttSync.data is not reactive.
51
+ data, // This is a reactive data-source (to use meteor terminology).
52
+ };
53
+ };
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './shared.jsx';
2
+ export * from './hooks.jsx';
3
+ export * from './client';
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@transitive-sdk/utils-web",
3
+ "version": "0.3.0",
4
+ "description": "Web utils for the Transitive framework",
5
+ "homepage": "https://transitiverobotics.com",
6
+ "author": {
7
+ "name" : "Christian Fritz",
8
+ "email" : "christian@transitiverobotics.com"
9
+ },
10
+ "keywords": [
11
+ "robotics"
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "main": "dist/utils-web.js",
18
+ "scripts": {
19
+ "test": "webpack serve -c webpack-test.config.js",
20
+ "build-test": "webpack -c webpack-test.config.js",
21
+ "prepare": "webpack --no-watch --mode=production"
22
+ },
23
+ "dependencies": {
24
+ "@babel/runtime": "^7.16.7",
25
+ "@webcomponents/custom-elements": "^1.2.1",
26
+ "@webcomponents/shadydom": "^1.4.3",
27
+ "bootstrap": "^4.6.0",
28
+ "jsonwebtoken": "^8.5.1",
29
+ "lodash": "^4.17.21",
30
+ "loglevel": "^1.8.0",
31
+ "mqtt-browser": "^4.2.7",
32
+ "react-shadow-dom-retarget-events": "^1.0.8",
33
+ "semver": "^7.3.5"
34
+ },
35
+ "devDependencies": {
36
+ "@babel/core": "^7.13.8",
37
+ "@babel/plugin-proposal-class-properties": "^7.13.0",
38
+ "@babel/plugin-transform-runtime": "^7.16.10",
39
+ "@babel/preset-env": "^7.13.9",
40
+ "@babel/preset-react": "^7.12.10",
41
+ "babel-loader": "^8.2.2",
42
+ "css-loader": "^5.0.1",
43
+ "extract-loader": "^5.1.0",
44
+ "react": "^17.0.1",
45
+ "react-bootstrap": "^1.4.3",
46
+ "react-dom": "^17.0.1",
47
+ "react-web-component-style-loader": "^0.1.4-alpha",
48
+ "webpack": "^5.65.0",
49
+ "webpack-cli": "^4.9.1",
50
+ "webpack-dev-server": "^4.7.3",
51
+ "webpack-node-externals": "^3.0.0",
52
+ "websocket-stream": "^5.5.2"
53
+ }
54
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Takes in a node attributes map and returns an object with camelCased properties and values
3
+ * @param nodeMap
4
+ * @returns {{}}
5
+ */
6
+ module.exports = function extractAttributes(nodeMap) {
7
+ if (!nodeMap.attributes) {
8
+ return {};
9
+ }
10
+
11
+ let obj = {};
12
+ let attribute;
13
+ const attributesAsNodeMap = [...nodeMap.attributes];
14
+ const attributes = attributesAsNodeMap.map((attribute) => ({ [attribute.name]: attribute.value }));
15
+
16
+ for (attribute of attributes) {
17
+ const key = Object.keys(attribute)[0];
18
+ const camelCasedKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
19
+ obj[camelCasedKey] = attribute[key];
20
+ }
21
+
22
+ return obj;
23
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * An optional library which is conditionally added
3
+ * @returns {[]}
4
+ */
5
+ module.exports = () => {
6
+ try {
7
+ return require('react-web-component-style-loader/exports').styleElements;
8
+ } catch (e) {
9
+ return [];
10
+ }
11
+ };
@@ -0,0 +1,89 @@
1
+ const React = require('react');
2
+ const ReactDOM = require('react-dom');
3
+ const retargetEvents = require('react-shadow-dom-retarget-events');
4
+ const getStyleElementsFromReactWebComponentStyleLoader = require('./getStyleElementsFromReactWebComponentStyleLoader');
5
+ const extractAttributes = require('./extractAttributes');
6
+
7
+ require('@webcomponents/shadydom');
8
+ require('@webcomponents/custom-elements');
9
+
10
+ module.exports = {
11
+ /**
12
+ * @param {JSX.Element} app
13
+ * @param {string} tagName - The name of the web component. Has to be minus "-" delimited.
14
+ * @param {boolean} useShadowDom - If the value is set to "true" the web component will use the `shadowDom`. The default value is true.
15
+ * @param {string[]} observedAttributes - The observed attributes of the web component
16
+ */
17
+ create: (app, tagName, useShadowDom = true, observedAttributes = []) => {
18
+ let appInstance;
19
+
20
+ const lifeCycleHooks = {
21
+ attachedCallback: 'webComponentAttached',
22
+ connectedCallback: 'webComponentConnected',
23
+ disconnectedCallback: 'webComponentDisconnected',
24
+ attributeChangedCallback: 'webComponentAttributeChanged',
25
+ adoptedCallback: 'webComponentAdopted'
26
+ };
27
+
28
+ function callConstructorHook(webComponentInstance) {
29
+ if (appInstance['webComponentConstructed']) {
30
+ appInstance['webComponentConstructed'].apply(appInstance, [webComponentInstance])
31
+ }
32
+ }
33
+
34
+ function callLifeCycleHook(hook, params) {
35
+ const instanceParams = params || [];
36
+ const instanceMethod = lifeCycleHooks[hook];
37
+
38
+ if (instanceMethod && appInstance && appInstance[instanceMethod]) {
39
+ appInstance[instanceMethod].apply(appInstance, instanceParams);
40
+ }
41
+ }
42
+
43
+ const proto = class extends HTMLElement {
44
+ static get observedAttributes() {
45
+ return observedAttributes;
46
+ }
47
+ connectedCallback() {
48
+ const webComponentInstance = this;
49
+ let mountPoint = webComponentInstance;
50
+
51
+ if (useShadowDom) {
52
+ // Re-assign the webComponentInstance (this) to the newly created shadowRoot
53
+ const shadowRoot = webComponentInstance.attachShadow({ mode: 'open' });
54
+ // Re-assign the mountPoint to the newly created "div" element
55
+ mountPoint = document.createElement('div');
56
+
57
+ // Move all of the styles assigned to the react component inside of the shadowRoot.
58
+ // By default this is not used, only if the library is explicitly installed
59
+ const styles = getStyleElementsFromReactWebComponentStyleLoader();
60
+ styles.forEach((style) => {
61
+ shadowRoot.appendChild(style.cloneNode(shadowRoot));
62
+ });
63
+
64
+ shadowRoot.appendChild(mountPoint);
65
+
66
+ retargetEvents(shadowRoot);
67
+ }
68
+
69
+ ReactDOM.render(React.cloneElement(app, extractAttributes(webComponentInstance)) , mountPoint, function () {
70
+ appInstance = this;
71
+
72
+ callConstructorHook(webComponentInstance);
73
+ callLifeCycleHook('connectedCallback');
74
+ });
75
+ }
76
+ disconnectedCallback () {
77
+ callLifeCycleHook('disconnectedCallback');
78
+ }
79
+ attributeChangedCallback (attributeName, oldValue, newValue, namespace) {
80
+ callLifeCycleHook('attributeChangedCallback', [attributeName, oldValue, newValue, namespace]);
81
+ }
82
+ adoptedCallback (oldDocument, newDocument) {
83
+ callLifeCycleHook('adoptedCallback', [oldDocument, newDocument]);
84
+ }
85
+ }
86
+
87
+ customElements.define(tagName, proto);
88
+ },
89
+ };
@@ -0,0 +1,4 @@
1
+ Copy of `src/dev` folder of
2
+ https://github.com/amay0048/react-web-component/commit/780950800e2962f45f0f029be618bb8b84610c89
3
+
4
+ By copying it, we avoid the extra react import that caused us to run into [Invalid hook call errors](https://reactjs.org/link/invalid-hook-call).
package/shared.jsx ADDED
@@ -0,0 +1,163 @@
1
+ import React, { useState, useEffect, useMemo } from 'react';
2
+ import { Button, Accordion, AccordionContext, Card, Badge }
3
+ from 'react-bootstrap';
4
+ import ReactWebComponent from './react-web-component';
5
+
6
+ import { parseCookie } from './client';
7
+
8
+ const styles = {
9
+ badge: {
10
+ width: '4em'
11
+ },
12
+ code: {
13
+ color: '#700',
14
+ borderLeft: '3px solid #aaa',
15
+ padding: '0.5em 0px 0.5em 2em',
16
+ backgroundColor: '#f0f0f0',
17
+ borderRadius: '4px',
18
+ marginTop: '0.5em',
19
+ },
20
+ inlineCode: {
21
+ color: '#700',
22
+ margin: '0px 0.5em 0px 0.5em',
23
+ }
24
+ };
25
+
26
+ const levelBadges = [
27
+ <Badge bg="success" style={styles.badge}>OK</Badge>,
28
+ <Badge bg="warning" style={styles.badge}>Warn</Badge>,
29
+ <Badge bg="danger" style={styles.badge}>Error</Badge>,
30
+ <Badge bg="secondary" style={styles.badge}>Stale</Badge>,
31
+ ];
32
+
33
+ /** The right badge for the level */
34
+ export const LevelBadge = ({level}) => levelBadges[level] || <span>{level}</span>;
35
+
36
+ /** reusable component for showing code */
37
+ export const Code = ({children}) => <pre style={styles.code}>
38
+ {children}
39
+ </pre>;
40
+
41
+ export const InlineCode = ({children}) => <tt style={styles.inlineCode}>
42
+ {children}
43
+ </tt>;
44
+
45
+
46
+ const intervals = {};
47
+
48
+ export const Timer = ({duration, onTimeout, onStart, setOnDisconnect, children}) => {
49
+ duration = duration || 60;
50
+ const [timer, setTimer] = useState(duration);
51
+ const [running, setRunning] = useState(false);
52
+ const id = useMemo(() => Math.random().toString(36).slice(2), []);
53
+
54
+ const stop = () => {
55
+ console.log('stopping timer for', id);
56
+ onTimeout && setTimeout(onTimeout, 1);
57
+ clearInterval(intervals[id]);
58
+ intervals[id] = null;
59
+ setRunning(false);
60
+ };
61
+
62
+ const startTimer = () => {
63
+ const interval = intervals[id];
64
+ console.log(interval, intervals, timer);
65
+ if (!interval && timer > 0) {
66
+ setRunning(true);
67
+ intervals[id] = setInterval(() =>
68
+ setTimer(t => {
69
+ if (--t > 0) {
70
+ return t;
71
+ } else {
72
+ stop();
73
+ }
74
+ }), 1000);
75
+ onStart && setTimeout(onStart, 1);
76
+ }
77
+
78
+ return stop;
79
+ };
80
+
81
+ useEffect(() => { timer > 0 && !running && startTimer() }, [timer]);
82
+
83
+ useEffect(() => stop, []);
84
+
85
+ setOnDisconnect && setOnDisconnect(() => {
86
+ // call on disconnect of the web component
87
+ stop()
88
+ });
89
+
90
+ const resetTimer = () => setTimer(duration);
91
+
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>;
106
+ };
107
+
108
+
109
+ /** Create a WebComponent from the given react component and name that is
110
+ reactive to the given attributes (if any). */
111
+ export const createWebComponent = (Component, name, reactiveAttributes = []) => {
112
+
113
+ class Wrapper extends React.Component {
114
+
115
+ onDisconnect = null;
116
+
117
+ // state = JSON.parse(JSON.stringify(this.props));
118
+ // state = this.props;
119
+ state = {};
120
+
121
+ /** function used by `Component` to register a onDisconnect handler */
122
+ setOnDisconnect(fn) {
123
+ this.onDisconnect = fn;
124
+ }
125
+
126
+ webComponentDisconnected() {
127
+ this.onDisconnect && this.onDisconnect();
128
+ // this ensures that the react component unmounts and all useEffect
129
+ // cleanups are called.
130
+ this.setState({_disconnected: true});
131
+ }
132
+
133
+ /**
134
+ Note this relies on the changed made in
135
+ github:amay0048/react-web-component#780950800e2962f45f0f029be618bb8b84610c89
136
+ that we used in our copy.
137
+ TODO: move this into our copy, i.e., do it internally to react-web-component
138
+ and update props.
139
+ */
140
+ webComponentAttributeChanged(name, oldValue, newValue) {
141
+ // console.log('webComponentAttributeChanged', name, oldValue, newValue, this.props, this.state);
142
+ const newState = this.state;
143
+ newState[name] = newValue;
144
+ this.setState(newState);
145
+ }
146
+
147
+ render() {
148
+ // @import url("https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css");
149
+ return <div>
150
+ <style>
151
+ @import url("https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css");
152
+ </style>
153
+ {!this.state._disconnected &&
154
+ <Component
155
+ {...this.state}
156
+ {...this.props}
157
+ setOnDisconnect={this.setOnDisconnect.bind(this)}/>}
158
+ </div>;
159
+ }
160
+ };
161
+
162
+ ReactWebComponent.create(<Wrapper />, name, false, reactiveAttributes);
163
+ };