UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

103 lines (102 loc) 3.82 kB
/** * DevExtreme (esm/__internal/file_management/file_system_item.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 { isString } from "../../core/utils/type"; import { getEscapedFileName, getFileExtension, getName, getPathParts, PATH_SEPARATOR, pathCombine } from "../file_management/utils"; class FileSystemItem { constructor() { if (isString(arguments.length <= 0 ? void 0 : arguments[0])) { this._publicCtor(arguments.length <= 0 ? void 0 : arguments[0], arguments.length <= 1 ? void 0 : arguments[1], arguments.length <= 2 ? void 0 : arguments[2]) } else { this._internalCtor(arguments.length <= 0 ? void 0 : arguments[0], arguments.length <= 1 ? void 0 : arguments[1], arguments.length <= 2 ? void 0 : arguments[2], arguments.length <= 3 ? void 0 : arguments[3]) } } _internalCtor(pathInfo, name, isDirectory, key) { this.name = name || ""; this.pathInfo = pathInfo ? [...pathInfo] : []; this.parentPath = this._getPathByPathInfo(this.pathInfo); this.relativeName = pathCombine(this.parentPath, name); this.key = key || this._getPathByPathInfo(this.getFullPathInfo(), true); this.path = pathCombine(this.parentPath, name); this.pathKeys = this.pathInfo.map((info => info.key)); if (!this.isRoot()) { this.pathKeys.push(this.key) } this._initialize(isDirectory) } _publicCtor(path, isDirectory, pathKeys) { this.path = path || ""; this.pathKeys = pathKeys ?? []; const pathInfo = []; const parts = getPathParts(path, true); for (let i = 0; i < parts.length - 1; i += 1) { const part = parts[i]; const pathInfoPart = { key: this.pathKeys[i] || part, name: getName(part) }; pathInfo.push(pathInfoPart) } this.pathInfo = pathInfo; this.relativeName = path; this.name = getName(path); this.key = this.pathKeys.length ? this.pathKeys[this.pathKeys.length - 1] : path; this.parentPath = parts.length > 1 ? parts[parts.length - 2] : ""; this._initialize(isDirectory) } _initialize(isDirectory) { this.isDirectory = !!isDirectory; this.size = 0; this.dateModified = new Date; this.thumbnail = ""; this.tooltipText = "" } getFullPathInfo() { const pathInfo = [...this.pathInfo ?? []]; if (!this.isRoot()) { pathInfo.push({ key: this.key, name: this.name }) } return pathInfo } isRoot() { return "" === this.path } getFileExtension() { return this.isDirectory ? "" : getFileExtension(this.name) } equals(item) { return item && this.key === item.key } createClone() { const result = new FileSystemItem(this.pathInfo, this.name, this.isDirectory, this.key); result.key = this.key; result.size = this.size; result.dateModified = this.dateModified; result.thumbnail = this.thumbnail; result.tooltipText = this.tooltipText; result.hasSubDirectories = this.hasSubDirectories; result.dataItem = this.dataItem; return result } _getPathByPathInfo(pathInfo, escape) { return pathInfo.map((info => escape ? getEscapedFileName(info.name) : info.name)).join(PATH_SEPARATOR) } } export default FileSystemItem;