UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

104 lines (99 loc) 5.03 kB
/** * DevExtreme (cjs/file_management/custom_provider.js) * Version: 23.2.6 * Build date: Wed May 01 2024 * * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; exports.default = void 0; var _common = require("../core/utils/common"); var _type = require("../core/utils/type"); var _data = require("../core/utils/data"); var _provider_base = _interopRequireDefault(require("./provider_base")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass) } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) { o.__proto__ = p; return o }; return _setPrototypeOf(o, p) } let CustomFileSystemProvider = function(_FileSystemProviderBa) { _inheritsLoose(CustomFileSystemProvider, _FileSystemProviderBa); function CustomFileSystemProvider(options) { var _this; options = (0, _common.ensureDefined)(options, {}); _this = _FileSystemProviderBa.call(this, options) || this; _this._hasSubDirsGetter = (0, _data.compileGetter)(options.hasSubDirectoriesExpr || "hasSubDirectories"); _this._getItemsFunction = _this._ensureFunction(options.getItems, () => []); _this._renameItemFunction = _this._ensureFunction(options.renameItem); _this._createDirectoryFunction = _this._ensureFunction(options.createDirectory); _this._deleteItemFunction = _this._ensureFunction(options.deleteItem); _this._moveItemFunction = _this._ensureFunction(options.moveItem); _this._copyItemFunction = _this._ensureFunction(options.copyItem); _this._uploadFileChunkFunction = _this._ensureFunction(options.uploadFileChunk); _this._abortFileUploadFunction = _this._ensureFunction(options.abortFileUpload); _this._downloadItemsFunction = _this._ensureFunction(options.downloadItems); _this._getItemsContentFunction = _this._ensureFunction(options.getItemsContent); return _this } var _proto = CustomFileSystemProvider.prototype; _proto.getItems = function(parentDir) { const pathInfo = parentDir.getFullPathInfo(); return this._executeActionAsDeferred(() => this._getItemsFunction(parentDir), true).then(dataItems => this._convertDataObjectsToFileItems(dataItems, pathInfo)) }; _proto.renameItem = function(item, name) { return this._executeActionAsDeferred(() => this._renameItemFunction(item, name)) }; _proto.createDirectory = function(parentDir, name) { return this._executeActionAsDeferred(() => this._createDirectoryFunction(parentDir, name)) }; _proto.deleteItems = function(items) { return items.map(item => this._executeActionAsDeferred(() => this._deleteItemFunction(item))) }; _proto.moveItems = function(items, destinationDirectory) { return items.map(item => this._executeActionAsDeferred(() => this._moveItemFunction(item, destinationDirectory))) }; _proto.copyItems = function(items, destinationFolder) { return items.map(item => this._executeActionAsDeferred(() => this._copyItemFunction(item, destinationFolder))) }; _proto.uploadFileChunk = function(fileData, chunksInfo, destinationDirectory) { return this._executeActionAsDeferred(() => this._uploadFileChunkFunction(fileData, chunksInfo, destinationDirectory)) }; _proto.abortFileUpload = function(fileData, chunksInfo, destinationDirectory) { return this._executeActionAsDeferred(() => this._abortFileUploadFunction(fileData, chunksInfo, destinationDirectory)) }; _proto.downloadItems = function(items) { return this._executeActionAsDeferred(() => this._downloadItemsFunction(items)) }; _proto.getItemsContent = function(items) { return this._executeActionAsDeferred(() => this._getItemsContentFunction(items)) }; _proto._hasSubDirs = function(dataObj) { const hasSubDirs = this._hasSubDirsGetter(dataObj); return "boolean" === typeof hasSubDirs ? hasSubDirs : true }; _proto._getKeyExpr = function(options) { return options.keyExpr || "key" }; _proto._ensureFunction = function(functionObject, defaultFunction) { defaultFunction = defaultFunction || _common.noop; return (0, _type.isFunction)(functionObject) ? functionObject : defaultFunction }; return CustomFileSystemProvider }(_provider_base.default); var _default = CustomFileSystemProvider; exports.default = _default; module.exports = exports.default; module.exports.default = exports.default;