@iobroker/adapter-react-v5 4.9.1 → 4.9.3
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/Components/CopyToClipboard.d.ts +6 -0
- package/Components/CopyToClipboard.js +158 -0
- package/Components/Image.d.ts +17 -57
- package/Components/Image.js +125 -162
- package/Components/MDUtils.d.ts +9 -9
- package/Components/MDUtils.js +82 -109
- package/Components/ObjectBrowser.d.ts +1 -1
- package/Components/TextWithIcon.d.ts +1 -1
- package/Components/Utils.d.ts +123 -187
- package/Components/Utils.js +1300 -1502
- package/Dialogs/SelectID.js +8 -8
- package/LegacyConnection.d.ts +3 -3
- package/Prompt.d.ts +1 -1
- package/Prompt.js +14 -12
- package/README.md +6 -0
- package/i18n.d.ts +6 -6
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +2 -2
- package/Components/Image.js.map +0 -1
- package/Components/MDUtils.js.map +0 -1
- package/Components/Utils.js.map +0 -1
- package/Components/copy-to-clipboard.d.ts +0 -2
- package/Components/copy-to-clipboard.js +0 -161
- package/Components/copy-to-clipboard.js.map +0 -1
- package/Prompt.js.map +0 -1
|
@@ -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;
|
package/Components/Image.d.ts
CHANGED
|
@@ -1,64 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
import PropTypes from 'prop-types';
|
|
24
|
+
export default Image;
|
package/Components/Image.js
CHANGED
|
@@ -1,174 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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;
|
package/Components/MDUtils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export default MDUtils;
|
|
2
1
|
declare class MDUtils {
|
|
3
|
-
static text2link(text:
|
|
4
|
-
static openLink(url:
|
|
5
|
-
static getTitle(text:
|
|
6
|
-
static extractHeader(text:
|
|
7
|
-
header:
|
|
8
|
-
body:
|
|
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:
|
|
11
|
-
static onCopy(e:
|
|
9
|
+
static removeDocsify(text: string): string;
|
|
10
|
+
static onCopy(e: Event | null, text: string): void;
|
|
12
11
|
}
|
|
12
|
+
export default MDUtils;
|