import { N as getDefaultExportFromCjs, O as _baseToString, Q as toString_1, B as GeometryType, U as LayerIcon, V as LineIcon, i as __read, W as _default, X as map, Y as uniqBy, h as __spreadArray, Z as filter, $ as find, a0 as Dropmenu, a1 as dataTreeFilterMenu, y as IconButton, a2 as getTheme, a3 as ThemeEnum, a4 as Tag, a5 as debounce, z as useStaticCallback, a6 as Input, s as __assign, a7 as i18n, a8 as get, a9 as FOLDER_STRUCTURE_TEMP_UUID, b as __awaiter, c as __generator, aa as Menu, ab as MenuItem, ac as Spin, ad as Tree, j as __rest, ae as includes, af as useStore, ag as DataSideBarStore, ah as ALL_SOURCE_MENUS, w as appContext, A as MAP_DRAG_PACKAGE } from './MapEditView-24782753.js';
import * as React from 'react';
import React__default, { useEffect, useState, useRef, useCallback } from 'react';
import { observer } from 'mobx-react';
import classNames from 'classnames';
import { u as useDataValue } from './useDataValue-8bdb351c.js';
import FolderOutlined from './index-65dd4b5a.js';
import FileIcon from './index-ae1de6c4.js';
import LocationIcon from './index-2c4e2ad2.js';
import LocationToLocationIcon from './index-f58067b3.js';
import LocationToPolygonIcon from './index-3fbe476f.js';
import GeoGlobalIcon from './index-2c6a7ff1.js';
import { _ as _castSlice, a as _charsStartIndex, b as _stringToArray, c as compact, u as useContextMenu } from './compact-6f8b3541.js';
import { v4 } from 'uuid';
import $ from 'jquery';
import 'maptalks';
import 'lodash';
import 'mobx';
import 'lz-string';
import 'dayjs';
import 'react-dom';
import 'react-is';
import '@loadable/component';
import 'js-beautify';
import 'axios';
import 'superstruct';
import '@tanem/react-nprogress';
import 'chroma-js';
import 'js-cookie';
import 'is-email';
import 'is-uuid';
import 'is-url';
import 'anymatch';
import 'perf-request';
import '@syncpoint/wkx';
import 'buffer';
import '@turf/turf';
import '@mapbox/polylabel';
import 'turf-multipolygon';
import 'turf-polygon';
import 'gcoord';
import 'eventemitter2';
import 'geobuf';
import 'localforage';
import 'rc-menu';
import 'perfect-scrollbar';
import 'ahooks';
import 'jszip';
import 'file-saver';
import 'screenfull';
import 'sql-formatter-fork';
import 'array-move';
import 'turf-multilinestring';
import 'copy-to-clipboard';
import 'maptalks.three';
import 'ajv';
import 'spark-md5';
import 'react-draggable';
import 'react-virtualized';
import 'turf-point';
import 'decamelize';
import 'rbush';
import 'qs';
import 'maptalks.snap';
import 'react-use';
import 'react-rnd';
import 'react-beautiful-dnd';

var baseToString = _baseToString,
    castSlice = _castSlice,
    charsStartIndex = _charsStartIndex,
    stringToArray = _stringToArray,
    toString = toString_1;

/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;

/**
 * Removes leading whitespace or specified characters from `string`.
 *
 * @static
 * @memberOf _
 * @since 4.0.0
 * @category String
 * @param {string} [string=''] The string to trim.
 * @param {string} [chars=whitespace] The characters to trim.
 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
 * @returns {string} Returns the trimmed string.
 * @example
 *
 * _.trimStart('  abc  ');
 * // => 'abc  '
 *
 * _.trimStart('-_-abc-_-', '_-');
 * // => 'abc-_-'
 */
function trimStart(string, chars, guard) {
  string = toString(string);
  if (string && (guard || chars === undefined)) {
    return string.replace(reTrimStart, '');
  }
  if (!string || !(chars = baseToString(chars))) {
    return string;
  }
  var strSymbols = stringToArray(string),
      start = charsStartIndex(strSymbols, stringToArray(chars));

  return castSlice(strSymbols, start).join('');
}

var trimStart_1 = trimStart;

var trimStart$1 = /*@__PURE__*/getDefaultExportFromCjs(trimStart_1);

var _a;
var GEO_TYPE_ONLY_ICON_MAP = (_a = {},
    _a["".concat(GeometryType.plain)] = FileIcon,
    _a["".concat(GeometryType.polygon)] = LayerIcon,
    _a["".concat(GeometryType.line)] = LineIcon,
    _a["".concat(GeometryType.point)] = LocationIcon,
    _a["".concat(GeometryType.pointToPoint)] = LocationToLocationIcon,
    _a["".concat(GeometryType.pointToPolygon)] = LocationToPolygonIcon,
    _a['geo-global'] = GeoGlobalIcon,
    _a);
var prefixCls$1 = 'dm-data-list';
var getAttrNum = function (style, key) {
    var val = "".concat(style.getPropertyValue(key).replace('px', ''));
    return val ? parseFloat(val) : 0;
};
var DataSideBarHeader = observer(function () {
    var store = React__default.useContext(DataSideBarContext).store;
    var changeSource = store.changeSource, source = store.source, dataSourceOpts = store.dataSourceOpts, changeDSOpts = store.changeDSOpts, originDSOpts = store.originDSOpts;
    var _a = __read(React__default.useState({
        viewList: [],
        hiddenList: [],
    }), 2), list = _a[0], setList = _a[1];
    var _b = __read(_default(), 2), ref = _b[0], width = _b[1].width;
    var visible = dataSourceOpts.length > 0;
    var _onClick = useDataValue(function (v) { return changeSource(v); });
    var getChild = React__default.useCallback(function (it, hidden) {
        var _a;
        var itemCls = classNames("".concat(prefixCls$1, "-header-item"), (_a = {},
            _a["".concat(prefixCls$1, "-header-item-active")] = source === it.value,
            _a["".concat(prefixCls$1, "-header-item-hidden")] = hidden,
            _a));
        return (React__default.createElement("div", { key: it.value, className: itemCls, "data-value": it.value, onClick: _onClick, "data-test": hidden ? 'data-side-bar-package-type' : undefined }, it.label));
    }, [_onClick, source]);
    var compactHiddenList = compact(list.hiddenList);
    var showAll = compactHiddenList.length === 0;
    var menus = map(compactHiddenList, function (it) { return ({
        key: it.value,
        title: it.label,
    }); });
    var allChildren = React__default.useMemo(function () {
        return map(dataSourceOpts, function (it) { return it && getChild(it, true); });
    }, [dataSourceOpts, getChild]);
    var children = React__default.useMemo(function () {
        return map(list.viewList, function (it) { return it && getChild(it, false); });
    }, [getChild, list.viewList]);
    React__default.useEffect(function () {
        var eleList = document.querySelectorAll(".".concat(prefixCls$1, "-header-item-hidden"));
        var totalW = 0;
        var vlLen = list.viewList.length;
        var opts = uniqBy(__spreadArray(__spreadArray(__spreadArray([], __read(originDSOpts.slice(0, vlLen - 1)), false), [
            find(dataSourceOpts, { value: source })
        ], false), __read(filter(originDSOpts.slice(vlLen - 1), function (it) { return it.value !== source; })), false), 'value');
        var vl = [];
        var hl = [];
        for (var index = 0; index < eleList.length; index++) {
            var ele = eleList[index];
            var it_1 = opts[index];
            if (it_1) {
                var ist = window.getComputedStyle(ele);
                var itemW = getAttrNum(ist, 'width') +
                    getAttrNum(ist, 'margin-left') +
                    getAttrNum(ist, 'margin-right');
                totalW += itemW;
                totalW <= width ? vl.push(it_1) : hl.push(it_1);
            }
        }
        setList({ viewList: vl, hiddenList: hl });
    }, [dataSourceOpts, list.viewList.length, originDSOpts, source, width]);
    return (React__default.createElement("div", { className: "".concat(prefixCls$1, "-header") }, visible ? (React__default.createElement(React__default.Fragment, null,
        React__default.createElement("div", { className: "".concat(prefixCls$1, "-header-wrapper"), ref: ref },
            React__default.createElement("div", { className: "".concat(prefixCls$1, "-header-tabs") }, children),
            React__default.createElement("div", { className: "".concat(prefixCls$1, "-header-tabs ").concat(prefixCls$1, "-header-tabs-hidden") }, allChildren)),
        !showAll && (React__default.createElement(Dropmenu, { menus: menus, values: [], onClickMenuItem: function (params) {
                changeSource(params.key + '');
                changeDSOpts();
            }, onlyText: true }, "\u66F4\u591A")))) : null));
});
DataSideBarHeader.displayName = 'DataSideBarHeader';
DataSideBarHeader.whyDidYouRender = true;
var DataTreeDropmenu = observer(function () {
    var store = React__default.useContext(DataSideBarContext).store;
    var changeGroup = store.changeGroup, groupValues = store.groupValues;
    return (React__default.createElement("div", { className: "".concat(prefixCls$1, "-filter-wrapper-item") },
        React__default.createElement(Dropmenu, { menus: dataTreeFilterMenu, values: groupValues, type: "assist-bg", onClickMenuItem: changeGroup, renderDropNode: function () { return React__default.createElement(IconButton, { icon: "sort" }); }, overlayClassName: "".concat(prefixCls$1, "-filter-dropmenu") })));
});
DataTreeDropmenu.displayName = 'DataTreeDropmenu';
var DataTreeFilterTags = observer(function () {
    var store = React__default.useContext(DataSideBarContext).store;
    var tags = store.tags, clearTags = store.clearTags;
    var isDarkTheme = getTheme('') === ThemeEnum.dark;
    return tags.length > 0 ? (React__default.createElement("div", { className: "".concat(prefixCls$1, "-filter-tags") }, map(tags, function (it) {
        return it && (React__default.createElement(Tag, { tag: it.title, color: isDarkTheme ? 'plain-blue-900' : 'blue-700', closable: true, onClickClose: function () { return clearTags(it); }, key: it.title }));
    }))) : null;
});
DataTreeFilterTags.displayName = 'DataTreeFilterTags';
var Search = observer(function (props) {
    var store = React__default.useContext(DataSideBarContext).store;
    var search = store.search, changeSearch = store.changeSearch;
    var _a = __read(React__default.useState(search), 2), value = _a[0], setValue = _a[1];
    var timeRef = React__default.useRef();
    // eslint-disable-next-line react-hooks/exhaustive-deps
    var debounceSetRouteStoreValue = React__default.useCallback(debounce(function (v) { return changeSearch(v); }, 500), []);
    var onChange = useStaticCallback(function (e) {
        var vl = trimStart$1(e.target.value);
        setValue(vl);
        debounceSetRouteStoreValue(vl);
        if (timeRef.current) {
            clearTimeout(timeRef.current);
        }
    });
    useEffect(function () {
        if (timeRef.current) {
            clearTimeout(timeRef.current);
        }
        timeRef.current = setTimeout(function () { return setValue(search); }, 300);
    }, [search]);
    return (React__default.createElement(Input, __assign({ value: value, onChange: onChange, prefixIcon: "search" }, props, { "data-test": "data-side-bar-search-input" })));
});
var DataTreeFilter = React__default.memo(function (_a) {
    var renderExtraFilterNode = _a.renderExtraFilterNode;
    return (React__default.createElement("div", { className: "".concat(prefixCls$1, "-filter") },
        React__default.createElement("div", { className: "".concat(prefixCls$1, "-filter-wrapper") },
            React__default.createElement("div", { className: "".concat(prefixCls$1, "-filter-wrapper-item") },
                React__default.createElement(Search, { placeholder: i18n.dataSideBar.searchData, size: "compact" })),
            React__default.createElement(DataTreeDropmenu, null),
            renderExtraFilterNode && renderExtraFilterNode(prefixCls$1)),
        React__default.createElement(DataTreeFilterTags, null)));
});
DataTreeFilter.displayName = 'DataTreeFilter';
DataTreeFilter.whyDidYouRender = true;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var loop = function (data, key, callback, parentKey) {
    if (parentKey === void 0) { parentKey = ''; }
    data.forEach(function (item) {
        if (item.key === key) {
            callback(item, parentKey);
            return;
        }
        if (item.children) {
            loop(item.children, key, callback, item.key);
        }
    });
};
// const FolderInput = (value: string) => {
//   const [val, setVal] = useState(value);
//   const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
//     setVal(e.target.value);
//   }, []);
//   return <Input value={val} onChange={handleChange} />;
// };
var uuid = v4();
var DataTree = observer(function (props) {
    var _a;
    var store = React__default.useContext(DataSideBarContext).store;
    var isEmptyList = store.isEmptyList, noSearchList = store.noSearchList, loading = store.loading, dataSideBarRcTreeData = store.dataSideBarRcTreeData, source = store.source, dataSourceOpts = store.dataSourceOpts, findDropTargetPath = store.findDropTargetPath, _moveItemsByDrag = store._moveItemsByDrag, newFolderTargetPath = store.newFolderTargetPath, setNewFolderTargetPath = store.setNewFolderTargetPath, editCardId = store.editCardId, renameFolder = store.renameFolder, traversalTree = store.traversalTree, clearTempFolderItem = store.clearTempFolderItem, _createFolder = store._createFolder, createTempNewFolder = store.createTempNewFolder, search = store.search, handleExpandSubFolder = store.handleExpandSubFolder, expandedKeys = store.expandedKeys, setExpandedKeys = store.setExpandedKeys, insertExpandKeys = store.insertExpandKeys, onScroll = store.onScroll;
    var _b = __read(useState(false), 2), isProcessingDrop = _b[0], setIsProcessingDrop = _b[1];
    var treeWrapperRef = useRef(null);
    var onDragStart = props.onDragStart, onDragEnd = props.onDragEnd, onDrop = props.onDrop, onRightClick = props.onRightClick, _c = props.resizing, resizing = _c === void 0 ? false : _c, onSelect = props.onSelect;
    var scrollElRef = useRef(null);
    // 文件夹功能选中拖拽项
    var _d = __read(useState([]), 2), selectedItemsForDrag = _d[0], setSelectedItemsForDrag = _d[1];
    // shift key down
    var shiftKeyPressed = useRef(false);
    var emptyText = React__default.useMemo(function () { return React__default.createElement("div", { className: "".concat(prefixCls$1, "-empty") }, i18n.dataSideBar.emptyText); }, []);
    var noSearchText = React__default.useMemo(function () { return React__default.createElement("div", { className: "".concat(prefixCls$1, "-nosearch") }, i18n.dataSideBar.noSearchText); }, []);
    var treeHidden = React__default.useMemo(function () { return (isEmptyList && emptyText) || (noSearchList && noSearchText); }, [emptyText, isEmptyList, noSearchList, noSearchText]);
    var phNode = React__default.useMemo(function () {
        var node = null;
        isEmptyList && emptyText && (node = emptyText);
        noSearchList && noSearchText && (node = noSearchText);
        return node;
    }, [emptyText, isEmptyList, noSearchList, noSearchText]);
    var tempNewFolderNameRef = useRef('');
    var handleInputChange = useCallback(function (e) {
        tempNewFolderNameRef.current = e.target.value;
    }, []);
    var handleRename = useCallback(function (originalPath) {
        if (tempNewFolderNameRef.current) {
            renameFolder(originalPath, tempNewFolderNameRef.current, true);
            tempNewFolderNameRef.current = '';
        }
    }, [renameFolder]);
    var handleCreateNewFolderByInput = useCallback(function () {
        var folderName = tempNewFolderNameRef.current;
        if (folderName) {
            _createFolder(newFolderTargetPath ? "".concat(newFolderTargetPath, "/").concat(folderName) : folderName, true);
        }
        else {
            clearTempFolderItem();
        }
        setNewFolderTargetPath(undefined);
        tempNewFolderNameRef.current = '';
    }, [setNewFolderTargetPath, _createFolder, newFolderTargetPath, clearTempFolderItem]);
    //在最近使用数据中增加对数据来源的显示
    var treeData = React__default.useMemo(function () {
        var list = source === 'recentData'
            ? map(dataSideBarRcTreeData, function (it) {
                var _a, _b, _c;
                return (__assign(__assign({}, it), { 
                    // 最近使用使用表明来源
                    name: ((_a = it.extra) === null || _a === void 0 ? void 0 : _a.displaySource) === 'recentData'
                        ? "".concat(it.name, "(").concat((_c = (_b = find(dataSourceOpts, { value: it.source })) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : i18n.dataSideBar.marketData, ")")
                        : it.name }));
            })
            : dataSideBarRcTreeData;
        var res = source === 'recentData'
            ? list
            : map(list, function (it) { return (__assign(__assign({}, it), { title: get(it, 'extra.packageType') !== 'collaboration_v2' ? (it.title) : (React__default.createElement("div", { style: {
                        display: 'flex',
                        alignItems: 'center',
                        justifyContent: 'space-between',
                        overflow: 'hidden',
                        width: '100%',
                    } },
                    React__default.createElement("div", { style: {
                            overflow: 'hidden',
                            textOverflow: 'ellipsis',
                            whiteSpace: 'nowrap',
                            width: "calc( 100% - 56px)",
                        } }, typeof it.title === 'function' ? it.title(it) : it.title),
                    React__default.createElement(Tag, { tag: i18n.dataSideBar.collaboration, color: 'purple-900' }))) })); });
        if (editCardId) {
            var toEditFolder_1;
            traversalTree(res, editCardId, function (i) {
                toEditFolder_1 = i;
            });
            if (toEditFolder_1) {
                var title_1 = toEditFolder_1.title;
                tempNewFolderNameRef.current = title_1;
                toEditFolder_1.title = function () { return (React__default.createElement(Input, { autoFocus: true, defaultValue: title_1, onChange: handleInputChange, onPressEnter: function () { return handleRename(toEditFolder_1 === null || toEditFolder_1 === void 0 ? void 0 : toEditFolder_1.key); }, onBlur: function () { return handleRename(toEditFolder_1 === null || toEditFolder_1 === void 0 ? void 0 : toEditFolder_1.key); } })); };
            }
        }
        traversalTree(res, FOLDER_STRUCTURE_TEMP_UUID, function (i) {
            i.title = (React__default.createElement(Input, { autoFocus: true, defaultValue: '', onChange: handleInputChange, onPressEnter: handleCreateNewFolderByInput, onBlur: handleCreateNewFolderByInput }));
        });
        return res;
    }, [
        dataSideBarRcTreeData,
        source,
        editCardId,
        traversalTree,
        handleInputChange,
        handleRename,
        handleCreateNewFolderByInput,
        dataSourceOpts,
    ]);
    var defaultDragStart = useCallback(function (info) {
        var _a, _b;
        var node = info.node;
        //@ts-ignore
        (_a = store.setDragSourceId) === null || _a === void 0 ? void 0 : _a.call(store, ((_b = node.packageUuid) === null || _b === void 0 ? void 0 : _b.toString()) || node.key.toString());
    }, [store]);
    var defaultDrop = useCallback(function (info) { return __awaiter(void 0, void 0, void 0, function () {
        var node, dragNode, dropKey, dragKey, dropPos, dropPosition, path, data;
        return __generator(this, function (_a) {
            if (isProcessingDrop)
                return [2 /*return*/];
            setIsProcessingDrop(true);
            node = info.node, dragNode = info.dragNode;
            dropKey = node.packageUuid || node.key;
            dragKey = (dragNode.packageUuid || dragNode.key);
            dropPos = node.pos.split('-');
            dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]);
            path = '';
            data = __spreadArray([], __read(treeData), false);
            if (dropPosition === 0) {
                // Drop on the content
                path = findDropTargetPath(dropKey);
            }
            else {
                // Drop on the gap (insert before or insert after)
                loop(data, dropKey, function (_item, parentKey) {
                    path = parentKey;
                });
            }
            if (path !== undefined && source !== 'recentData') {
                // 拖拽元素不在多选选中目标之内
                if (selectedItemsForDrag.length > 1 && !includes(selectedItemsForDrag, dragKey))
                    return [2 /*return*/];
                _moveItemsByDrag({
                    dragItemIds: selectedItemsForDrag.length > 1 ? selectedItemsForDrag : [dragKey],
                    dropFolderId: path,
                });
            }
            console.log('dragKey: ', dragKey);
            console.log('dropKey: ', dropKey);
            console.log('dropPosition: ', dropPosition);
            console.log('dropToGap: ', info.dropToGap);
            setSelectedItemsForDrag([]);
            setIsProcessingDrop(false);
            return [2 /*return*/];
        });
    }); }, [
        isProcessingDrop,
        treeData,
        source,
        findDropTargetPath,
        selectedItemsForDrag,
        _moveItemsByDrag,
    ]);
    var handleSelect = useCallback(function (_selectedKeys, info) {
        if (source === 'recentData')
            return;
        if (shiftKeyPressed.current) {
            setSelectedItemsForDrag(function (prev) { return __spreadArray(__spreadArray([], __read(prev), false), [info.node.key], false); });
        }
        else {
            setSelectedItemsForDrag(function () { return [info.node.key]; });
        }
    }, [source]);
    var handleSelectPackage = useCallback(function (_e, node) {
        // 非文件夹节点
        if (!node.children) {
            // 文件夹内部资源节点（treeNode） 与原有外层数据结构（allList）不同 需要使用原有数据
            var packageUuid_1 = node.packageUuid || node.key;
            var item_1;
            dataSideBarRcTreeData.forEach(function (i) {
                if (i.isFolder) {
                    var lt = i.children || [], it_2 = lt.find(function (k) { return k.packageUuid === packageUuid_1; });
                    if (it_2) {
                        item_1 = it_2;
                        return true;
                    }
                }
                else {
                    if (i.packageUuid === packageUuid_1) {
                        item_1 = i;
                        return true;
                    }
                }
            });
            if (item_1) {
                onSelect === null || onSelect === void 0 ? void 0 : onSelect(item_1);
            }
        }
    }, [dataSideBarRcTreeData, onSelect]);
    var handleExpand = useCallback(function (keys) {
        setExpandedKeys(keys);
    }, [setExpandedKeys]);
    var iconRender = useCallback(function (nodeProps) {
        var _a, _b;
        var IconView;
        if ((_a = nodeProps.data) === null || _a === void 0 ? void 0 : _a.children) {
            IconView = FolderOutlined;
        }
        else {
            var type = nodeProps.geometryType;
            IconView = (_b = GEO_TYPE_ONLY_ICON_MAP[type]) !== null && _b !== void 0 ? _b : FileIcon;
        }
        return React__default.createElement(IconView, { className: "dmc-icon" });
    }, []);
    var handleKeydown = useCallback(function (e) {
        if (e.shiftKey) {
            shiftKeyPressed.current = true;
        }
    }, []);
    var handleKeyup = useCallback(function (e) {
        if (e.key === 'Shift') {
            shiftKeyPressed.current = false;
        }
    }, []);
    var handleCreateNewFolderByContextMenu = useCallback(function () {
        createTempNewFolder('');
    }, [createTempNewFolder]);
    useEffect(function () {
        document.body.addEventListener('keydown', handleKeydown);
        document.body.addEventListener('keyup', handleKeyup);
        return function () {
            document.body.removeEventListener('keydown', handleKeydown);
            document.body.removeEventListener('keyup', handleKeyup);
        };
    }, [handleKeydown, handleKeyup]);
    useEffect(function () {
        if (newFolderTargetPath) {
            if (!expandedKeys.find(function (i) { return i === newFolderTargetPath; })) {
                insertExpandKeys(newFolderTargetPath);
            }
        }
    }, [expandedKeys, insertExpandKeys, newFolderTargetPath]);
    useEffect(function () {
        setExpandedKeys([]);
    }, [source, search, setExpandedKeys]);
    var createFolderContextMenu = useContextMenu({
        triggerElement: (_a = treeWrapperRef.current) === null || _a === void 0 ? void 0 : _a.componentWrapper,
        menuRender: function () { return (React__default.createElement(Menu, null,
            React__default.createElement(MenuItem, { onClick: handleCreateNewFolderByContextMenu }, i18n.common.newFolder))); },
        disabled: source === 'recentData' || loading || !!search,
        triggerByChild: false,
        blackList: ['dmc-input', 'dmc-input-textarea', 'INPUT', 'TEXTAREA'],
    });
    var handleWheel = useCallback(function (e) {
        var el = scrollElRef.current;
        if (el) {
            onScroll === null || onScroll === void 0 ? void 0 : onScroll(e, el.clientHeight, el.scrollHeight, el.scrollTop);
        }
        else {
            var el_1 = e.target;
            while (el_1) {
                if (el_1.classList.contains('dmc-tree-list-holder')) {
                    scrollElRef.current = el_1;
                    onScroll === null || onScroll === void 0 ? void 0 : onScroll(e, el_1.clientHeight, el_1.scrollHeight, el_1.scrollTop);
                    break;
                }
                el_1 = el_1.parentElement;
            }
        }
    }, [onScroll]);
    useEffect(function () {
        if (loading)
            return;
        var item = document.querySelector(".".concat(prefixCls$1, "-").concat(uuid));
        if (item) {
            item.addEventListener('wheel', handleWheel);
        }
        return function () {
            if (item) {
                item.removeEventListener('wheel', handleWheel);
            }
        };
    }, [handleWheel, loading]);
    return (React__default.createElement("div", { className: "".concat(prefixCls$1, "-tree") },
        createFolderContextMenu,
        loading ? (React__default.createElement(Spin, null)) : treeHidden ? (phNode) : (React__default.createElement(Tree, { expandedKeys: expandedKeys, onExpand: handleExpand, icon: iconRender, treeData: treeData, onDragStart: onDragStart || defaultDragStart, onDrop: onDrop || defaultDrop, onDragEnd: onDragEnd, draggable: !resizing, type: "assist-bg", onSelect: handleSelect, onDoubleClick: handleSelectPackage, selectedKeys: selectedItemsForDrag, multiple: selectedItemsForDrag.length > 1, onRightClick: onRightClick, itemHeight: 24, virtual: true, withoutHoverEffect: resizing, loadData: handleExpandSubFolder, ref: treeWrapperRef }))));
});
DataTree.displayName = 'DataTree';
DataTree.whyDidYouRender = true;
var DataSideBarView = React__default.memo(function (_a) {
    var renderExtraFilterNode = _a.renderExtraFilterNode, renderFooter = _a.renderFooter, treeProps = __rest(_a, ["renderExtraFilterNode", "renderFooter"]);
    return (React__default.createElement("div", { className: "".concat(prefixCls$1, " ").concat(prefixCls$1, "-").concat(uuid) },
        React__default.createElement(DataSideBarHeader, null),
        React__default.createElement(DataTreeFilter, { renderExtraFilterNode: renderExtraFilterNode }),
        React__default.createElement(DataTree, __assign({}, treeProps)),
        renderFooter && renderFooter()));
});

var DataSideBarContext = React.createContext({
    //@ts-ignore
    store: {},
});
var DataSideBar = function (_a) {
    var rStore = _a.rStore, projectOption = _a.projectOption, restProps = __rest(_a, ["rStore", "projectOption"]);
    var selfRStore = useStore(function () { return new DataSideBarStore({ projectOption: projectOption }); });
    var rsRef = React.useRef(rStore);
    var routeStoreRef = rStore ? rsRef : selfRStore;
    React.useEffect(function () {
        var _a, _b;
        if (!rStore) {
            //默认是地图的dataSourceMenu，也就是全部的datasourcemenus
            (_a = routeStoreRef.current) === null || _a === void 0 ? void 0 : _a.initDataSourceMenus(ALL_SOURCE_MENUS);
            (_b = routeStoreRef.current) === null || _b === void 0 ? void 0 : _b.getRecentData();
            routeStoreRef.current && routeStoreRef.current.initDataList();
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    var value = React.useMemo(function () { return ({
        store: routeStoreRef.current,
    }); }, [routeStoreRef]);
    return (React.createElement(DataSideBarContext.Provider, { value: value },
        React.createElement(DataSideBarView, __assign({}, restProps))));
};

var suppArr = [
    GeometryType.point,
    GeometryType.line,
    GeometryType.polygon,
    GeometryType.pointToPolygon,
];
var geoArr = [GeometryType.polygon, GeometryType.pointToPolygon];
var prefixCls = 'map-data-package-list';
var DataPackageList = observer(function () {
    var routeStore = React.useContext(appContext.getContext()).routeStore;
    var MapSettingStore = routeStore.MapSettingStore, inEditPage = routeStore.inEditPage, projectOption = routeStore.projectOption;
    var packageConfigShow = MapSettingStore.packageConfigShow, changePackageConfigShow = MapSettingStore.changePackageConfigShow;
    return (React.createElement("div", { className: prefixCls },
        React.createElement(DataSideBar, { onDragStart: function (e) {
                if (inEditPage && !packageConfigShow) {
                    changePackageConfigShow();
                }
                var event = e.event, defaultNode = e.node;
                // source除了customer | sql 都是market
                var node = __assign(__assign({}, defaultNode), { source: defaultNode.source === 'customer' || defaultNode.source === 'sql'
                        ? defaultNode.source
                        : 'market' });
                if (node.geoType === 'plain') {
                    return;
                }
                var nodeStr = JSON.stringify(node);
                event.dataTransfer.setData(MAP_DRAG_PACKAGE, nodeStr);
                sessionStorage.setItem(MAP_DRAG_PACKAGE, nodeStr);
                var geoType = node.geoType, geometryType = node.geometryType;
                var _type = geoType || geometryType;
                if (suppArr.indexOf(_type) > -1) {
                    $('.dm-map-packages-config-list-wrapper.supp-filters').addClass('can-dragover');
                }
                if (geoArr.indexOf(_type) > -1) {
                    $('.dm-map-packages-config-list-wrapper.geo-filters').addClass('can-dragover');
                }
            }, onDragEnd: function () {
                $('.dm-map-packages-config-list-wrapper.supp-filters').removeClass('can-dragover');
                $('.dm-map-packages-config-list-wrapper.geo-filters').removeClass('can-dragover');
            }, projectOption: projectOption })));
});
var DataPackageList$1 = DataPackageList;

export { DataPackageList$1 as default };
