@iobroker/adapter-react-v5 4.10.1 → 4.10.4

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.
Files changed (43) hide show
  1. package/Components/CustomModal.d.ts +24 -2
  2. package/Components/CustomModal.js +77 -145
  3. package/Components/FileBrowser.d.ts +68 -130
  4. package/Components/FileBrowser.js +1405 -1987
  5. package/Components/FileViewer.d.ts +9 -82
  6. package/Components/FileViewer.js +248 -321
  7. package/Components/IconSelector.d.ts +28 -22
  8. package/Components/IconSelector.js +2122 -2073
  9. package/Components/Loader.d.ts +8 -3
  10. package/Components/Loader.js +4 -2
  11. package/Components/Loaders/MV.d.ts +12 -0
  12. package/Components/Loaders/MV.js +51 -0
  13. package/Components/Loaders/PT.d.ts +19 -38
  14. package/Components/Loaders/PT.js +153 -78
  15. package/Components/Loaders/Vendor.d.ts +19 -31
  16. package/Components/Loaders/Vendor.js +61 -79
  17. package/Components/SelectWithIcon.d.ts +23 -20
  18. package/Components/SelectWithIcon.js +143 -204
  19. package/Components/types.d.ts +0 -47
  20. package/Dialogs/Error.d.ts +3 -5
  21. package/Dialogs/Error.js +1 -3
  22. package/Dialogs/SelectFile.d.ts +53 -170
  23. package/Dialogs/SelectFile.js +100 -257
  24. package/README.md +3 -0
  25. package/icons/IconClearFilter.js.map +1 -1
  26. package/icons/IconClosed.js.map +1 -1
  27. package/icons/IconCopy.js.map +1 -1
  28. package/icons/IconDocumentReadOnly.js.map +1 -1
  29. package/icons/IconExpert.d.ts +10 -36
  30. package/icons/IconExpert.js +8 -42
  31. package/index.d.ts +2 -0
  32. package/index.js +5 -2
  33. package/package.json +2 -2
  34. package/types.d.ts +9 -7
  35. package/Components/CustomModal.js.map +0 -1
  36. package/Components/FileBrowser.js.map +0 -1
  37. package/Components/FileViewer.js.map +0 -1
  38. package/Components/IconSelector.js.map +0 -1
  39. package/Components/Loaders/PT.js.map +0 -1
  40. package/Components/Loaders/Vendor.js.map +0 -1
  41. package/Components/SelectWithIcon.js.map +0 -1
  42. package/Dialogs/SelectFile.js.map +0 -1
  43. package/icons/IconExpert.js.map +0 -1
@@ -1,350 +1,277 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- 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;
7
17
  });
8
- exports["default"] = exports.EXTENSIONS = void 0;
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- var _react = _interopRequireWildcard(require("react"));
17
- var _styles = require("@mui/styles");
18
- var _propTypes = _interopRequireDefault(require("prop-types"));
19
- var _material = require("@mui/material");
20
- var _fa = require("react-icons/fa");
21
- var _iconsMaterial = require("@mui/icons-material");
22
- var _IconNoIcon = _interopRequireDefault(require("../icons/IconNoIcon"));
23
- var _withWidth = _interopRequireDefault(require("./withWidth"));
24
- var _Utils = _interopRequireDefault(require("./Utils"));
25
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
26
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
27
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
28
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } // File viewer in adapter-react does not support write
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
+ exports.EXTENSIONS = void 0;
30
+ // File viewer in adapter-react does not support write
29
31
  // import { Buffer } from 'buffer';
32
+ const react_1 = __importStar(require("react"));
33
+ const styles_1 = require("@mui/styles");
34
+ const material_1 = require("@mui/material");
30
35
  // Icons
36
+ const fa_1 = require("react-icons/fa");
37
+ const icons_material_1 = require("@mui/icons-material");
38
+ const IconNoIcon_1 = __importDefault(require("../icons/IconNoIcon"));
39
+ const withWidth_1 = __importDefault(require("./withWidth"));
40
+ const Utils_1 = __importDefault(require("./Utils"));
31
41
  // File viewer in adapter-react does not use ace editor
32
42
  // import Editor from './Editor';
33
-
34
- var styles = function styles() {
35
- return {
43
+ const styles = {
36
44
  dialog: {
37
- height: '100%'
45
+ height: '100%',
38
46
  },
39
47
  paper: {
40
- height: 'calc(100% - 64px)'
48
+ height: 'calc(100% - 64px)',
41
49
  },
42
50
  content: {
43
- textAlign: 'center'
51
+ textAlign: 'center',
44
52
  },
45
53
  textarea: {
46
- width: '100%',
47
- height: '100%'
54
+ width: '100%',
55
+ height: '100%',
48
56
  },
49
57
  img: {
50
- width: 'auto',
51
- height: 'calc(100% - 5px)',
52
- objectFit: 'contain'
58
+ width: 'auto',
59
+ height: 'calc(100% - 5px)',
60
+ objectFit: 'contain',
53
61
  },
54
62
  dialogTitle: {
55
- justifyContent: 'space-between',
56
- display: 'flex'
57
- }
58
- };
63
+ justifyContent: 'space-between',
64
+ display: 'flex',
65
+ },
59
66
  };
60
- var EXTENSIONS = exports.EXTENSIONS = {
61
- images: ['png', 'jpg', 'svg', 'jpeg', 'bmp', 'gif', 'apng', 'avif', 'webp'],
62
- code: ['js', 'json', 'json5', 'md'],
63
- txt: ['log', 'txt', 'html', 'css', 'xml'],
64
- audio: ['mp3', 'wav', 'ogg', 'acc'],
65
- video: ['mp4', 'mov', 'avi']
67
+ exports.EXTENSIONS = {
68
+ images: ['png', 'jpg', 'svg', 'jpeg', 'bmp', 'gif', 'apng', 'avif', 'webp'],
69
+ code: ['js', 'json', 'json5', 'md'],
70
+ txt: ['log', 'txt', 'html', 'css', 'xml'],
71
+ audio: ['mp3', 'wav', 'ogg', 'acc'],
72
+ video: ['mp4', 'mov', 'avi'],
66
73
  };
67
74
  function bufferToBase64(buffer, isFull) {
68
- var binary = '';
69
- var bytes = new Uint8Array(buffer);
70
- var len = bytes.byteLength;
71
- for (var i = 0; i < len && (isFull || i < 50); i++) {
72
- binary += String.fromCharCode(bytes[i]);
73
- }
74
- return window.btoa(binary);
75
+ let binary = '';
76
+ const bytes = new Uint8Array(buffer);
77
+ const len = bytes.byteLength;
78
+ for (let i = 0; i < len && (isFull || i < 50); i++) {
79
+ binary += String.fromCharCode(bytes[i]);
80
+ }
81
+ return window.btoa(binary);
75
82
  }
76
-
77
- /**
78
- * @typedef {object} FileViewerProps
79
- * @property {string} [key] The key to identify this component.
80
- * @property {import('../types').Translator} t Translation function
81
- * @property {ioBroker.Languages} [lang] The selected language.
82
- * @property {boolean} [expertMode] Is expert mode enabled? (default: false)
83
- * @property {() => void} onClose Callback when the viewer is closed.
84
- * @property {string} href The URL to the file to be displayed.
85
- *
86
- * @extends {React.Component<FileViewerProps>}
87
- */
88
- var FileViewer = /*#__PURE__*/function (_Component) {
89
- (0, _inherits2["default"])(FileViewer, _Component);
90
- /**
91
- * @param {Readonly<FileViewerProps>} props
92
- */
93
- function FileViewer(props) {
94
- var _this;
95
- (0, _classCallCheck2["default"])(this, FileViewer);
96
- _this = _callSuper(this, FileViewer, [props]);
97
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onFileChanged", function (id, fileName, size) {
98
- if (!_this.state.changed) {
99
- _this.timeout && clearTimeout(_this.timeout);
100
- _this.timeout = setTimeout(function () {
101
- _this.timeout = null;
102
- if (size === null) {
103
- window.alert('Show file was deleted!');
104
- } else if (_this.state.text !== null || _this.state.code !== null) {
105
- _this.readFile();
106
- } else {
107
- _this.setState({
108
- forceUpdate: Date.now()
109
- });
110
- }
111
- }, 300);
112
- }
113
- });
114
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "writeFile64", function () {
115
- /*
116
- // File viewer in adapter-react does not support write
117
- const parts = this.props.href.split('/');
118
- const data = this.state.editingValue;
119
- parts.splice(0, 2);
120
- const adapter = parts[0];
121
- const name = parts.splice(1).join('/');
122
- this.props.socket.writeFile64(adapter, name, Buffer.from(data).toString('base64'))
123
- .then(() => this.props.onClose())
124
- .catch(e => window.alert(`Cannot write file: ${e}`));
125
- */
126
- });
127
- var ext = _Utils["default"].getFileExtension(_this.props.href);
128
- _this.state = {
129
- text: null,
130
- code: null,
131
- ext: ext,
132
- // File viewer in adapter-react does not support write
133
- editing: /* !!this.props.formatEditFile || */false,
134
- editingValue: null,
135
- copyPossible: EXTENSIONS.code.includes(ext) || EXTENSIONS.txt.includes(ext),
136
- forceUpdate: Date.now(),
137
- changed: false,
138
- imgError: false
139
- };
140
- return _this;
141
- }
142
- (0, _createClass2["default"])(FileViewer, [{
143
- key: "readFile",
144
- value: function readFile() {
145
- var _this2 = this;
146
- if (this.props.href) {
147
- var parts = this.props.href.split('/');
148
- parts.splice(0, 2);
149
- var adapter = parts[0];
150
- var name = parts.splice(1).join('/');
151
- this.props.socket.readFile(adapter, name).then(function (data) {
152
- if (data.file !== undefined) {
153
- data = data.file;
154
- }
155
- var newState = {
156
- copyPossible: _this2.state.copyPossible,
157
- ext: _this2.state.ext
158
- };
159
- // try to detect valid extension
160
- if (data.type === 'Buffer') {
161
- if (name.toLowerCase().endsWith('.json5')) {
162
- newState.ext = 'json5';
163
- newState.copyPossible = true;
164
- try {
165
- data = atob(bufferToBase64(data.data, true));
166
- } catch (e) {
167
- console.error('Cannot convert base64 to string');
168
- data = '';
169
- }
170
- } else {
171
- var ext = _Utils["default"].detectMimeType(bufferToBase64(data.data));
172
- if (ext) {
173
- newState.ext = ext;
174
- newState.copyPossible = EXTENSIONS.code.includes(ext) || EXTENSIONS.txt.includes(ext);
175
- }
83
+ class FileViewer extends react_1.Component {
84
+ constructor(props) {
85
+ super(props);
86
+ this.timeout = null;
87
+ this.onFileChanged = (id, fileName, size) => {
88
+ if (!this.state.changed) {
89
+ this.timeout && clearTimeout(this.timeout);
90
+ this.timeout = setTimeout(() => {
91
+ this.timeout = null;
92
+ if (size === null) {
93
+ window.alert('Show file was deleted!');
94
+ }
95
+ else if (this.state.text !== null || this.state.code !== null) {
96
+ this.readFile();
97
+ }
98
+ else {
99
+ this.setState({ forceUpdate: Date.now() });
100
+ }
101
+ }, 300);
176
102
  }
177
- }
178
- if (newState.copyPossible) {
179
- if (EXTENSIONS.txt.includes(newState.ext)) {
180
- newState.text = data;
181
- newState.editingValue = data;
182
- } else if (EXTENSIONS.code.includes(newState.ext)) {
183
- newState.code = data;
184
- newState.editingValue = data;
185
- }
186
- }
187
- _this2.setState(newState);
188
- })["catch"](function (e) {
189
- return window.alert("Cannot read file: ".concat(e));
190
- });
191
- }
103
+ };
104
+ this.writeFile64 = () => {
105
+ /*
106
+ // File viewer in adapter-react does not support write
107
+ const parts = this.props.href.split('/');
108
+ const data = this.state.editingValue;
109
+ parts.splice(0, 2);
110
+ const adapter = parts[0];
111
+ const name = parts.splice(1).join('/');
112
+ this.props.socket.writeFile64(adapter, name, Buffer.from(data).toString('base64'))
113
+ .then(() => this.props.onClose())
114
+ .catch(e => window.alert(`Cannot write file: ${e}`));
115
+ */
116
+ };
117
+ const ext = Utils_1.default.getFileExtension(props.href);
118
+ this.state = {
119
+ text: null,
120
+ code: null,
121
+ ext,
122
+ // File viewer in adapter-react does not support write
123
+ editing: /* !!this.props.formatEditFile || */ false,
124
+ editingValue: null,
125
+ copyPossible: !!ext && (exports.EXTENSIONS.code.includes(ext) || exports.EXTENSIONS.txt.includes(ext)),
126
+ forceUpdate: Date.now(),
127
+ changed: false,
128
+ imgError: false,
129
+ };
192
130
  }
193
- }, {
194
- key: "componentDidMount",
195
- value: function componentDidMount() {
196
- this.readFile();
197
- var parts = this.props.href.split('/');
198
- parts.splice(0, 2);
199
- var adapter = parts[0];
200
- var name = parts.splice(1).join('/');
201
- this.props.supportSubscribes && this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
131
+ readFile() {
132
+ if (this.props.href) {
133
+ const parts = this.props.href.split('/');
134
+ parts.splice(0, 2);
135
+ const adapter = parts[0];
136
+ const name = parts.splice(1).join('/');
137
+ this.props.socket.readFile(adapter, name)
138
+ .then((data) => {
139
+ let fileData = '';
140
+ if (data.file !== undefined) {
141
+ fileData = data.file;
142
+ }
143
+ const newState = { copyPossible: this.state.copyPossible, ext: this.state.ext };
144
+ // try to detect valid extension
145
+ if (data.type === 'Buffer') {
146
+ if (name.toLowerCase().endsWith('.json5')) {
147
+ newState.ext = 'json5';
148
+ newState.copyPossible = true;
149
+ try {
150
+ fileData = atob(bufferToBase64(data.data, true));
151
+ }
152
+ catch (e) {
153
+ console.error('Cannot convert base64 to string');
154
+ fileData = '';
155
+ }
156
+ }
157
+ else {
158
+ const ext = Utils_1.default.detectMimeType(bufferToBase64(data.data));
159
+ if (ext) {
160
+ newState.ext = ext;
161
+ newState.copyPossible = exports.EXTENSIONS.code.includes(ext) || exports.EXTENSIONS.txt.includes(ext);
162
+ }
163
+ }
164
+ }
165
+ if (newState.copyPossible) {
166
+ if (newState.ext && exports.EXTENSIONS.txt.includes(newState.ext)) {
167
+ newState.text = fileData;
168
+ newState.editingValue = fileData;
169
+ }
170
+ else if (newState.ext && exports.EXTENSIONS.code.includes(newState.ext)) {
171
+ newState.code = fileData;
172
+ newState.editingValue = fileData;
173
+ }
174
+ }
175
+ // @ts-expect-error I don't know how to fix it
176
+ this.setState(newState);
177
+ })
178
+ .catch(e => window.alert(`Cannot read file: ${e}`));
179
+ }
202
180
  }
203
- }, {
204
- key: "componentWillUnmount",
205
- value: function componentWillUnmount() {
206
- this.timeout && clearTimeout(this.timeout);
207
- var parts = this.props.href.split('/');
208
- parts.splice(0, 2);
209
- var adapter = parts[0];
210
- var name = parts.splice(1).join('/');
211
- this.props.supportSubscribes && this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
181
+ componentDidMount() {
182
+ this.readFile();
183
+ const parts = this.props.href.split('/');
184
+ parts.splice(0, 2);
185
+ const adapter = parts[0];
186
+ const name = parts.splice(1).join('/');
187
+ this.props.supportSubscribes && this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
188
+ }
189
+ componentWillUnmount() {
190
+ this.timeout && clearTimeout(this.timeout);
191
+ const parts = this.props.href.split('/');
192
+ parts.splice(0, 2);
193
+ const adapter = parts[0];
194
+ const name = parts.splice(1).join('/');
195
+ this.props.supportSubscribes && this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
212
196
  }
213
- }, {
214
- key: "getContent",
215
- value: function getContent() {
216
- var _this3 = this;
217
- if (EXTENSIONS.images.includes(this.state.ext)) {
218
- if (this.state.imgError) {
219
- return /*#__PURE__*/_react["default"].createElement(_IconNoIcon["default"], {
220
- className: _Utils["default"].clsx(this.props.classes.img, this.props.getClassBackgroundImage())
221
- });
197
+ static getEditFile(ext) {
198
+ switch (ext) {
199
+ case 'json':
200
+ return 'json';
201
+ case 'json5':
202
+ return 'json5';
203
+ case 'js':
204
+ return 'javascript';
205
+ case 'html':
206
+ return 'html';
207
+ case 'txt':
208
+ return 'html';
209
+ default:
210
+ return 'json';
222
211
  }
223
- return /*#__PURE__*/_react["default"].createElement("img", {
224
- onError: function onError(e) {
225
- e.target.onerror = null;
226
- _this3.setState({
227
- imgError: true
228
- });
229
- },
230
- className: _Utils["default"].clsx(this.props.classes.img, this.props.getClassBackgroundImage()),
231
- src: "".concat(this.props.href, "?ts=").concat(this.state.forceUpdate),
232
- alt: this.props.href
233
- });
234
- }
235
- if (this.state.code !== null || this.state.text !== null || this.state.editing) {
236
- // File viewer in adapter-react does not support write
237
- // return <AceEditor
238
- // mode={FileViewer.getEditFile(this.props.formatEditFile)}
239
- // width="100%"
240
- // height="100%"
241
- // theme={this.props.themeName === 'dark' ? 'clouds_midnight' : 'chrome'}
242
- // value={this.state.editingValue || this.state.code || this.state.text}
243
- // onChange={newValue => this.setState({ editingValue: newValue, changed: true })}
244
- // name="UNIQUE_ID_OF_DIV"
245
- // readOnly={!this.state.editing}
246
- // fontSize={14}
247
- // setOptions={{
248
- // enableBasicAutocompletion: true,
249
- // enableLiveAutocompletion: true,
250
- // enableSnippets: true,
251
- // }}
252
- // editorProps={{ $blockScrolling: true }}
253
- // />;
254
- return /*#__PURE__*/_react["default"].createElement(_material.TextField, {
255
- variant: "standard",
256
- className: this.props.classes.textarea,
257
- multiline: true,
258
- inputProps: {
259
- readOnly: !this.state.editing
260
- },
261
- value: this.state.editingValue || this.state.code || this.state.text
262
- // onChange={newValue => this.setState({ editingValue: newValue, changed: true })}
263
- ,
264
- InputProps: {
265
- readOnly: !this.state.editing
266
- }
267
- });
268
- }
269
- return null;
270
212
  }
271
- }, {
272
- key: "render",
273
- value: function render() {
274
- var _this4 = this;
275
- return /*#__PURE__*/_react["default"].createElement(_material.Dialog, {
276
- classes: {
277
- scrollPaper: this.props.classes.dialog,
278
- paper: this.props.classes.paper
279
- },
280
- scroll: "paper",
281
- open: !!this.props.href,
282
- onClose: function onClose() {
283
- return _this4.props.onClose();
284
- },
285
- fullWidth: true,
286
- maxWidth: "xl",
287
- "aria-labelledby": "ar_dialog_file_view_title"
288
- }, /*#__PURE__*/_react["default"].createElement("div", {
289
- className: this.props.classes.dialogTitle
290
- }, /*#__PURE__*/_react["default"].createElement(_material.DialogTitle, {
291
- id: "ar_dialog_file_view_title"
292
- }, "".concat(this.props.t(this.state.editing ? 'Edit' : 'View'), ": ").concat(this.props.href)), EXTENSIONS.images.includes(this.state.ext) && /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_material.IconButton, {
293
- size: "large",
294
- color: "inherit",
295
- onClick: this.props.setStateBackgroundImage
296
- }, /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Brightness6, null)))), /*#__PURE__*/_react["default"].createElement(_material.DialogContent, {
297
- className: this.props.classes.content
298
- }, this.getContent()), /*#__PURE__*/_react["default"].createElement(_material.DialogActions, null, this.state.copyPossible ? /*#__PURE__*/_react["default"].createElement(_material.Button, {
299
- color: "grey",
300
- onClick: function onClick(e) {
301
- return _Utils["default"].copyToClipboard(_this4.state.text || _this4.state.code, e);
302
- },
303
- startIcon: /*#__PURE__*/_react["default"].createElement(_fa.FaCopy, null)
304
- }, this.props.t('Copy content')) : null, this.state.editing ? /*#__PURE__*/_react["default"].createElement(_material.Button, {
305
- color: "grey",
306
- disabled: this.state.editingValue === this.state.code || this.state.editingValue === this.state.text,
307
- variant: "contained",
308
- onClick: this.writeFile64,
309
- startIcon: /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Save, null)
310
- }, this.props.t('Save')) : null, /*#__PURE__*/_react["default"].createElement(_material.Button, {
311
- variant: "contained",
312
- onClick: function onClick() {
313
- return _this4.props.onClose();
314
- },
315
- color: "primary",
316
- startIcon: /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Close, null)
317
- }, this.props.t('Close'))));
213
+ getContent() {
214
+ if (this.state.ext && exports.EXTENSIONS.images.includes(this.state.ext)) {
215
+ if (this.state.imgError) {
216
+ return react_1.default.createElement(IconNoIcon_1.default, { className: Utils_1.default.clsx(this.props.classes.img, this.props.getClassBackgroundImage()) });
217
+ }
218
+ return react_1.default.createElement("img", { onError: e => {
219
+ // @ts-ignore-error to check
220
+ e.target.onerror = null;
221
+ this.setState({ imgError: true });
222
+ }, className: Utils_1.default.clsx(this.props.classes.img, this.props.getClassBackgroundImage()), src: `${this.props.href}?ts=${this.state.forceUpdate}`, alt: this.props.href });
223
+ }
224
+ if (this.state.code !== null || this.state.text !== null || this.state.editing) {
225
+ // File viewer in adapter-react does not support write
226
+ // return <AceEditor
227
+ // mode={FileViewer.getEditFile(this.props.formatEditFile)}
228
+ // width="100%"
229
+ // height="100%"
230
+ // theme={this.props.themeName === 'dark' ? 'clouds_midnight' : 'chrome'}
231
+ // value={this.state.editingValue || this.state.code || this.state.text}
232
+ // onChange={newValue => this.setState({ editingValue: newValue, changed: true })}
233
+ // name="UNIQUE_ID_OF_DIV"
234
+ // readOnly={!this.state.editing}
235
+ // fontSize={14}
236
+ // setOptions={{
237
+ // enableBasicAutocompletion: true,
238
+ // enableLiveAutocompletion: true,
239
+ // enableSnippets: true,
240
+ // }}
241
+ // editorProps={{ $blockScrolling: true }}
242
+ // />;
243
+ return react_1.default.createElement(material_1.TextField, { variant: "standard", className: this.props.classes.textarea, multiline: true, inputProps: { readOnly: !this.state.editing }, value: this.state.editingValue || this.state.code || this.state.text,
244
+ // onChange={newValue => this.setState({ editingValue: newValue, changed: true })}
245
+ InputProps: { readOnly: !this.state.editing } });
246
+ }
247
+ return null;
318
248
  }
319
- }], [{
320
- key: "getEditFile",
321
- value: function getEditFile(ext) {
322
- switch (ext) {
323
- case 'json':
324
- return 'json';
325
- case 'json5':
326
- return 'json5';
327
- case 'js':
328
- return 'javascript';
329
- case 'html':
330
- return 'html';
331
- case 'txt':
332
- return 'html';
333
- default:
334
- return 'json';
335
- }
249
+ render() {
250
+ return react_1.default.createElement(material_1.Dialog, { classes: { scrollPaper: this.props.classes.dialog, paper: this.props.classes.paper }, scroll: "paper", open: !!this.props.href, onClose: () => this.props.onClose(), fullWidth: true, maxWidth: "xl", "aria-labelledby": "ar_dialog_file_view_title" },
251
+ react_1.default.createElement("div", { className: this.props.classes.dialogTitle },
252
+ react_1.default.createElement(material_1.DialogTitle, { id: "ar_dialog_file_view_title" }, `${this.props.t(this.state.editing ? 'Edit' : 'View')}: ${this.props.href}`),
253
+ this.state.ext && exports.EXTENSIONS.images.includes(this.state.ext) && react_1.default.createElement("div", null,
254
+ react_1.default.createElement(material_1.IconButton, { size: "large", color: "inherit", onClick: this.props.setStateBackgroundImage },
255
+ react_1.default.createElement(icons_material_1.Brightness6, null)))),
256
+ react_1.default.createElement(material_1.DialogContent, { className: this.props.classes.content }, this.getContent()),
257
+ react_1.default.createElement(material_1.DialogActions, null,
258
+ this.state.copyPossible ?
259
+ react_1.default.createElement(material_1.Button
260
+ // @ts-expect-error grey is valid color
261
+ , {
262
+ // @ts-expect-error grey is valid color
263
+ color: "grey", onClick: e => {
264
+ e.stopPropagation();
265
+ e.preventDefault();
266
+ Utils_1.default.copyToClipboard(this.state.text || this.state.code || '');
267
+ }, startIcon: react_1.default.createElement(fa_1.FaCopy, null) }, this.props.t('Copy content')) : null,
268
+ this.state.editing ?
269
+ react_1.default.createElement(material_1.Button
270
+ // @ts-expect-error grey is valid color
271
+ , {
272
+ // @ts-expect-error grey is valid color
273
+ color: "grey", disabled: this.state.editingValue === this.state.code || this.state.editingValue === this.state.text, variant: "contained", onClick: this.writeFile64, startIcon: react_1.default.createElement(icons_material_1.Save, null) }, this.props.t('Save')) : null,
274
+ react_1.default.createElement(material_1.Button, { variant: "contained", onClick: () => this.props.onClose(), color: "primary", startIcon: react_1.default.createElement(icons_material_1.Close, null) }, this.props.t('Close'))));
336
275
  }
337
- }]);
338
- return FileViewer;
339
- }(_react.Component);
340
- FileViewer.propTypes = {
341
- t: _propTypes["default"].func,
342
- onClose: _propTypes["default"].func,
343
- href: _propTypes["default"].string.isRequired,
344
- supportSubscribes: _propTypes["default"].bool
345
- };
346
-
347
- /** @type {typeof FileViewer} */
348
- var _export = (0, _withWidth["default"])()((0, _styles.withStyles)(styles)(FileViewer));
349
- var _default = exports["default"] = _export;
350
- //# sourceMappingURL=FileViewer.js.map
276
+ }
277
+ exports.default = (0, withWidth_1.default)()((0, styles_1.withStyles)(styles)(FileViewer));