@pisell/materials 1.0.341 → 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.
@@ -135,15 +135,14 @@ var TreeItem = function TreeItem(props) {
135
135
  var renderChildren = useMemo(function () {
136
136
  var _item$children2;
137
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
- console.log('showChildren', childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.tabKey);
139
- var _tabKey = childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.tabKey;
138
+ var _isAvailableTab = (childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.tabKey) === 'available';
140
139
  return showChildren && /*#__PURE__*/React.createElement(SortableContext, {
141
140
  items: item.children.map(function (child) {
142
141
  return "".concat(item[rowKey], "-").concat(child[rowKey]);
143
142
  }),
144
143
  strategy: verticalListSortingStrategy
145
144
  }, item.children.map(function (child) {
146
- return _tabKey === 'available' && child !== null && child !== void 0 && child.is_available || !_tabKey ? /*#__PURE__*/React.createElement(TreeItem, {
145
+ return _isAvailableTab && child !== null && child !== void 0 && child.is_available || !_isAvailableTab ? /*#__PURE__*/React.createElement(TreeItem, {
147
146
  id: "".concat(item[rowKey], "-").concat(child[rowKey]),
148
147
  key: "".concat(item[rowKey], "-").concat(child[rowKey]),
149
148
  item: child,
@@ -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
@@ -119,8 +119,7 @@ var TreeItem = (props) => {
119
119
  const renderChildren = (0, import_react.useMemo)(() => {
120
120
  var _a;
121
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
- console.log("showChildren", childrenProps == null ? void 0 : childrenProps.tabKey);
123
- const _tabKey = childrenProps == null ? void 0 : childrenProps.tabKey;
122
+ const _isAvailableTab = (childrenProps == null ? void 0 : childrenProps.tabKey) === "available";
124
123
  return showChildren && /* @__PURE__ */ import_react.default.createElement(
125
124
  import_sortable2.SortableContext,
126
125
  {
@@ -130,7 +129,7 @@ var TreeItem = (props) => {
130
129
  strategy: import_sortable2.verticalListSortingStrategy
131
130
  },
132
131
  item.children.map(
133
- (child) => _tabKey === "available" && (child == null ? void 0 : child.is_available) || !_tabKey ? /* @__PURE__ */ import_react.default.createElement(
132
+ (child) => _isAvailableTab && (child == null ? void 0 : child.is_available) || !_isAvailableTab ? /* @__PURE__ */ import_react.default.createElement(
134
133
  TreeItem,
135
134
  {
136
135
  id: `${item[rowKey]}-${child[rowKey]}`,
@@ -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: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "1.0.341",
3
+ "version": "1.0.342",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -63,8 +63,8 @@
63
63
  "react-virtualized-auto-sizer": "^1.0.20",
64
64
  "crypto-js": "^4.2.0",
65
65
  "@pisell/utils": "1.0.27",
66
- "@pisell/date-picker": "1.0.82",
67
- "@pisell/icon": "0.0.10"
66
+ "@pisell/icon": "0.0.10",
67
+ "@pisell/date-picker": "1.0.82"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "react": "^18.0.0",