xdesign-vue-next
Version:
XDesign Component for vue-next
408 lines (398 loc) • 17.2 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
import { createElementVNode, openBlock, createElementBlock, toRefs, ref, shallowRef, computed, watch, h, createVNode, onUnmounted } from 'vue';
import { _ as _toConsumableArray } from '../../_chunks/dep-5bec687c.mjs';
import { _ as _defineProperty } from '../../_chunks/dep-f9e836af.mjs';
import { c as cloneDeep_1 } from '../../_chunks/dep-91ac8f71.mjs';
import { g as get_1 } from '../../_chunks/dep-7fa157cd.mjs';
import TableTreeStore from '../../_common/js/table/tree-store.mjs';
import useClassName from './useClassName.mjs';
import { renderCell } from '../tr.mjs';
import '../../hooks/useConfig.mjs';
import '../../hooks/index.mjs';
import { useConfig } from '../../config-provider/useConfig.mjs';
import { useTNodeDefault } from '../../hooks/tnode.mjs';
import '../../_chunks/dep-89b966f4.mjs';
import '../../_chunks/dep-82805301.mjs';
import '../../_chunks/dep-10a947a6.mjs';
import '../../_chunks/dep-c4737535.mjs';
import '../../_chunks/dep-81c83986.mjs';
import '../../_chunks/dep-6aa0223b.mjs';
import '../../_chunks/dep-db381ece.mjs';
import '../../_chunks/dep-1cc1c24f.mjs';
import '../../_chunks/dep-b75d8d74.mjs';
import '../../_chunks/dep-6ad18815.mjs';
import '../../_chunks/dep-5755c21c.mjs';
import '../../_chunks/dep-7f239c43.mjs';
import '../../_chunks/dep-6f04869e.mjs';
import '../../_chunks/dep-d32fbbb3.mjs';
import '../../_chunks/dep-dafada74.mjs';
import '../../_chunks/dep-addc2a84.mjs';
import '../../_chunks/dep-a95026f2.mjs';
import '../../_chunks/dep-068e912d.mjs';
import '../../_chunks/dep-6e7b37b8.mjs';
import '../../_chunks/dep-e1ab85c5.mjs';
import '../../_chunks/dep-5f0e0453.mjs';
import '../../_chunks/dep-71f84cf2.mjs';
import '../../_chunks/dep-0e832fc7.mjs';
import '../../_chunks/dep-69963a8c.mjs';
import '../../_chunks/dep-8d1c9a23.mjs';
import '../../_chunks/dep-03412fab.mjs';
import '../../_chunks/dep-205ff58d.mjs';
import '../../_chunks/dep-fa6608fd.mjs';
import '../../_chunks/dep-7dcfa37a.mjs';
import '../../_chunks/dep-4903a8a8.mjs';
import '../../_chunks/dep-72a1dd28.mjs';
import '../../_chunks/dep-1bae6a97.mjs';
import '../../_common/js/table/utils.mjs';
import '../../_chunks/dep-23f91684.mjs';
import '../../_common/js/log/index.mjs';
import '../../_common/js/log/log.mjs';
import '../../_chunks/dep-11fa9c2c.mjs';
import '../../_chunks/dep-b09f48fa.mjs';
import '../../_chunks/dep-26bf361a.mjs';
import '../../_chunks/dep-3ec3335a.mjs';
import '../../_chunks/dep-ed4e7c50.mjs';
import '../../_chunks/dep-a666b9ad.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/en_US.mjs';
import '../../config-provider/type.mjs';
import '../../_chunks/dep-f4eba04c.mjs';
import '../../_chunks/dep-735bcd0d.mjs';
import '../../_chunks/dep-765678ef.mjs';
import '../../_chunks/dep-abf7f90d.mjs';
import '../../_chunks/dep-cc9bfda3.mjs';
import '../../_chunks/dep-b57a2815.mjs';
import '../../_chunks/dep-983ce253.mjs';
import '../utils.mjs';
import './useFixed.mjs';
import '../../_chunks/dep-32d4c595.mjs';
import '../../_chunks/dep-0c786bea.mjs';
import '../../_chunks/dep-e727a519.mjs';
import '../../_chunks/dep-29f616db.mjs';
import '../../_chunks/dep-4265f69a.mjs';
import '../../_chunks/dep-395d33c9.mjs';
import '../../_chunks/dep-e901316d.mjs';
import '../../_common/js/utils/getScrollbarWidth.mjs';
import '../../_common/js/utils/helper.mjs';
import '../../_chunks/dep-53e379cd.mjs';
import '../../_chunks/dep-5a2ce53e.mjs';
import '../../utils/dom.mjs';
import '../../utils/easing.mjs';
import '../ellipsis.mjs';
import '../../utils/render-tnode.mjs';
import '../../_chunks/dep-9d7ebc32.mjs';
import '../../_chunks/dep-a628549d.mjs';
import '../../_chunks/dep-8db27830.mjs';
import '../../_chunks/dep-ae4bffa5.mjs';
import '../../tooltip/index.mjs';
import '../../tooltip/tooltip.mjs';
import '../../_chunks/dep-60f1d7ee.mjs';
import '../../tooltip/props.mjs';
import '../../popup/props.mjs';
import '../../popup/index.mjs';
import '../../popup/popup.mjs';
import '@popperjs/core';
import '../../hooks/useVModel.mjs';
import '../../_common/js/utils/set-style.mjs';
import '../../popup/container.mjs';
import '../../hooks/useResizeObserver.mjs';
import '../../hooks/icon.mjs';
import '../../hooks/slot.mjs';
import '../../hooks/useCommonClassName.mjs';
import '../../hooks/useDefaultValue.mjs';
import '../../hooks/useDestroyOnClose.mjs';
import '../../hooks/useKeepAnimation.mjs';
import '../../hooks/useRipple.mjs';
import '../../utils/set-style.mjs';
import '../../hooks/useVirtualScroll.mjs';
import '../../hooks/useImagePreviewUrl.mjs';
import '../../_common/js/upload/utils.mjs';
import '../../utils/withInstall.mjs';
import './style/css.mjs';
import '../../popup/type.mjs';
import '../../tooltip/util.mjs';
import '../../tooltip/type.mjs';
import '../base-table-props.mjs';
import './useLazyLoad.mjs';
import '../../_common/js/utils/observe.mjs';
import './useRowspanAndColspan.mjs';
const _hoisted_1$1 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2$1 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "M4 3h16a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm1 2v14h14V5H5Zm6 6V7h2v4h4v2h-4v4h-2v-4H7v-2h4Z"
}, null, -1 /* HOISTED */);
const _hoisted_3$1 = [
_hoisted_2$1
];
function render$1(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1$1, _hoisted_3$1))
}
var __unplugin_components_1 = { name: 'ri-add-box-line', render: render$1 };
/* vite-plugin-components disabled */
const _hoisted_1 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "M4 3h16a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm1 2v14h14V5H5Zm2 6h10v2H7v-2Z"
}, null, -1 /* HOISTED */);
const _hoisted_3 = [
_hoisted_2
];
function render(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1, _hoisted_3))
}
var __unplugin_components_0 = { name: 'ri-checkbox-indeterminate-line', render };
/* vite-plugin-components disabled */
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function useTreeData(props, context) {
var _toRefs = toRefs(props),
data = _toRefs.data,
columns = _toRefs.columns;
var _useConfig = useConfig("table"),
t = _useConfig.t,
globalConfig = _useConfig.globalConfig;
var store = ref(new TableTreeStore());
var treeNodeCol = shallowRef();
var dataSource = ref([]);
var _useClassName = useClassName(),
tableTreeClasses = _useClassName.tableTreeClasses;
var renderTNode = useTNodeDefault();
var rowDataKeys = computed(function () {
var _props$tree;
return {
rowKey: props.rowKey || "id",
childrenKey: ((_props$tree = props.tree) === null || _props$tree === void 0 ? void 0 : _props$tree.childrenKey) || "children"
};
});
var checkedColumn = computed(function () {
return columns.value.find(function (col) {
return col.colKey === "row-select";
});
});
watch(checkedColumn, function (column) {
if (!store.value) return;
store.value.updateDisabledState(dataSource.value, column, rowDataKeys.value);
});
var foldIcon = function foldIcon(context2) {
var params = _objectSpread(_objectSpread({}, context2), {}, {
type: "fold"
});
var defaultFoldIcon = t(globalConfig.value.treeExpandAndFoldIcon, h, params) || createVNode(__unplugin_components_0, null, null);
return renderTNode("treeExpandAndFoldIcon", {
defaultNode: defaultFoldIcon,
params: params
});
};
var expandIcon = function expandIcon(context2) {
var params = _objectSpread(_objectSpread({}, context2), {}, {
type: "expand"
});
var defaultExpandIcon = t(globalConfig.value.treeExpandAndFoldIcon, h, params) || createVNode(__unplugin_components_1, null, null);
return renderTNode("treeExpandAndFoldIcon", {
defaultNode: defaultExpandIcon,
params: params
});
};
var uniqueKeys = computed(function () {
var _store$value;
return ((_store$value = store.value) === null || _store$value === void 0 || (_store$value = _store$value.getAllUniqueKeys(data.value, rowDataKeys.value)) === null || _store$value === void 0 ? void 0 : _store$value.join()) || "";
});
watch([uniqueKeys], function () {
if (!data.value) return;
if (!props.tree) {
dataSource.value = data.value;
return;
}
resetData(data.value);
}, {
immediate: true
});
onUnmounted(function () {
var _store$value$treeData;
if (!props.tree) return;
(_store$value$treeData = store.value.treeDataMap) === null || _store$value$treeData === void 0 ? void 0 : _store$value$treeData.clear();
store.value = null;
});
watch(function () {
var _props$tree2;
return [columns, (_props$tree2 = props.tree) === null || _props$tree2 === void 0 ? void 0 : _props$tree2.treeNodeColumnIndex];
}, function () {
treeNodeCol.value = getTreeNodeColumnCol();
}, {
immediate: true
});
function resetData(data2) {
var _props$tree3;
var newVal = cloneDeep_1(data2);
store.value.initialTreeStore(newVal, props.columns, rowDataKeys.value);
if ((_props$tree3 = props.tree) !== null && _props$tree3 !== void 0 && _props$tree3.defaultExpandAll) {
newVal = store.value.expandAll(newVal, rowDataKeys.value);
}
dataSource.value = newVal;
}
function getTreeNodeStyle(level) {
var _props$tree4, _props$tree5;
if (level === void 0) return;
var indent = ((_props$tree4 = props.tree) === null || _props$tree4 === void 0 ? void 0 : _props$tree4.indent) === void 0 ? 24 : (_props$tree5 = props.tree) === null || _props$tree5 === void 0 ? void 0 : _props$tree5.indent;
return indent ? {
paddingLeft: "".concat(level * indent || 1, "px")
} : {};
}
function toggleExpandData(p, trigger) {
var _store$value2, _props$onTreeExpandCh;
var currentData = _objectSpread({}, p);
if (p.row.__VIRTUAL_SCROLL_INDEX !== void 0) {
currentData.rowIndex = p.row.__VIRTUAL_SCROLL_INDEX;
}
dataSource.value = _toConsumableArray(store.value.toggleExpandData(currentData, dataSource.value, rowDataKeys.value));
var rowValue = get_1(p.row, rowDataKeys.value.rowKey);
var rowState = (_store$value2 = store.value) === null || _store$value2 === void 0 || (_store$value2 = _store$value2.treeDataMap) === null || _store$value2 === void 0 ? void 0 : _store$value2.get(rowValue);
(_props$onTreeExpandCh = props.onTreeExpandChange) === null || _props$onTreeExpandCh === void 0 ? void 0 : _props$onTreeExpandCh.call(props, {
row: p.row,
rowIndex: p.rowIndex,
rowState: rowState,
trigger: trigger
});
}
function getTreeNodeColumnCol() {
var _props$tree6;
var columns2 = props.columns;
var treeNodeColumnIndex = ((_props$tree6 = props.tree) === null || _props$tree6 === void 0 ? void 0 : _props$tree6.treeNodeColumnIndex) || 0;
while ((_columns2$treeNodeCol = columns2[treeNodeColumnIndex]) !== null && _columns2$treeNodeCol !== void 0 && _columns2$treeNodeCol.type || ((_columns2$treeNodeCol2 = columns2[treeNodeColumnIndex]) === null || _columns2$treeNodeCol2 === void 0 ? void 0 : _columns2$treeNodeCol2.colKey) === "__EXPAND_ROW_ICON_COLUMN__") {
var _columns2$treeNodeCol, _columns2$treeNodeCol2;
treeNodeColumnIndex += 1;
}
return columns2[treeNodeColumnIndex];
}
function formatTreeColumn(col) {
if (!props.tree || col.colKey !== treeNodeCol.value.colKey) return col;
var newCol = _objectSpread({}, treeNodeCol.value);
newCol.cell = function (h2, p) {
var cellInfo = renderCell(_objectSpread(_objectSpread({}, p), {}, {
col: _objectSpread({}, treeNodeCol.value)
}), context.slots, {
cellEmptyContent: props.cellEmptyContent
});
var currentState = store.value.treeDataMap.get(get_1(p.row, rowDataKeys.value.rowKey));
var colStyle = getTreeNodeStyle(currentState === null || currentState === void 0 ? void 0 : currentState.level);
var classes = _defineProperty({}, tableTreeClasses.inlineCol, !!col.ellipsis);
var childrenNodes = get_1(p.row, rowDataKeys.value.childrenKey);
if (childrenNodes && childrenNodes instanceof Array || childrenNodes === true) {
var _store$value$treeData2;
var iconNode = (_store$value$treeData2 = store.value.treeDataMap.get(get_1(p.row, rowDataKeys.value.rowKey))) !== null && _store$value$treeData2 !== void 0 && _store$value$treeData2.expanded ? foldIcon(p) : expandIcon(p);
return createVNode("div", {
"class": [tableTreeClasses.col, classes],
"style": colStyle
}, [!!(childrenNodes.length || childrenNodes === true) && createVNode("span", {
"class": tableTreeClasses.icon,
"onClick": function onClick(e) {
toggleExpandData(p, "expand-fold-icon");
e.stopPropagation();
}
}, [iconNode]), cellInfo]);
}
return createVNode("div", {
"style": colStyle,
"class": [classes, tableTreeClasses.leafNode]
}, [createVNode("span", {
"class": tableTreeClasses.icon
}, null), cellInfo]);
};
if (newCol.ellipsis === true) {
newCol.ellipsis = function (h2, p) {
return renderCell(_objectSpread(_objectSpread({}, p), {}, {
col: _objectSpread({}, treeNodeCol.value)
}), context.slots);
};
}
return newCol;
}
function setData(key, newRowData) {
var rowIndex = store.value.updateData(key, newRowData, dataSource.value, rowDataKeys.value);
var newData = _toConsumableArray(dataSource.value);
newData[rowIndex] = newRowData;
dataSource.value = newData;
}
function getData(key) {
return store.value.getData(key);
}
function remove(key) {
dataSource.value = _toConsumableArray(store.value.remove(key, dataSource.value, rowDataKeys.value));
}
function appendTo() {
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var newData = arguments.length > 1 ? arguments[1] : undefined;
if (!key) {
dataSource.value = store.value.appendToRoot(newData, dataSource.value, rowDataKeys.value);
return;
}
dataSource.value = _toConsumableArray(store.value.appendTo(key, newData, dataSource.value, rowDataKeys.value));
}
function insertAfter(rowValue, newData) {
dataSource.value = _toConsumableArray(store.value.insertAfter(rowValue, newData, dataSource.value, rowDataKeys.value));
}
function insertBefore(rowValue, newData) {
dataSource.value = _toConsumableArray(store.value.insertBefore(rowValue, newData, dataSource.value, rowDataKeys.value));
}
function expandAll() {
dataSource.value = _toConsumableArray(store.value.expandAll(dataSource.value, rowDataKeys.value));
}
function foldAll() {
dataSource.value = _toConsumableArray(store.value.foldAll(dataSource.value, rowDataKeys.value));
}
function swapData(params) {
var r = store.value.swapData(dataSource.value, params, rowDataKeys.value);
if (r.result) {
dataSource.value = _toConsumableArray(r.dataSource);
} else {
var _props$onAbnormalDrag;
var params2 = {
code: r.code,
reason: r.reason
};
(_props$onAbnormalDrag = props.onAbnormalDragSort) === null || _props$onAbnormalDrag === void 0 ? void 0 : _props$onAbnormalDrag.call(props, params2);
}
}
function getTreeNode() {
return store.value.getTreeNode(dataSource.value, rowDataKeys.value);
}
function getTreeExpandedRow() {
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "data";
return store.value.getTreeExpandedRow(dataSource.value, rowDataKeys.value, type);
}
return {
store: store,
rowDataKeys: rowDataKeys,
dataSource: dataSource,
swapData: swapData,
setData: setData,
getData: getData,
remove: remove,
appendTo: appendTo,
insertAfter: insertAfter,
insertBefore: insertBefore,
formatTreeColumn: formatTreeColumn,
toggleExpandData: toggleExpandData,
expandAll: expandAll,
foldAll: foldAll,
getTreeNode: getTreeNode,
resetData: resetData,
getTreeExpandedRow: getTreeExpandedRow
};
}
export { useTreeData as default };
//# sourceMappingURL=useTreeData.mjs.map