@pisell/materials 1.0.340 → 1.0.342

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,14 @@
1
1
  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); }
2
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
3
7
  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; }
4
8
  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; }
5
9
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
10
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
11
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
12
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
13
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
14
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -53,7 +53,9 @@ var TreeItem = function TreeItem(props) {
53
53
  }
54
54
  }, [activeId]);
55
55
  var style = {
56
- transform: CSS.Transform.toString(transform),
56
+ transform: CSS.Transform.toString(transform && _objectSpread(_objectSpread({}, transform), {}, {
57
+ scaleY: 1
58
+ })),
57
59
  transition: transition
58
60
  };
59
61
  var rowKey = useMemo(function () {
@@ -64,15 +66,15 @@ var TreeItem = function TreeItem(props) {
64
66
  over = event.over;
65
67
  if (!over || !active || !lists.length) return;
66
68
  try {
67
- var _active$rowKey, _over$rowKey;
68
- var _active$rowKey$split = (_active$rowKey = active[rowKey]) === null || _active$rowKey === void 0 ? void 0 : _active$rowKey.split('-'),
69
- _active$rowKey$split2 = _slicedToArray(_active$rowKey$split, 2),
70
- activeParentId = _active$rowKey$split2[0],
71
- _activeId = _active$rowKey$split2[1];
72
- var _over$rowKey$split = (_over$rowKey = over[rowKey]) === null || _over$rowKey === void 0 ? void 0 : _over$rowKey.split('-'),
73
- _over$rowKey$split2 = _slicedToArray(_over$rowKey$split, 2),
74
- overParentId = _over$rowKey$split2[0],
75
- overId = _over$rowKey$split2[1];
69
+ var _active$id, _over$id;
70
+ var _active$id$split = active === null || active === void 0 ? void 0 : (_active$id = active.id) === null || _active$id === void 0 ? void 0 : _active$id.split('-'),
71
+ _active$id$split2 = _slicedToArray(_active$id$split, 2),
72
+ activeParentId = _active$id$split2[0],
73
+ _activeId = _active$id$split2[1];
74
+ var _over$id$split = over === null || over === void 0 ? void 0 : (_over$id = over.id) === null || _over$id === void 0 ? void 0 : _over$id.split('-'),
75
+ _over$id$split2 = _slicedToArray(_over$id$split, 2),
76
+ overParentId = _over$id$split2[0],
77
+ overId = _over$id$split2[1];
76
78
  var parentIndex = lists.findIndex(function (item) {
77
79
  return item[rowKey] == activeParentId;
78
80
  });
@@ -132,22 +134,24 @@ var TreeItem = function TreeItem(props) {
132
134
  };
133
135
  var renderChildren = useMemo(function () {
134
136
  var _item$children2;
135
- return (item === null || item === void 0 ? void 0 : (_item$children2 = item.children) === null || _item$children2 === void 0 ? void 0 : _item$children2.length) > 0 && (expandedKeys === null || expandedKeys === void 0 ? void 0 : expandedKeys.includes(item[rowKey])) && /*#__PURE__*/React.createElement(SortableContext, {
137
+ var showChildren = (item === null || item === void 0 ? void 0 : (_item$children2 = item.children) === null || _item$children2 === void 0 ? void 0 : _item$children2.length) > 0 && (expandedKeys === null || expandedKeys === void 0 ? void 0 : expandedKeys.includes(item[rowKey]));
138
+ var _isAvailableTab = (childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.tabKey) === 'available';
139
+ return showChildren && /*#__PURE__*/React.createElement(SortableContext, {
136
140
  items: item.children.map(function (child) {
137
141
  return "".concat(item[rowKey], "-").concat(child[rowKey]);
138
142
  }),
139
143
  strategy: verticalListSortingStrategy
140
144
  }, item.children.map(function (child) {
141
- return /*#__PURE__*/React.createElement(TreeItem, {
145
+ return _isAvailableTab && child !== null && child !== void 0 && child.is_available || !_isAvailableTab ? /*#__PURE__*/React.createElement(TreeItem, {
142
146
  id: "".concat(item[rowKey], "-").concat(child[rowKey]),
143
147
  key: "".concat(item[rowKey], "-").concat(child[rowKey]),
144
148
  item: child,
145
149
  lists: lists,
146
150
  depth: depth + 1,
147
151
  childrenProps: childrenProps
148
- });
152
+ }) : null;
149
153
  }));
150
- }, [item.children, expandedKeys, rowKey, lists]);
154
+ }, [item.children, expandedKeys, rowKey, lists, childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.tabKey]);
151
155
 
152
156
  // 右侧图标
153
157
  var rightIcon = useMemo(function () {
@@ -179,7 +183,7 @@ var TreeItem = function TreeItem(props) {
179
183
  style: style
180
184
  }, attributes, listeners), /*#__PURE__*/React.createElement("div", {
181
185
  style: {
182
- paddingLeft: "".concat(depth * 20, "px")
186
+ paddingLeft: !depth ? '8px' : "".concat(depth * 20, "px")
183
187
  },
184
188
  className: classNames("".concat(prefix, "-drag-sort-tree"), childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.className),
185
189
  onClick: onSelect
@@ -6,9 +6,12 @@
6
6
  align-items: center;
7
7
  justify-content: space-between;
8
8
  font-size: 16px;
9
- padding: 6px;
10
9
  cursor: pointer;
11
10
  touch-action: none !important;
11
+ width: 100%;
12
+ color: #101828;
13
+ height: 40px;
14
+ line-height: 40px;
12
15
  }
13
16
 
14
17
  &-drag-sort-tree:hover {
@@ -22,6 +25,7 @@
22
25
 
23
26
  &-drag-sort-tree &-drag-sort-tree-title {
24
27
  margin-left: 10px;
28
+ font-size: 14px;
25
29
  }
26
30
 
27
31
  &-drag-sort-tree-icon,
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import React, { useState } from 'react';
7
+ import React, { useEffect, useState } from 'react';
8
8
  import { DndContext, useSensor, useSensors, PointerSensor } from '@dnd-kit/core';
9
9
  import { SortableContext, verticalListSortingStrategy, arrayMove } from '@dnd-kit/sortable';
10
10
  import TreeItem from "./TreeItem";
@@ -12,6 +12,7 @@ import { restrictToVerticalAxis, restrictToParentElement } from '@dnd-kit/modifi
12
12
  var DragSortTree = function DragSortTree(props) {
13
13
  var value = props.value,
14
14
  rowKey = props.rowKey,
15
+ tabKey = props.tabKey,
15
16
  onChange = props.onChange;
16
17
  var _useState = useState(value || []),
17
18
  _useState2 = _slicedToArray(_useState, 2),
@@ -21,6 +22,10 @@ var DragSortTree = function DragSortTree(props) {
21
22
  _useState4 = _slicedToArray(_useState3, 2),
22
23
  activeId = _useState4[0],
23
24
  setActiveId = _useState4[1];
25
+ useEffect(function () {
26
+ // 防止切换的时候数据不更新,拖拽之后,如果切换tab,需要用更新之后的数据
27
+ setItems(value || []);
28
+ }, [tabKey]);
24
29
  var sensors = useSensors(useSensor(PointerSensor, {
25
30
  activationConstraint: {
26
31
  distance: 5
@@ -28,17 +33,18 @@ var DragSortTree = function DragSortTree(props) {
28
33
  }));
29
34
  var handleDragStart = function handleDragStart(event) {
30
35
  var active = event.active;
31
- setActiveId(active[rowKey]);
36
+ setActiveId(active === null || active === void 0 ? void 0 : active.id);
32
37
  };
33
38
  var handleDragEnd = function handleDragEnd(event) {
34
39
  var active = event.active,
35
40
  over = event.over;
41
+
36
42
  // 拖拽结束将这个值设置为空,防止第二次拖拽同一个节点,监听不到这个变化
37
43
  setActiveId(null);
38
44
  if (!over || !active) return;
39
45
  try {
40
- var _activeId = active[rowKey];
41
- var overId = over[rowKey];
46
+ var _activeId = active.id;
47
+ var overId = over.id;
42
48
  if (_activeId !== overId) {
43
49
  var activeIndex = items.findIndex(function (item) {
44
50
  return item[rowKey] === _activeId;
@@ -15,5 +15,6 @@ export declare type SortType = {
15
15
  hiddenDraggableIcon?: boolean;
16
16
  hiddenRightIcon?: boolean;
17
17
  hiddenWarningIcon?: boolean;
18
+ tabKey?: string;
18
19
  onChange?: (value: ValueProps[]) => void;
19
20
  };
@@ -52,7 +52,7 @@ var TreeItem = (props) => {
52
52
  }
53
53
  }, [activeId]);
54
54
  const style = {
55
- transform: import_utilities.CSS.Transform.toString(transform),
55
+ transform: import_utilities.CSS.Transform.toString(transform && { ...transform, scaleY: 1 }),
56
56
  transition
57
57
  };
58
58
  const rowKey = (0, import_react.useMemo)(() => {
@@ -64,8 +64,8 @@ var TreeItem = (props) => {
64
64
  if (!over || !active || !lists.length)
65
65
  return;
66
66
  try {
67
- let [activeParentId, activeId2] = (_a = active[rowKey]) == null ? void 0 : _a.split("-");
68
- let [overParentId, overId] = (_b = over[rowKey]) == null ? void 0 : _b.split("-");
67
+ let [activeParentId, activeId2] = (_a = active == null ? void 0 : active.id) == null ? void 0 : _a.split("-");
68
+ let [overParentId, overId] = (_b = over == null ? void 0 : over.id) == null ? void 0 : _b.split("-");
69
69
  const parentIndex = lists.findIndex(
70
70
  (item2) => item2[rowKey] == activeParentId
71
71
  );
@@ -118,7 +118,9 @@ var TreeItem = (props) => {
118
118
  };
119
119
  const renderChildren = (0, import_react.useMemo)(() => {
120
120
  var _a;
121
- return ((_a = item == null ? void 0 : item.children) == null ? void 0 : _a.length) > 0 && (expandedKeys == null ? void 0 : expandedKeys.includes(item[rowKey])) && /* @__PURE__ */ import_react.default.createElement(
121
+ const showChildren = ((_a = item == null ? void 0 : item.children) == null ? void 0 : _a.length) > 0 && (expandedKeys == null ? void 0 : expandedKeys.includes(item[rowKey]));
122
+ const _isAvailableTab = (childrenProps == null ? void 0 : childrenProps.tabKey) === "available";
123
+ return showChildren && /* @__PURE__ */ import_react.default.createElement(
122
124
  import_sortable2.SortableContext,
123
125
  {
124
126
  items: item.children.map(
@@ -126,19 +128,21 @@ var TreeItem = (props) => {
126
128
  ),
127
129
  strategy: import_sortable2.verticalListSortingStrategy
128
130
  },
129
- item.children.map((child) => /* @__PURE__ */ import_react.default.createElement(
130
- TreeItem,
131
- {
132
- id: `${item[rowKey]}-${child[rowKey]}`,
133
- key: `${item[rowKey]}-${child[rowKey]}`,
134
- item: child,
135
- lists,
136
- depth: depth + 1,
137
- childrenProps
138
- }
139
- ))
131
+ item.children.map(
132
+ (child) => _isAvailableTab && (child == null ? void 0 : child.is_available) || !_isAvailableTab ? /* @__PURE__ */ import_react.default.createElement(
133
+ TreeItem,
134
+ {
135
+ id: `${item[rowKey]}-${child[rowKey]}`,
136
+ key: `${item[rowKey]}-${child[rowKey]}`,
137
+ item: child,
138
+ lists,
139
+ depth: depth + 1,
140
+ childrenProps
141
+ }
142
+ ) : null
143
+ )
140
144
  );
141
- }, [item.children, expandedKeys, rowKey, lists]);
145
+ }, [item.children, expandedKeys, rowKey, lists, childrenProps == null ? void 0 : childrenProps.tabKey]);
142
146
  const rightIcon = (0, import_react.useMemo)(() => {
143
147
  const hiddenRightIcon = childrenProps == null ? void 0 : childrenProps.hiddenRightIcon;
144
148
  return !hiddenRightIcon ? /* @__PURE__ */ import_react.default.createElement(
@@ -164,7 +168,7 @@ var TreeItem = (props) => {
164
168
  /* @__PURE__ */ import_react.default.createElement("div", { ref: setNodeRef, style, ...attributes, ...listeners }, /* @__PURE__ */ import_react.default.createElement(
165
169
  "div",
166
170
  {
167
- style: { paddingLeft: `${depth * 20}px` },
171
+ style: { paddingLeft: !depth ? "8px" : `${depth * 20}px` },
168
172
  className: (0, import_classnames.default)(
169
173
  `${prefix}-drag-sort-tree`,
170
174
  childrenProps == null ? void 0 : childrenProps.className
@@ -6,9 +6,12 @@
6
6
  align-items: center;
7
7
  justify-content: space-between;
8
8
  font-size: 16px;
9
- padding: 6px;
10
9
  cursor: pointer;
11
10
  touch-action: none !important;
11
+ width: 100%;
12
+ color: #101828;
13
+ height: 40px;
14
+ line-height: 40px;
12
15
  }
13
16
 
14
17
  &-drag-sort-tree:hover {
@@ -22,6 +25,7 @@
22
25
 
23
26
  &-drag-sort-tree &-drag-sort-tree-title {
24
27
  margin-left: 10px;
28
+ font-size: 14px;
25
29
  }
26
30
 
27
31
  &-drag-sort-tree-icon,
@@ -38,9 +38,12 @@ var import_sortable = require("@dnd-kit/sortable");
38
38
  var import_TreeItem = __toESM(require("./TreeItem"));
39
39
  var import_modifiers = require("@dnd-kit/modifiers");
40
40
  var DragSortTree = (props) => {
41
- const { value, rowKey, onChange } = props;
41
+ const { value, rowKey, tabKey, onChange } = props;
42
42
  const [items, setItems] = (0, import_react.useState)(value || []);
43
43
  const [activeId, setActiveId] = (0, import_react.useState)(null);
44
+ (0, import_react.useEffect)(() => {
45
+ setItems(value || []);
46
+ }, [tabKey]);
44
47
  const sensors = (0, import_core.useSensors)(
45
48
  (0, import_core.useSensor)(import_core.PointerSensor, {
46
49
  activationConstraint: {
@@ -50,7 +53,7 @@ var DragSortTree = (props) => {
50
53
  );
51
54
  const handleDragStart = (event) => {
52
55
  const { active } = event;
53
- setActiveId(active[rowKey]);
56
+ setActiveId(active == null ? void 0 : active.id);
54
57
  };
55
58
  const handleDragEnd = (event) => {
56
59
  const { active, over } = event;
@@ -58,8 +61,8 @@ var DragSortTree = (props) => {
58
61
  if (!over || !active)
59
62
  return;
60
63
  try {
61
- const activeId2 = active[rowKey];
62
- const overId = over[rowKey];
64
+ const activeId2 = active.id;
65
+ const overId = over.id;
63
66
  if (activeId2 !== overId) {
64
67
  const activeIndex = items.findIndex(
65
68
  (item) => item[rowKey] === activeId2
@@ -15,5 +15,6 @@ export declare type SortType = {
15
15
  hiddenDraggableIcon?: boolean;
16
16
  hiddenRightIcon?: boolean;
17
17
  hiddenWarningIcon?: boolean;
18
+ tabKey?: string;
18
19
  onChange?: (value: ValueProps[]) => void;
19
20
  };
@@ -62,6 +62,11 @@ export default {
62
62
  },
63
63
  ]
64
64
  },
65
+ {
66
+ name: "tabKey",
67
+ title: { label: 'tabKey', tip: 'tabKey | 标识当前选中的tab' },
68
+ propType: 'string',
69
+ },
65
70
  {
66
71
  name: "titleRender",
67
72
  title: { label: '标题', tip: '是否自定义标题内容 | node/func' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "1.0.340",
3
+ "version": "1.0.342",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",