@iobroker/adapter-react-v5 4.9.0 → 4.9.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.
@@ -0,0 +1,6 @@
1
+ declare function copy(text: string, options?: {
2
+ debug?: boolean;
3
+ format?: string;
4
+ message?: string;
5
+ }): boolean;
6
+ export default copy;
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ MIT License
5
+
6
+ Copyright (c) 2017 sudodoki <smd.deluzion@gmail.com>
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+ */
26
+ // https://github.com/sudodoki/toggle-selection/blob/gh-pages/index.js
27
+ function deselectCurrent() {
28
+ const selection = document.getSelection();
29
+ if (!(selection === null || selection === void 0 ? void 0 : selection.rangeCount)) {
30
+ return () => { };
31
+ }
32
+ let active = document.activeElement;
33
+ const ranges = [];
34
+ for (let i = 0; i < selection.rangeCount; i++) {
35
+ ranges.push(selection.getRangeAt(i));
36
+ }
37
+ switch (active === null || active === void 0 ? void 0 : active.tagName.toUpperCase()) { // .toUpperCase handles XHTML
38
+ case 'INPUT':
39
+ case 'TEXTAREA':
40
+ active.blur();
41
+ break;
42
+ default:
43
+ active = null;
44
+ break;
45
+ }
46
+ selection.removeAllRanges();
47
+ return () => {
48
+ selection.type === 'Caret' &&
49
+ selection.removeAllRanges();
50
+ if (!selection.rangeCount) {
51
+ ranges.forEach(range => selection.addRange(range));
52
+ }
53
+ active && active.focus();
54
+ };
55
+ }
56
+ // https://github.com/sudodoki/copy-to-clipboard/blob/master/index.js
57
+ const clipboardToIE11Formatting = {
58
+ 'text/plain': 'Text',
59
+ 'text/html': 'Url',
60
+ default: 'Text',
61
+ };
62
+ const defaultMessage = 'Copy to clipboard: #{key}, Enter';
63
+ function format(message) {
64
+ const copyKey = `${/mac os x/i.test(navigator.userAgent) ? '⌘' : 'Ctrl'}+C`;
65
+ return message.replace(/#{\s*key\s*}/g, copyKey);
66
+ }
67
+ function copy(text, options) {
68
+ let reselectPrevious;
69
+ let range;
70
+ let selection;
71
+ let mark;
72
+ let success = false;
73
+ options = options || {};
74
+ const debug = options.debug || false;
75
+ try {
76
+ reselectPrevious = deselectCurrent();
77
+ range = document.createRange();
78
+ selection = document.getSelection();
79
+ mark = document.createElement('span');
80
+ mark.textContent = text;
81
+ // avoid screen readers from reading out loud the text
82
+ mark.ariaHidden = 'true';
83
+ // reset user styles for span element
84
+ mark.style.all = 'unset';
85
+ // prevents scrolling to the end of the page
86
+ mark.style.position = 'fixed';
87
+ mark.style.top = '0px';
88
+ mark.style.clip = 'rect(0, 0, 0, 0)';
89
+ // used to preserve spaces and line breaks
90
+ mark.style.whiteSpace = 'pre';
91
+ // do not inherit user-select (it may be `none`)
92
+ // @ts-ignore
93
+ mark.style.webkitUserSelect = 'text';
94
+ // @ts-ignore
95
+ mark.style.MozUserSelect = 'text';
96
+ // @ts-ignore
97
+ mark.style.msUserSelect = 'text';
98
+ mark.style.userSelect = 'text';
99
+ mark.addEventListener('copy', e => {
100
+ var _a, _b, _c, _d;
101
+ e.stopPropagation();
102
+ if (options === null || options === void 0 ? void 0 : options.format) {
103
+ e.preventDefault();
104
+ if (typeof e.clipboardData === 'undefined') { // IE 11
105
+ debug && console.warn('unable to use e.clipboardData');
106
+ debug && console.warn('trying IE specific stuff');
107
+ (_a = window.clipboardData) === null || _a === void 0 ? void 0 : _a.clearData();
108
+ // @ts-ignore
109
+ const _format = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting.default;
110
+ (_b = window.clipboardData) === null || _b === void 0 ? void 0 : _b.setData(_format, text);
111
+ }
112
+ else { // all other browsers
113
+ (_c = e.clipboardData) === null || _c === void 0 ? void 0 : _c.clearData();
114
+ (_d = e.clipboardData) === null || _d === void 0 ? void 0 : _d.setData(options.format, text);
115
+ }
116
+ }
117
+ });
118
+ document.body.appendChild(mark);
119
+ range.selectNodeContents(mark);
120
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range);
121
+ const successful = document.execCommand('copy');
122
+ if (!successful) {
123
+ throw new Error('copy command was unsuccessful');
124
+ }
125
+ success = true;
126
+ }
127
+ catch (err) {
128
+ debug && console.error('unable to copy using execCommand: ', err);
129
+ debug && console.warn('trying IE specific stuff');
130
+ try {
131
+ window.clipboardData.setData(options.format || 'text', text);
132
+ // options.onCopy && options.onCopy((window as any).clipboardData);
133
+ success = true;
134
+ }
135
+ catch (error) {
136
+ debug && console.error('unable to copy using clipboardData: ', error);
137
+ debug && console.error('falling back to prompt');
138
+ const message = format('message' in options ? options.message || '' : defaultMessage);
139
+ window.prompt(message, text);
140
+ }
141
+ }
142
+ finally {
143
+ if (selection) {
144
+ if (range && typeof selection.removeRange === 'function') {
145
+ selection.removeRange(range);
146
+ }
147
+ else {
148
+ selection.removeAllRanges();
149
+ }
150
+ }
151
+ if (mark) {
152
+ document.body.removeChild(mark);
153
+ }
154
+ reselectPrevious && reselectPrevious();
155
+ }
156
+ return success;
157
+ }
158
+ exports.default = copy;
@@ -1,64 +1,24 @@
1
- export default Image;
2
- export type ImageProps = {
3
- /**
4
- * The color.
5
- */
1
+ import React, { Component } from 'react';
2
+ interface ImageProps {
6
3
  color?: string;
7
- /**
8
- * The source of the image.
9
- */
10
4
  src?: string;
11
- /**
12
- * The image prefix (default: './files/')
13
- */
14
5
  imagePrefix?: string;
15
- /**
16
- * The CSS class name.
17
- */
18
6
  className?: string;
19
- /**
20
- * Show image errors (or just show no image)?
21
- */
22
7
  showError?: boolean;
23
- };
24
- /**
25
- * @typedef {object} ImageProps
26
- * @property {string} [color] The color.
27
- * @property {string} [src] The source of the image.
28
- * @property {string} [imagePrefix] The image prefix (default: './files/')
29
- * @property {string} [className] The CSS class name.
30
- * @property {boolean} [showError] Show image errors (or just show no image)?
31
- *
32
- * @extends {React.Component<ImageProps>}
33
- */
34
- declare class Image extends React.Component<ImageProps, any, any> {
35
- static getDerivedStateFromProps(props: any, state: any): {
36
- src: any;
37
- svg: any;
38
- created: boolean;
39
- color: any;
40
- showError: any;
41
- };
42
- constructor(props: any);
43
- state: {
44
- svg: boolean;
45
- created: boolean;
46
- color: string;
47
- src: string;
48
- imgError: boolean;
49
- showError: boolean;
50
- };
51
- svg: React.JSX.Element;
52
- getSvgFromData(src: any): React.JSX.Element;
53
- render(): React.JSX.Element;
54
8
  }
55
- declare namespace Image {
56
- namespace propTypes {
57
- let color: PropTypes.Requireable<string>;
58
- let src: PropTypes.Validator<string>;
59
- let className: PropTypes.Requireable<string>;
60
- let imagePrefix: PropTypes.Requireable<string>;
61
- }
9
+ interface ImageState {
10
+ svg?: boolean;
11
+ created?: boolean;
12
+ color?: string;
13
+ src?: string;
14
+ imgError?: boolean;
15
+ showError?: boolean;
16
+ }
17
+ declare class Image extends Component<ImageProps, ImageState> {
18
+ private svg;
19
+ constructor(props: ImageProps);
20
+ static getDerivedStateFromProps(props: ImageProps, state: ImageState): ImageState;
21
+ getSvgFromData(src: string): React.JSX.Element | null;
22
+ render(): React.JSX.Element;
62
23
  }
63
- import React from 'react';
64
- import PropTypes from 'prop-types';
24
+ export default Image;
@@ -1,174 +1,137 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
6
17
  });
7
- exports["default"] = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
- var _react = _interopRequireDefault(require("react"));
15
- var _propTypes = _interopRequireDefault(require("prop-types"));
16
- var _IconNoIcon = _interopRequireDefault(require("../icons/IconNoIcon"));
17
- 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); }; }
18
- 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; } }
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const IconNoIcon_1 = __importDefault(require("../icons/IconNoIcon"));
19
31
  function getElementFromSource(src) {
20
- var svgContainer = document.createElement('div');
21
- svgContainer.innerHTML = src;
22
- var svg = svgContainer.firstElementChild;
23
- if (svg.remove) {
24
- svg.remove();
25
- } else {
26
- svgContainer.removeChild(svg);
27
- }
28
- svgContainer.remove();
29
- return svg;
32
+ const svgContainer = document.createElement('div');
33
+ svgContainer.innerHTML = src;
34
+ const svg = svgContainer.firstElementChild;
35
+ if (svg === null || svg === void 0 ? void 0 : svg.remove) {
36
+ svg.remove();
37
+ }
38
+ else if (svg) {
39
+ svgContainer.removeChild(svg);
40
+ }
41
+ svgContainer.remove();
42
+ return svg;
30
43
  }
31
44
  function serializeAttrs(map) {
32
- var ret = {};
33
- for (var prop, i = 0; i < map.length; i++) {
34
- var key = map[i].name;
35
- if (key === 'class') {
36
- prop = 'className';
37
- } else if (!key.startsWith('data-')) {
38
- prop = key.replace(/[-|:]([a-z])/g, function (g) {
39
- return g[1].toUpperCase();
40
- });
41
- } else {
42
- prop = key;
45
+ const ret = {};
46
+ if (!map) {
47
+ return ret;
43
48
  }
44
- ret[prop] = map[i].value;
45
- }
46
- return ret;
49
+ for (let prop, i = 0; i < map.length; i++) {
50
+ const key = map[i].name;
51
+ if (key === 'class') {
52
+ prop = 'className';
53
+ }
54
+ else if (!key.startsWith('data-')) {
55
+ prop = key.replace(/[-|:]([a-z])/g, g => g[1].toUpperCase());
56
+ }
57
+ else {
58
+ prop = key;
59
+ }
60
+ ret[prop] = map[i].value;
61
+ }
62
+ return ret;
47
63
  }
48
-
49
- /**
50
- * @typedef {object} ImageProps
51
- * @property {string} [color] The color.
52
- * @property {string} [src] The source of the image.
53
- * @property {string} [imagePrefix] The image prefix (default: './files/')
54
- * @property {string} [className] The CSS class name.
55
- * @property {boolean} [showError] Show image errors (or just show no image)?
56
- *
57
- * @extends {React.Component<ImageProps>}
58
- */
59
- var Image = /*#__PURE__*/function (_React$Component) {
60
- (0, _inherits2["default"])(Image, _React$Component);
61
- var _super = _createSuper(Image);
62
- function Image(props) {
63
- var _this;
64
- (0, _classCallCheck2["default"])(this, Image);
65
- _this = _super.call(this, props);
66
- _this.state = {
67
- svg: !!(_this.props.src && _this.props.src.startsWith('data:')),
68
- created: true,
69
- color: _this.props.color || '',
70
- src: _this.props.src || '',
71
- imgError: false,
72
- showError: _this.props.showError
73
- };
74
- _this.svg = _this.state.svg ? _this.getSvgFromData(_this.state.src) : null;
75
- return _this;
76
- }
77
- (0, _createClass2["default"])(Image, [{
78
- key: "getSvgFromData",
79
- value: function getSvgFromData(src) {
80
- var len = 'data:image/svg+xml;base64,';
81
- if (!src.startsWith(len)) {
82
- return null;
83
- }
84
- src = src.substring(len.length);
85
- try {
86
- src = atob(src);
87
- var svg = getElementFromSource(src);
88
- var inner = svg.innerHTML;
89
- var svgProps = serializeAttrs(svg.attributes || []);
90
- svg.remove();
91
- return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
92
- className: this.props.className,
93
- style: this.state.color ? {
94
- color: this.state.color
95
- } : {}
96
- }, svgProps, {
97
- dangerouslySetInnerHTML: {
98
- __html: inner
99
- }
100
- }));
101
- } catch (e) {
102
- // ignore
103
- }
104
- return null;
64
+ class Image extends react_1.Component {
65
+ constructor(props) {
66
+ var _a;
67
+ super(props);
68
+ this.state = {
69
+ svg: !!((_a = this.props.src) === null || _a === void 0 ? void 0 : _a.startsWith('data:')),
70
+ created: true,
71
+ color: this.props.color || '',
72
+ src: this.props.src || '',
73
+ imgError: false,
74
+ showError: !!this.props.showError,
75
+ };
76
+ this.svg = this.state.svg && this.state.src ? this.getSvgFromData(this.state.src) : null;
105
77
  }
106
- }, {
107
- key: "render",
108
- value: function render() {
109
- var _this2 = this;
110
- if (this.state.svg) {
111
- if (!this.state.created) {
112
- setTimeout(function () {
113
- _this2.svg = _this2.getSvgFromData(_this2.state.src);
114
- _this2.setState({
115
- created: true
116
- });
117
- }, 50);
78
+ static getDerivedStateFromProps(props, state) {
79
+ var _a;
80
+ const newState = {};
81
+ let changed = false;
82
+ if (props && state && props.src !== state.src) {
83
+ newState.src = props.src;
84
+ newState.svg = (_a = props.src) === null || _a === void 0 ? void 0 : _a.startsWith('data:');
85
+ newState.created = false;
86
+ changed = true;
118
87
  }
119
- return this.svg;
120
- }
121
- if (this.state.src) {
122
- if (this.state.imgError || !this.state.src) {
123
- return /*#__PURE__*/_react["default"].createElement(_IconNoIcon["default"], {
124
- className: this.props.className
125
- });
88
+ if (props && state && props.color !== state.color) {
89
+ newState.color = props.color;
90
+ newState.created = false;
91
+ changed = true;
126
92
  }
127
- return /*#__PURE__*/_react["default"].createElement("img", {
128
- className: this.props.className,
129
- src: (this.props.imagePrefix || '') + this.state.src,
130
- alt: "",
131
- onError: function onError() {
132
- return _this2.props.showError ? _this2.setState({
133
- imgError: true
134
- }) : _this2.setState({
135
- src: ''
136
- });
137
- }
138
- });
139
- }
140
- return null;
93
+ if (props && state && props.showError !== state.showError) {
94
+ newState.showError = props.showError;
95
+ changed = true;
96
+ }
97
+ return changed ? newState : null;
141
98
  }
142
- }], [{
143
- key: "getDerivedStateFromProps",
144
- value: function getDerivedStateFromProps(props, state) {
145
- var newState = {};
146
- var changed = false;
147
- if (props && state && props.src !== state.src) {
148
- newState.src = props.src;
149
- newState.svg = props.src && props.src.startsWith('data:');
150
- newState.created = false;
151
- changed = true;
152
- }
153
- if (props && state && props.color !== state.color) {
154
- newState.color = props.color;
155
- newState.created = false;
156
- changed = true;
157
- }
158
- if (props && state && props.showError !== state.showError) {
159
- newState.showError = props.showError;
160
- changed = true;
161
- }
162
- return changed ? newState : null;
99
+ getSvgFromData(src) {
100
+ const len = 'data:image/svg+xml;base64,';
101
+ if (!src.startsWith(len)) {
102
+ return null;
103
+ }
104
+ src = src.substring(len.length);
105
+ try {
106
+ src = atob(src);
107
+ const svg = getElementFromSource(src);
108
+ const inner = svg.innerHTML;
109
+ const svgProps = serializeAttrs(svg.attributes);
110
+ svg.remove();
111
+ return react_1.default.createElement("svg", Object.assign({ className: this.props.className, style: this.state.color ? { color: this.state.color } : {} }, svgProps, { dangerouslySetInnerHTML: { __html: inner } }));
112
+ }
113
+ catch (e) {
114
+ // ignore
115
+ }
116
+ return null;
163
117
  }
164
- }]);
165
- return Image;
166
- }(_react["default"].Component);
167
- Image.propTypes = {
168
- color: _propTypes["default"].string,
169
- src: _propTypes["default"].string.isRequired,
170
- className: _propTypes["default"].string,
171
- imagePrefix: _propTypes["default"].string
172
- };
173
- var _default = exports["default"] = Image;
174
- //# sourceMappingURL=Image.js.map
118
+ render() {
119
+ if (this.state.svg) {
120
+ if (!this.state.created) {
121
+ setTimeout(() => {
122
+ this.svg = this.state.src ? this.getSvgFromData(this.state.src) : null;
123
+ this.setState({ created: true });
124
+ }, 50);
125
+ }
126
+ return this.svg;
127
+ }
128
+ if (this.state.src) {
129
+ if (this.state.imgError || !this.state.src) {
130
+ return react_1.default.createElement(IconNoIcon_1.default, { className: this.props.className });
131
+ }
132
+ return react_1.default.createElement("img", { className: this.props.className, src: (this.props.imagePrefix || '') + this.state.src, alt: "", onError: () => (this.props.showError ? this.setState({ imgError: true }) : this.setState({ src: '' })) });
133
+ }
134
+ return null;
135
+ }
136
+ }
137
+ exports.default = Image;
@@ -1,12 +1,12 @@
1
- export default MDUtils;
2
1
  declare class MDUtils {
3
- static text2link(text: any): any;
4
- static openLink(url: any, target: any): void;
5
- static getTitle(text: any): any;
6
- static extractHeader(text: any): {
7
- header: {};
8
- body: any;
2
+ static text2link(text: string): string;
3
+ static openLink(url: string, target?: string): void;
4
+ static getTitle(text: string): string | number | true;
5
+ static extractHeader(text: string): {
6
+ header: Record<string, string | boolean | number>;
7
+ body: string;
9
8
  };
10
- static removeDocsify(text: any): any;
11
- static onCopy(e: any, text: any): void;
9
+ static removeDocsify(text: string): string;
10
+ static onCopy(e: Event | null, text: string): void;
12
11
  }
12
+ export default MDUtils;