| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- /**
- * DevExtreme (ui/file_manager/file_provider/array.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- var _common = require("../../../core/utils/common");
- var _data = require("../../../core/utils/data");
- var _iterator = require("../../../core/utils/iterator");
- var _type = require("../../../core/utils/type");
- var _type2 = _interopRequireDefault(_type);
- var _errors = require("../../../data/errors");
- var _file_provider = require("./file_provider");
- var _uiFile_manager = require("../ui.file_manager.common");
- var _uiFile_manager2 = require("../ui.file_manager.utils");
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {
- "default": obj
- }
- }
- function _typeof(obj) {
- "@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
- return typeof obj
- } : function(obj) {
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
- }, _typeof(obj)
- }
- function _classCallCheck(instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function")
- }
- }
- function _defineProperties(target, props) {
- for (var i = 0; i < props.length; i++) {
- var descriptor = props[i];
- descriptor.enumerable = descriptor.enumerable || false;
- descriptor.configurable = true;
- if ("value" in descriptor) {
- descriptor.writable = true
- }
- Object.defineProperty(target, descriptor.key, descriptor)
- }
- }
- function _createClass(Constructor, protoProps, staticProps) {
- if (protoProps) {
- _defineProperties(Constructor.prototype, protoProps)
- }
- if (staticProps) {
- _defineProperties(Constructor, staticProps)
- }
- Object.defineProperty(Constructor, "prototype", {
- writable: false
- });
- return Constructor
- }
- function _inherits(subClass, superClass) {
- if ("function" !== typeof superClass && null !== superClass) {
- throw new TypeError("Super expression must either be null or a function")
- }
- subClass.prototype = Object.create(superClass && superClass.prototype, {
- constructor: {
- value: subClass,
- writable: true,
- configurable: true
- }
- });
- Object.defineProperty(subClass, "prototype", {
- writable: false
- });
- if (superClass) {
- _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)
- }
- function _createSuper(Derived) {
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
- return function() {
- var result, Super = _getPrototypeOf(Derived);
- if (hasNativeReflectConstruct) {
- var NewTarget = _getPrototypeOf(this).constructor;
- result = Reflect.construct(Super, arguments, NewTarget)
- } else {
- result = Super.apply(this, arguments)
- }
- return _possibleConstructorReturn(this, result)
- }
- }
- function _possibleConstructorReturn(self, call) {
- if (call && ("object" === _typeof(call) || "function" === typeof call)) {
- return call
- } else {
- if (void 0 !== call) {
- throw new TypeError("Derived constructors may only return object or undefined")
- }
- }
- return _assertThisInitialized(self)
- }
- function _assertThisInitialized(self) {
- if (void 0 === self) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
- }
- return self
- }
- function _isNativeReflectConstruct() {
- if ("undefined" === typeof Reflect || !Reflect.construct) {
- return false
- }
- if (Reflect.construct.sham) {
- return false
- }
- if ("function" === typeof Proxy) {
- return true
- }
- try {
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
- return true
- } catch (e) {
- return false
- }
- }
- function _getPrototypeOf(o) {
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
- return o.__proto__ || Object.getPrototypeOf(o)
- };
- return _getPrototypeOf(o)
- }
- var ArrayFileProvider = function(_FileProvider) {
- _inherits(ArrayFileProvider, _FileProvider);
- var _super = _createSuper(ArrayFileProvider);
- function ArrayFileProvider(options) {
- var _this;
- _classCallCheck(this, ArrayFileProvider);
- options = (0, _common.ensureDefined)(options, {});
- _this = _super.call(this, options);
- var initialArray = options.data;
- if (initialArray && !Array.isArray(initialArray)) {
- throw _errors.errors.Error("E4006")
- }
- var itemsExpr = options.itemsExpr || "items";
- _this._subFileItemsGetter = (0, _data.compileGetter)(itemsExpr);
- _this._subFileItemsSetter = _type2.default.isFunction(itemsExpr) ? itemsExpr : (0, _data.compileSetter)(itemsExpr);
- var nameExpr = _this._getNameExpr(options);
- _this._nameSetter = _type2.default.isFunction(nameExpr) ? nameExpr : (0, _data.compileSetter)(nameExpr);
- var isDirExpr = _this._getIsDirExpr(options);
- _this._getIsDirSetter = _type2.default.isFunction(isDirExpr) ? isDirExpr : (0, _data.compileSetter)(isDirExpr);
- _this._data = initialArray || [];
- return _this
- }
- _createClass(ArrayFileProvider, [{
- key: "getItems",
- value: function(path, itemType) {
- return this._getItems(path, itemType)
- }
- }, {
- key: "renameItem",
- value: function(item, name) {
- item.dataItem.name = name
- }
- }, {
- key: "createFolder",
- value: function(parentFolder, name) {
- var newItem = {};
- this._nameSetter(newItem, name);
- this._getIsDirSetter(newItem, true);
- var array = this._getChildrenArray(parentFolder.dataItem);
- array.push(newItem)
- }
- }, {
- key: "deleteItems",
- value: function(items) {
- var _this2 = this;
- (0, _iterator.each)(items, function(_, item) {
- return _this2._deleteItem(item)
- })
- }
- }, {
- key: "moveItems",
- value: function(items, destinationDir) {
- var _this3 = this;
- var array = this._getChildrenArray(destinationDir.dataItem);
- (0, _iterator.each)(items, function(_, item) {
- _this3._checkAbilityToMoveOrCopyItem(item, destinationDir);
- _this3._deleteItem(item);
- array.push(item.dataItem)
- })
- }
- }, {
- key: "copyItems",
- value: function(items, destinationDir) {
- var _this4 = this;
- var array = this._getChildrenArray(destinationDir.dataItem);
- (0, _iterator.each)(items, function(_, item) {
- _this4._checkAbilityToMoveOrCopyItem(item, destinationDir);
- var copiedItem = _this4._createCopy(item.dataItem);
- array.push(copiedItem)
- })
- }
- }, {
- key: "_checkAbilityToMoveOrCopyItem",
- value: function(item, destinationDir) {
- var newItemPath = (0, _uiFile_manager2.pathCombine)(destinationDir.relativeName, item.name);
- if (0 === newItemPath.indexOf(item.relativeName)) {
- throw {
- errorId: _uiFile_manager.ErrorCode.Other,
- fileItem: item
- }
- }
- }
- }, {
- key: "_createCopy",
- value: function(dataObj) {
- var _this5 = this;
- var copyObj = {};
- this._nameSetter(copyObj, this._nameGetter(dataObj));
- this._getIsDirSetter(copyObj, this._isDirGetter(dataObj));
- var items = this._subFileItemsGetter(dataObj);
- if (Array.isArray(items)) {
- var itemsCopy = [];
- (0, _iterator.each)(items, function(_, childItem) {
- var childCopy = _this5._createCopy(childItem);
- itemsCopy.push(childCopy)
- });
- this._subFileItemsSetter(copyObj, itemsCopy)
- }
- return copyObj
- }
- }, {
- key: "_deleteItem",
- value: function(_ref) {
- var parentPath = _ref.parentPath,
- dataItem = _ref.dataItem;
- var array = this._data;
- if ("" !== parentPath) {
- var folder = this._findItem(parentPath);
- array = this._subFileItemsGetter(folder)
- }
- var index = array.indexOf(dataItem);
- array.splice(index, 1)
- }
- }, {
- key: "_getChildrenArray",
- value: function(dataItem) {
- if (!dataItem) {
- return this._data
- }
- var subItems = this._subFileItemsGetter(dataItem);
- if (!Array.isArray(subItems)) {
- subItems = [];
- this._subFileItemsSetter(dataItem, subItems)
- }
- return subItems
- }
- }, {
- key: "_getItems",
- value: function(path, itemType) {
- if ("" === path || void 0 === path) {
- return this._convertDataObjectsToFileItems(this._data, "", itemType)
- }
- var folderEntry = this._findItem(path);
- var entries = folderEntry && this._subFileItemsGetter(folderEntry) || [];
- return this._convertDataObjectsToFileItems(entries, path, itemType)
- }
- }, {
- key: "_findItem",
- value: function(path) {
- var _this6 = this;
- if ("" === path) {
- return null
- }
- var result = null;
- var data = this._data;
- var parts = path.split("/");
- var _loop = function(i) {
- var part = parts[i];
- result = data.filter(function(entry) {
- return _this6._isDirGetter(entry) && _this6._nameGetter(entry) === part
- })[0];
- if (result) {
- var children = _this6._subFileItemsGetter(result);
- if (children) {
- data = children
- } else {
- if (i !== parts.length - 1) {
- return {
- v: null
- }
- }
- }
- } else {
- return {
- v: null
- }
- }
- };
- for (var i = 0; i < parts.length; i++) {
- var _ret = _loop(i);
- if ("object" === _typeof(_ret)) {
- return _ret.v
- }
- }
- return result
- }
- }, {
- key: "_hasSubDirs",
- value: function(dataObj) {
- var subItems = (0, _common.ensureDefined)(this._subFileItemsGetter(dataObj), []);
- if (!Array.isArray(subItems)) {
- return true
- }
- for (var i = 0; i < subItems.length; i++) {
- if (true === this._isDirGetter(subItems[i])) {
- return true
- }
- }
- return false
- }
- }]);
- return ArrayFileProvider
- }(_file_provider.FileProvider);
- module.exports = ArrayFileProvider;
|