UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

108 lines (107 loc) 3.56 kB
/** * DevExtreme (esm/__internal/ui/chat/file_view/file_view.js) * Version: 25.2.5 * Build date: Fri Feb 20 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import messageLocalization from "../../../../common/core/localization/message"; import $ from "../../../../core/renderer"; import DOMComponent from "../../../core/widget/dom_component"; import File from "../../../ui/chat/file_view/file"; export const CHAT_FILE_VIEW_CLASS = "dx-chat-file-view"; class FileView extends DOMComponent { constructor() { super(...arguments); this._fileInstances = [] } _getDefaultOptions() { return Object.assign({}, super._getDefaultOptions(), { files: [], activeStateEnabled: true, focusStateEnabled: true, hoverStateEnabled: true }) } _initMarkup() { this.$element().addClass("dx-chat-file-view"); super._initMarkup(); this._renderItems(); this._toggleAria() } _renderItems() { const { files: files = [] } = this.option(); this._clearFileInstances(); files.forEach((file => { this._renderItem(file) })) } _renderItem(data) { const $file = $("<div>"); const fileInstance = this._createComponent($file, File, this._getFileConfig(data)); this.$element().append($file); this._fileInstances.push(fileInstance) } _getFileConfig(data) { const { activeStateEnabled: activeStateEnabled, focusStateEnabled: focusStateEnabled, hoverStateEnabled: hoverStateEnabled, onDownload: onDownload } = this.option(); const configuration = { data: data, activeStateEnabled: activeStateEnabled, focusStateEnabled: focusStateEnabled, hoverStateEnabled: hoverStateEnabled, onDownload: onDownload }; return configuration } _toggleAria() { const { files: files } = this.option(); const applyAria = Boolean(null === files || void 0 === files ? void 0 : files.length); const aria = { role: applyAria ? "list" : null, "aria-label": applyAria ? messageLocalization.format("dxChat-fileViewLabel") : null }; this.$element().attr(aria) } _clearFileInstances() { var _this$_fileInstances; null === (_this$_fileInstances = this._fileInstances) || void 0 === _this$_fileInstances || _this$_fileInstances.forEach((instance => { instance.dispose() })); this._fileInstances = []; this.$element().empty() } _dispose() { this._clearFileInstances(); super._dispose() } _optionChanged(args) { const { name: name } = args; switch (name) { case "activeStateEnabled": case "focusStateEnabled": case "hoverStateEnabled": case "onDownload": this._renderItems(); break; case "files": this._renderItems(); this._toggleAria(); break; default: super._optionChanged(args) } } } export default FileView;