@iobroker/adapter-react-v5 3.0.8 → 3.0.9
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.
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
12
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
20
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
+
|
|
22
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
+
|
|
24
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
+
|
|
26
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
27
|
+
|
|
28
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
29
|
+
|
|
30
|
+
var _LinearProgress = _interopRequireDefault(require("@mui/material/LinearProgress"));
|
|
31
|
+
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
36
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
37
|
+
|
|
38
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
|
+
|
|
40
|
+
var ConfigCustom = /*#__PURE__*/function (_Component) {
|
|
41
|
+
(0, _inherits2["default"])(ConfigCustom, _Component);
|
|
42
|
+
|
|
43
|
+
var _super = _createSuper(ConfigCustom);
|
|
44
|
+
|
|
45
|
+
function ConfigCustom(props) {
|
|
46
|
+
var _this;
|
|
47
|
+
|
|
48
|
+
(0, _classCallCheck2["default"])(this, ConfigCustom);
|
|
49
|
+
_this = _super.call(this, props); // schema.url - location of Widget
|
|
50
|
+
// schema.name - Component name
|
|
51
|
+
|
|
52
|
+
_this.state = {
|
|
53
|
+
Component: null,
|
|
54
|
+
error: ''
|
|
55
|
+
};
|
|
56
|
+
return _this;
|
|
57
|
+
} // load component dynamically
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
(0, _createClass2["default"])(ConfigCustom, [{
|
|
61
|
+
key: "componentDidMount",
|
|
62
|
+
value: function () {
|
|
63
|
+
var _componentDidMount = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
64
|
+
var component, keys;
|
|
65
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
66
|
+
while (1) {
|
|
67
|
+
switch (_context.prev = _context.next) {
|
|
68
|
+
case 0:
|
|
69
|
+
if (this.props.schema.url) {
|
|
70
|
+
_context.next = 4;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.error('URL is empty. Cannot load custom component!');
|
|
75
|
+
this.setState({
|
|
76
|
+
error: 'URL is empty. Cannot load custom component!'
|
|
77
|
+
});
|
|
78
|
+
return _context.abrupt("return");
|
|
79
|
+
|
|
80
|
+
case 4:
|
|
81
|
+
if (this.props.schema.url.startsWith('http:') || this.props.schema.url.startsWith('https:')) {
|
|
82
|
+
window._customComponent = this.props.schema.url;
|
|
83
|
+
} else if (this.props.schema.url.startsWith('./')) {
|
|
84
|
+
window._customComponent = "".concat(window.location.protocol, "//").concat(window.location.host).concat(this.props.schema.url.replace(/^\./, ''));
|
|
85
|
+
} else {
|
|
86
|
+
window._customComponent = "".concat(window.location.protocol, "//").concat(window.location.host, "/").concat(this.props.schema.url);
|
|
87
|
+
} // custom component always has constant name
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
_context.next = 7;
|
|
91
|
+
return Promise.resolve().then(function () {
|
|
92
|
+
return _interopRequireWildcard(require('CustomComponent/Components'));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
case 7:
|
|
96
|
+
component = _context.sent;
|
|
97
|
+
|
|
98
|
+
if (!component || !!component["default"] || !component["default"][this.props.schema.name]) {
|
|
99
|
+
keys = Object.keys((component === null || component === void 0 ? void 0 : component["default"]) || {});
|
|
100
|
+
console.error('URL is empty. Cannot load custom component!');
|
|
101
|
+
this.setState({
|
|
102
|
+
error: "Component ".concat(this.props.schema.name, " not found in ").concat(this.props.schema.url, ". Found: ").concat(keys.join(', '))
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
this.setState({
|
|
106
|
+
Component: component["default"][this.props.schema.name]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
case 9:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context.stop();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, _callee, this);
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
function componentDidMount() {
|
|
119
|
+
return _componentDidMount.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return componentDidMount;
|
|
123
|
+
}()
|
|
124
|
+
}, {
|
|
125
|
+
key: "render",
|
|
126
|
+
value: function render() {
|
|
127
|
+
var Component = this.state.Component;
|
|
128
|
+
|
|
129
|
+
if (!Component) {
|
|
130
|
+
if (this.state.error) {
|
|
131
|
+
return /*#__PURE__*/_react["default"].createElement("div", null, this.state.error);
|
|
132
|
+
} else {
|
|
133
|
+
return /*#__PURE__*/_react["default"].createElement(_LinearProgress["default"], null);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return /*#__PURE__*/_react["default"].createElement(Component, this.props);
|
|
138
|
+
}
|
|
139
|
+
}]);
|
|
140
|
+
return ConfigCustom;
|
|
141
|
+
}(_react.Component);
|
|
142
|
+
|
|
143
|
+
ConfigCustom.propTypes = {
|
|
144
|
+
socket: _propTypes["default"].object.isRequired,
|
|
145
|
+
themeType: _propTypes["default"].string,
|
|
146
|
+
themeName: _propTypes["default"].string,
|
|
147
|
+
style: _propTypes["default"].object,
|
|
148
|
+
className: _propTypes["default"].string,
|
|
149
|
+
data: _propTypes["default"].object.isRequired,
|
|
150
|
+
schema: _propTypes["default"].object,
|
|
151
|
+
onError: _propTypes["default"].func,
|
|
152
|
+
onChange: _propTypes["default"].func
|
|
153
|
+
};
|
|
154
|
+
var _default = ConfigCustom;
|
|
155
|
+
exports["default"] = _default;
|
|
156
|
+
//# sourceMappingURL=ConfigCustom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigCustom.js","names":["ConfigCustom","props","state","Component","error","schema","url","console","setState","startsWith","window","_customComponent","location","protocol","host","replace","component","name","keys","Object","join","propTypes","socket","PropTypes","object","isRequired","themeType","string","themeName","style","className","data","onError","func","onChange"],"sources":["JsonConfigComponent/ConfigCustom.jsx"],"sourcesContent":["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\nimport LinearProgress from \"@mui/material/LinearProgress\";\n\nclass ConfigCustom extends Component {\n constructor(props) {\n super(props);\n // schema.url - location of Widget\n // schema.name - Component name\n\n this.state = {\n Component: null,\n error: '',\n };\n }\n\n // load component dynamically\n async componentDidMount() {\n if (!this.props.schema.url) {\n console.error('URL is empty. Cannot load custom component!');\n this.setState({ error: 'URL is empty. Cannot load custom component!' });\n return;\n }\n\n if (this.props.schema.url.startsWith('http:') || this.props.schema.url.startsWith('https:')) {\n window._customComponent = this.props.schema.url;\n } else if (this.props.schema.url.startsWith('./')) {\n window._customComponent = `${window.location.protocol}//${window.location.host}${this.props.schema.url.replace(/^\\./, '')}`;\n } else {\n window._customComponent = `${window.location.protocol}//${window.location.host}/${this.props.schema.url}`;\n }\n\n // custom component always has constant name\n const component = await import('CustomComponent/Components');\n\n if (!component || !!component.default || !component.default[this.props.schema.name]) {\n const keys = Object.keys(component?.default || {});\n console.error('URL is empty. Cannot load custom component!');\n this.setState({ error: `Component ${this.props.schema.name} not found in ${this.props.schema.url}. Found: ${keys.join(', ')}` });\n } else {\n this.setState({\n Component: component.default[this.props.schema.name]\n });\n }\n }\n\n render() {\n const Component = this.state.Component;\n if (!Component) {\n if (this.state.error) {\n return <div>{this.state.error}</div>;\n } else {\n return <LinearProgress />;\n }\n }\n\n return <Component {...this.props} />;\n }\n}\n\nConfigCustom.propTypes = {\n socket: PropTypes.object.isRequired,\n themeType: PropTypes.string,\n themeName: PropTypes.string,\n style: PropTypes.object,\n className: PropTypes.string,\n data: PropTypes.object.isRequired,\n schema: PropTypes.object,\n onError: PropTypes.func,\n onChange: PropTypes.func,\n};\n\nexport default ConfigCustom;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;IAEMA,Y;;;;;EACF,sBAAYC,KAAZ,EAAmB;IAAA;;IAAA;IACf,0BAAMA,KAAN,EADe,CAEf;IACA;;IAEA,MAAKC,KAAL,GAAa;MACTC,SAAS,EAAE,IADF;MAETC,KAAK,EAAE;IAFE,CAAb;IALe;EASlB,C,CAED;;;;;;6GACA;QAAA;QAAA;UAAA;YAAA;cAAA;gBAAA,IACS,KAAKH,KAAL,CAAWI,MAAX,CAAkBC,GAD3B;kBAAA;kBAAA;gBAAA;;gBAEQC,OAAO,CAACH,KAAR,CAAc,6CAAd;gBACA,KAAKI,QAAL,CAAc;kBAAEJ,KAAK,EAAE;gBAAT,CAAd;gBAHR;;cAAA;gBAOI,IAAI,KAAKH,KAAL,CAAWI,MAAX,CAAkBC,GAAlB,CAAsBG,UAAtB,CAAiC,OAAjC,KAA6C,KAAKR,KAAL,CAAWI,MAAX,CAAkBC,GAAlB,CAAsBG,UAAtB,CAAiC,QAAjC,CAAjD,EAA6F;kBACzFC,MAAM,CAACC,gBAAP,GAA0B,KAAKV,KAAL,CAAWI,MAAX,CAAkBC,GAA5C;gBACH,CAFD,MAEO,IAAI,KAAKL,KAAL,CAAWI,MAAX,CAAkBC,GAAlB,CAAsBG,UAAtB,CAAiC,IAAjC,CAAJ,EAA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,SAAS,GAAG,KAAKD,KAAL,CAAWC,SAA7B;;MACA,IAAI,CAACA,SAAL,EAAgB;QACZ,IAAI,KAAKD,KAAL,CAAWE,KAAf,EAAsB;UAClB,oBAAO,6CAAM,KAAKF,KAAL,CAAWE,KAAjB,CAAP;QACH,CAFD,MAEO;UACH,oBAAO,gCAAC,0BAAD,OAAP;QACH;MACJ;;MAED,oBAAO,gCAAC,SAAD,EAAe,KAAKH,KAApB,CAAP;IACH;;;EArDsBE,gB;;AAwD3BH,YAAY,CAACqB,SAAb,GAAyB;EACrBC,MAAM,EAAEC,qBAAA,CAAUC,MAAV,CAAiBC,UADJ;EAErBC,SAAS,EAAEH,qBAAA,CAAUI,MAFA;EAGrBC,SAAS,EAAEL,qBAAA,CAAUI,MAHA;EAIrBE,KAAK,EAAEN,qBAAA,CAAUC,MAJI;EAKrBM,SAAS,EAAEP,qBAAA,CAAUI,MALA;EAMrBI,IAAI,EAAER,qBAAA,CAAUC,MAAV,CAAiBC,UANF;EAOrBpB,MAAM,EAAEkB,qBAAA,CAAUC,MAPG;EAQrBQ,OAAO,EAAET,qBAAA,CAAUU,IARE;EASrBC,QAAQ,EAAEX,qBAAA,CAAUU;AATC,CAAzB;eAYejC,Y"}
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/adapter-react-v5",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"description": "React classes to develop admin interfaces for ioBroker with react.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "bluefox",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/ioBroker/adapter-react-v5.git"
|
|
16
16
|
},
|
|
17
|
+
"module": "./index.js",
|
|
17
18
|
"keywords": [
|
|
18
19
|
"iobroker",
|
|
19
20
|
"adapter",
|