pixuireactcomponents 1.5.18 → 1.5.20

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.5.18",
3
+ "version": "1.5.20",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -46,6 +46,7 @@ export declare class DragList extends Component<DragListProps, DragListState> {
46
46
  private dragIndex;
47
47
  private dragEndIndex;
48
48
  private containerRect;
49
+ private init;
49
50
  constructor(props: DragListProps);
50
51
  componentDidMount(): void;
51
52
  moveItem(oldIndex: number, newIndex: number): void;
@@ -30,9 +30,10 @@ var DragItem = /** @class */ (function (_super) {
30
30
  function DragItem(props) {
31
31
  var _this = _super.call(this, props) || this;
32
32
  _this.updateIndex = function (index) {
33
+ _this.index = index;
33
34
  var newCol = index % _this.props.visibleCount;
34
35
  var newRow = Math.floor(index / _this.props.visibleCount);
35
- _this.setState({ index: index, col: newCol, row: newRow });
36
+ _this.setState({ col: newCol, row: newRow });
36
37
  if (_this.props.animationTime != 0) {
37
38
  if (_this.animation) {
38
39
  clearTimeout(_this.animation);
@@ -44,17 +45,16 @@ var DragItem = /** @class */ (function (_super) {
44
45
  };
45
46
  _this.handleDragStart = function (e) {
46
47
  _this.setState({ isDragging: true });
47
- _this.props.onDragStart(_this.state.index, e);
48
+ _this.props.onDragStart(_this.index, e);
48
49
  };
49
50
  _this.handleDrag = function (e) {
50
- _this.props.onDrag(_this.state.index, e);
51
+ _this.props.onDrag(_this.index, e);
51
52
  };
52
53
  _this.handleDragEnd = function (e) {
53
54
  _this.setState({ isDragging: false });
54
- _this.props.onDragEnd(_this.state.index, e);
55
+ _this.props.onDragEnd(_this.index, e);
55
56
  };
56
57
  _this.state = {
57
- index: props.index,
58
58
  isValid: true,
59
59
  child: props.child,
60
60
  col: _this.props.index % _this.props.visibleCount,
@@ -62,6 +62,7 @@ var DragItem = /** @class */ (function (_super) {
62
62
  isDragging: false,
63
63
  };
64
64
  _this.ref = createRef();
65
+ _this.index = props.index;
65
66
  return _this;
66
67
  }
67
68
  DragItem.prototype.render = function () {
@@ -117,13 +118,12 @@ var DragList = /** @class */ (function (_super) {
117
118
  dragOffsetX: relativeX - _this.props.itemWidth / 2,
118
119
  dragOffsetY: relativeY - _this.props.itemHeight / 2,
119
120
  });
120
- if (_this.state.draggingIndex !== null && validIndex !== _this.state.draggingIndex) {
121
- _this.moveItem(_this.state.draggingIndex, validIndex);
122
- _this.setState({ draggingIndex: validIndex });
121
+ if (_this.dragIndex !== -1 && validIndex !== _this.dragIndex) {
122
+ _this.moveItem(_this.dragIndex, validIndex);
123
+ _this.dragIndex = validIndex;
123
124
  }
124
125
  };
125
126
  _this.handleDragEnd = function (index, e) {
126
- console.log('dragend', e);
127
127
  _this.dragIndex = -1;
128
128
  _this.setState({
129
129
  draggingIndex: null,
@@ -145,49 +145,49 @@ var DragList = /** @class */ (function (_super) {
145
145
  width: 0,
146
146
  height: 0,
147
147
  };
148
+ _this.init = false;
148
149
  return _this;
149
150
  }
150
151
  DragList.prototype.componentDidMount = function () {
151
152
  if (this.ref.current) {
152
153
  this.containerRect = this.ref.current.getBoundingClientRect();
153
154
  this.listSize = this.containerRect.width;
155
+ this.init = true;
154
156
  }
155
- this.visibleCount = Math.floor(this.listSize / this.props.itemWidth);
156
- for (var i = 0; i < this.props.itemSize; i++) {
157
- var ref = createRef();
158
- var item = {
159
- vNode: (h(DragItem, { onDragStart: this.handleDragStart, onDrag: this.handleDrag, onDragEnd: this.handleDragEnd, key: i, ref: ref, index: i, child: this.props.renderItemFunc(i), itemHeight: this.props.itemHeight, itemWidth: this.props.itemWidth, visibleCount: this.visibleCount, animationTime: this.props.animationTime != null ? this.props.animationTime : 150, style: this.props.itemStyle ? this.props.itemStyle : {}, dragStyle: this.props.dragItemStyle ? this.props.dragItemStyle : {} })),
160
- isValid: false,
161
- ref: ref,
162
- };
163
- this.itemCache.push(item);
157
+ if (this.init) {
158
+ this.visibleCount = Math.floor(this.listSize / this.props.itemWidth);
159
+ for (var i = 0; i < this.props.itemSize; i++) {
160
+ var ref = createRef();
161
+ var item = {
162
+ vNode: (h(DragItem, { onDragStart: this.handleDragStart, onDrag: this.handleDrag, onDragEnd: this.handleDragEnd, key: i, ref: ref, index: i, child: this.props.renderItemFunc(i), itemHeight: this.props.itemHeight, itemWidth: this.props.itemWidth, visibleCount: this.visibleCount, animationTime: this.props.animationTime != null ? this.props.animationTime : 150, style: this.props.itemStyle ? this.props.itemStyle : {}, dragStyle: this.props.dragItemStyle ? this.props.dragItemStyle : {} })),
163
+ isValid: false,
164
+ ref: ref,
165
+ };
166
+ this.itemCache.push(item);
167
+ }
168
+ this.forceUpdate();
164
169
  }
165
- this.forceUpdate();
166
170
  };
167
171
  DragList.prototype.moveItem = function (oldIndex, newIndex) {
168
- var item = this.itemCache[oldIndex];
169
- // this.itemCache.splice(oldIndex, 1);
170
- // this.itemCache.splice(newIndex, 0, item);
171
172
  for (var i = 0; i < this.itemCache.length; i++) {
172
173
  var node = this.itemCache[i].ref.current;
173
174
  if (oldIndex < newIndex) {
174
- if (node.state.index > oldIndex && node.state.index <= newIndex) {
175
- this.itemCache[i].ref.current.updateIndex(node.state.index - 1);
175
+ if (node.index > oldIndex && node.index <= newIndex) {
176
+ this.itemCache[i].ref.current.updateIndex(node.index - 1);
176
177
  }
177
- else if (node.state.index == oldIndex) {
178
+ else if (node.index == oldIndex) {
178
179
  this.itemCache[i].ref.current.updateIndex(newIndex);
179
180
  }
180
181
  }
181
182
  else {
182
- if (node.state.index >= newIndex && node.state.index < oldIndex) {
183
- this.itemCache[i].ref.current.updateIndex(node.state.index + 1);
183
+ if (node.index >= newIndex && node.index < oldIndex) {
184
+ this.itemCache[i].ref.current.updateIndex(node.index + 1);
184
185
  }
185
- else if (node.state.index == oldIndex) {
186
+ else if (node.index == oldIndex) {
186
187
  this.itemCache[i].ref.current.updateIndex(newIndex);
187
188
  }
188
189
  }
189
190
  }
190
- this.forceUpdate();
191
191
  };
192
192
  DragList.prototype.render = function () {
193
193
  return (h("div", { ref: this.ref, style: {
@@ -197,7 +197,7 @@ var DragList = /** @class */ (function (_super) {
197
197
  height: this.props.height,
198
198
  } },
199
199
  this.itemCache.map(function (item) { return item.vNode; }),
200
- this.state.draggingIndex !== null && (h("div", { style: __assign({ position: 'absolute', top: "".concat(this.state.dragOffsetY, "px"), left: "".concat(this.state.dragOffsetX, "px"), width: this.props.itemWidth, height: this.props.itemHeight, zIndex: 1000, pointerEvents: 'none', opacity: 0.5 }, this.props.hoverItemStyle) }))));
200
+ h("div", { style: __assign({ display: this.state.draggingIndex !== null ? 'block' : 'none', position: 'absolute', top: "".concat(this.state.dragOffsetY, "px"), left: "".concat(this.state.dragOffsetX, "px"), width: this.props.itemWidth, height: this.props.itemHeight, zIndex: 1000, pointerEvents: 'none', opacity: 0.5 }, this.props.hoverItemStyle) })));
201
201
  };
202
202
  return DragList;
203
203
  }(Component));