slick-components 4.4.13 → 4.4.14

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.
@@ -69,7 +69,7 @@
69
69
  };
70
70
  return SlickInitService;
71
71
  }());
72
- SlickInitService.version = "4.4.13";
72
+ SlickInitService.version = "4.4.14";
73
73
  SlickInitService.decorators = [
74
74
  { type: core.Injectable }
75
75
  ];
@@ -566,6 +566,16 @@
566
566
  }
567
567
  return hasSelector;
568
568
  };
569
+ SlickUtilsService.findParentByAttr = function (el, attrName, attrValue) {
570
+ var currentEl = el;
571
+ while (currentEl && currentEl !== document.body) {
572
+ if (currentEl.hasAttribute(attrName) && currentEl.getAttribute(attrName) === attrValue) {
573
+ return currentEl;
574
+ }
575
+ currentEl = currentEl.parentElement;
576
+ }
577
+ return null;
578
+ };
569
579
  SlickUtilsService.findParent = function (el, className) {
570
580
  var currentEl = el;
571
581
  while (currentEl && currentEl !== document.body) {
@@ -633,6 +643,11 @@
633
643
  }
634
644
  catch (_a) { }
635
645
  };
646
+ SlickUtilsService.arrayInsert = function (elementToInsert, arr, index) {
647
+ var pre = arr.slice(0, index);
648
+ var post = arr.slice(index, arr.length);
649
+ return __spreadArray(__spreadArray(__spreadArray([], __read(pre)), [elementToInsert]), __read(post));
650
+ };
636
651
  return SlickUtilsService;
637
652
  }());
638
653
  SlickUtilsService.getHashCode = function (str) {
@@ -3968,155 +3983,205 @@
3968
3983
  function SlickDropListDirective(el) {
3969
3984
  var _this = this;
3970
3985
  this.onSlickDropListReorder = new core.EventEmitter();
3986
+ this.onSlickDropListEnter = new core.EventEmitter();
3987
+ this.onSlickDropListLeave = new core.EventEmitter();
3971
3988
  this.uuid = SlickUtilsService.newGuid();
3972
3989
  this.fnMouseDown = function (e) { return _this.mouseDown(e); };
3973
- this.fnMouseEnter = function (e) { return _this.mouseEnter(e); };
3990
+ this.fnMouseMove = function (e) { return _this.mouseMove(e); };
3974
3991
  this.fnMouseUp = function () { return _this.mouseUp(); };
3975
- this.first = true;
3976
3992
  this.el = el.nativeElement;
3977
3993
  this.el.setAttribute("drop-list-uuid", this.uuid);
3978
3994
  }
3979
3995
  SlickDropListDirective.prototype.ngOnInit = function () {
3980
3996
  this.el.style.position = "relative";
3981
- this.el.addEventListener("mousedown", this.fnMouseDown, true);
3997
+ document.addEventListener("mousedown", this.fnMouseDown, true);
3982
3998
  };
3983
3999
  SlickDropListDirective.prototype.ngOnDestroy = function () {
3984
- var _this = this;
3985
- this.el.removeEventListener("mousedown", this.fnMouseDown, true);
4000
+ document.removeEventListener("mousedown", this.fnMouseDown, true);
4001
+ document.removeEventListener("mousemove", this.fnMouseMove, true);
3986
4002
  document.removeEventListener("mouseup", this.fnMouseUp, true);
3987
- this.el.querySelectorAll(".slick-drop-list-item").forEach(function (e) { return e.removeEventListener("mouseenter", _this.fnMouseEnter, false); });
3988
4003
  };
3989
- SlickDropListDirective.prototype.mouseDown = function (e) {
4004
+ SlickDropListDirective.prototype.mouseDown = function (e, target) {
4005
+ if (target === void 0) { target = null; }
3990
4006
  return __awaiter(this, void 0, void 0, function () {
3991
- var grabEls, sortOrder, dropListItems, i, item, dropListItem;
3992
- var _this = this;
4007
+ var parent, grabEls, dropListItem;
3993
4008
  return __generator(this, function (_a) {
4009
+ this.isAdding = false;
4010
+ this.isMoving = false;
3994
4011
  if (e.button !== 0 || !e || !e.target)
3995
4012
  return [2 /*return*/];
4013
+ document.removeEventListener("mouseup", this.fnMouseUp, true);
4014
+ document.removeEventListener("mousemove", this.fnMouseMove, true);
4015
+ document.addEventListener("mouseup", this.fnMouseUp, true);
4016
+ document.addEventListener("mousemove", this.fnMouseMove, true);
4017
+ if (!target)
4018
+ target = e.target;
4019
+ parent = SlickUtilsService.findParentByAttr(target, 'drop-list-uuid', this.uuid);
4020
+ if (!parent)
4021
+ return [2 /*return*/];
4022
+ this.isMoving = true;
3996
4023
  grabEls = this.el.querySelectorAll(".slick-drop-list-grab");
3997
- if (grabEls.length > 0 && !SlickUtilsService.findParent(e.target, "slick-drop-list-grab"))
4024
+ if (grabEls.length > 0 && !SlickUtilsService.findParent(target, "slick-drop-list-grab"))
3998
4025
  return [2 /*return*/, true];
3999
- this.first = true;
4000
- this.isMoving = true;
4001
- sortOrder = 0;
4002
- dropListItems = this.el.querySelectorAll(".slick-drop-list-item");
4003
- for (i = 0; i < dropListItems.length; i++) {
4004
- item = dropListItems[i];
4005
- item.setAttribute("data-sortorder", sortOrder.toString());
4006
- //item.style.cursor = "move";
4007
- sortOrder++;
4008
- }
4009
- document.removeEventListener("mouseup", this.fnMouseUp, true);
4010
- this.el.querySelectorAll(".slick-drop-list-item").forEach(function (e) { return e.removeEventListener("mouseenter", _this.fnMouseEnter, false); });
4011
- dropListItem = SlickUtilsService.findParent(e.target, "slick-drop-list-item");
4026
+ dropListItem = SlickUtilsService.findParent(target, "slick-drop-list-item");
4012
4027
  if (!dropListItem) {
4013
4028
  console.error("Can't find item element");
4014
4029
  return [2 /*return*/];
4015
4030
  }
4016
- this.el.style.userSelect = "none";
4017
- this.cursorOffset = e.pageY - dropListItem.getBoundingClientRect().top;
4018
- this.originalIdx = parseInt(dropListItem.getAttribute("data-sortorder"));
4019
- this.currentIdx = parseInt(dropListItem.getAttribute("data-sortorder"));
4020
- this.lastIdx = parseInt(dropListItem.getAttribute("data-sortorder"));
4021
- this.placeholderEl = dropListItem;
4022
- this.placeholderEl.classList.add("slick-drop-list-placeholder");
4023
- this.placeholderEl.classList.remove("slick-drop-list-item");
4024
- this.placeholderEl.style.boxShadow = "4px 12px 6px rgba(0,0,0,.24)";
4025
- this.placeholderHeight = this.placeholderEl.getBoundingClientRect().height;
4026
- this.el.removeChild(this.placeholderEl);
4027
- this.el.appendChild(this.placeholderEl);
4028
- this.itemHeights = [];
4029
- this.el.querySelectorAll(".slick-drop-list-item").forEach(function (item) { return _this.itemHeights.push(item.getBoundingClientRect().height); });
4030
- this.el.querySelectorAll(".slick-drop-list-item").forEach(function (e) { return e.addEventListener("mouseenter", _this.fnMouseEnter, false); });
4031
- document.addEventListener("mouseup", this.fnMouseUp, true);
4031
+ // Find which element the mouse is over
4032
+ this.currentIdx = this.findElementIdx(e.y, false);
4033
+ this.originalIdx = this.currentIdx;
4034
+ this.startMove(dropListItem);
4032
4035
  return [2 /*return*/];
4033
4036
  });
4034
4037
  });
4035
4038
  };
4036
- SlickDropListDirective.prototype.mouseEnter = function (e) {
4037
- // Now see if we need to swap the orders
4038
- var parent = SlickUtilsService.findParent(e.target, "slick-drop-list-item");
4039
- if (parent && !parent.classList.contains("slick-drop-list-placeholder")) {
4040
- this.currentIdx = 0;
4041
- var allDropListItems = this.el.querySelectorAll(".slick-drop-list-item");
4042
- for (var i = 0; i < allDropListItems.length; i++) {
4043
- var item = allDropListItems[i];
4044
- if (item !== parent)
4045
- this.currentIdx++;
4046
- else
4047
- break;
4039
+ SlickDropListDirective.prototype.mouseMove = function (e) {
4040
+ if (this.isAdding)
4041
+ return;
4042
+ var parent = SlickUtilsService.findParentByAttr(e.target, 'drop-list-uuid', this.uuid);
4043
+ if (!parent) {
4044
+ // If this isn't the parent, but we we're moving, that means we just left this parent
4045
+ // Send a message which element was dragged out and reset everything else
4046
+ if (this.isMoving && this.onSlickDropListLeave.observers.length > 0) {
4047
+ this.isMoving = false;
4048
+ var allItems = this.el.querySelectorAll(".slick-drop-list-item");
4049
+ allItems.forEach(function (item) {
4050
+ item.classList.remove("slick-drop-list-item-animation");
4051
+ item.style.transform = "";
4052
+ });
4053
+ this.onSlickDropListLeave.emit(this.originalIdx);
4054
+ }
4055
+ return;
4056
+ }
4057
+ if (!this.isMoving && this.onSlickDropListEnter.observers.length === 0)
4058
+ return;
4059
+ // If the mouse was clicked outside of this droplist, but it has now moved inside this droplist, tell the parent where
4060
+ // in the droplist it has moved.
4061
+ // Since there is no way for a directive to have functions called via ViewChild, just assume that the page
4062
+ // has added the appropriate element at the appropriate place
4063
+ if (!this.isMoving && this.onSlickDropListEnter) {
4064
+ this.isAdding = true;
4065
+ // Find which element the mouse is over
4066
+ var idx = this.findElementIdx(e.y, false);
4067
+ this.isAddingMouseEvent = e;
4068
+ // The caller needs to call the ready function after adding the new record to the array
4069
+ this.onSlickDropListEnter.emit({ idx: idx, ready: this.newItemReady.bind(this) });
4070
+ return;
4071
+ }
4072
+ // Find which element the mouse is over
4073
+ var dropListItems = this.el.querySelectorAll(".slick-drop-list-item");
4074
+ for (var i = 0; i < dropListItems.length; i++) {
4075
+ var dropListItem = dropListItems[i];
4076
+ var boundingRect = dropListItem.getBoundingClientRect();
4077
+ var topHalfTop = boundingRect.top;
4078
+ var topHalfBottom = topHalfTop + (boundingRect.height / 2);
4079
+ var bottomHalfTop = topHalfBottom + 1;
4080
+ var bottomHalfBottom = boundingRect.bottom;
4081
+ if (this.currentIdx !== i && e.y >= topHalfTop && e.y <= topHalfBottom) {
4082
+ this.currentIdx = i;
4083
+ this.redraw();
4084
+ break;
4085
+ }
4086
+ if (this.currentIdx !== i + 1 && e.y >= bottomHalfTop && e.y <= bottomHalfBottom) {
4087
+ this.currentIdx = i + 1;
4088
+ this.redraw();
4089
+ break;
4048
4090
  }
4049
- this.redraw();
4050
4091
  }
4051
4092
  };
4052
4093
  SlickDropListDirective.prototype.mouseUp = function () {
4053
- var _this = this;
4054
- var allItems = this.el.querySelectorAll(".slick-drop-list-item");
4055
- var sortOrderEl = allItems[this.currentIdx];
4056
- var sortOrder = parseInt(sortOrderEl.getAttribute("data-sortorder"));
4094
+ document.removeEventListener("mouseup", this.fnMouseUp, true);
4095
+ document.removeEventListener("mousemove", this.fnMouseMove, true);
4096
+ if (!this.isMoving)
4097
+ return;
4098
+ this.isMoving = false;
4099
+ // Remove the placeholder
4057
4100
  this.placeholderEl.classList.remove("slick-drop-list-placeholder");
4058
4101
  this.placeholderEl.classList.add("slick-drop-list-item");
4059
4102
  this.placeholderEl.style.boxShadow = "";
4060
4103
  this.placeholderEl.style.transform = "";
4061
- this.placeholderEl.removeAttribute("data-sortorder");
4062
- this.placeholderEl.removeEventListener("mouseenter", this.fnMouseEnter, false);
4063
4104
  this.el.removeChild(this.placeholderEl);
4064
- if (sortOrder === allItems.length)
4105
+ // Add the placeholder back
4106
+ var allItems = this.el.querySelectorAll(".slick-drop-list-item");
4107
+ if (this.currentIdx === allItems.length)
4065
4108
  this.el.appendChild(this.placeholderEl);
4066
4109
  else
4067
- this.el.insertBefore(this.placeholderEl, sortOrderEl);
4110
+ this.el.insertBefore(this.placeholderEl, allItems[this.currentIdx]);
4068
4111
  this.placeholderEl = null;
4069
4112
  allItems.forEach(function (item) {
4070
4113
  item.classList.remove("slick-drop-list-item-animation");
4071
- item.removeAttribute("data-sortorder");
4072
4114
  item.style.transform = "";
4073
- item.removeEventListener("mouseenter", _this.fnMouseEnter, false);
4074
4115
  });
4075
- document.removeEventListener("mouseup", this.fnMouseUp, true);
4076
4116
  if (this.onSlickDropListReorder)
4077
- this.onSlickDropListReorder.emit([this.originalIdx, sortOrder]);
4117
+ this.onSlickDropListReorder.emit([this.originalIdx, this.currentIdx]);
4118
+ this.originalIdx = null;
4078
4119
  this.currentIdx = null;
4079
- this.lastIdx = null;
4080
- this.dir = null;
4081
4120
  };
4082
4121
  SlickDropListDirective.prototype.redraw = function () {
4083
- if (this.dir && this.currentIdx === this.lastIdx)
4084
- this.dir = (this.dir === 'UP') ? 'DOWN' : 'UP';
4085
- else
4086
- this.dir = (this.currentIdx <= this.lastIdx) ? "UP" : "DOWN";
4087
- this.lastIdx = this.currentIdx;
4088
4122
  var allChildren = this.el.querySelectorAll(".slick-drop-list-item");
4089
4123
  var placeholderOffset = 0;
4090
- if (this.dir === "UP") {
4091
- for (var i = 0; i < allChildren.length; i++) {
4092
- var item = allChildren[i];
4093
- if (i < this.currentIdx) {
4094
- item.style.transform = "translate3d(0px, 0px, 0px)";
4095
- }
4096
- else {
4097
- item.style.transform = "translate3d(0px, " + this.placeholderHeight + "px, 0px)";
4098
- placeholderOffset += this.itemHeights[i];
4099
- }
4124
+ for (var i = 0; i < allChildren.length; i++) {
4125
+ var item = allChildren[i];
4126
+ if (i < this.currentIdx) {
4127
+ item.style.transform = "translate3d(0px, 0px, 0px)";
4100
4128
  }
4101
- }
4102
- else {
4103
- for (var i = 0; i < allChildren.length; i++) {
4104
- var item = allChildren[i];
4105
- if (i <= this.currentIdx) {
4106
- item.style.transform = "translate3d(0px, 0px, 0px)";
4107
- }
4108
- else {
4109
- item.style.transform = "translate3d(0px, " + this.placeholderHeight + "px, 0px)";
4110
- placeholderOffset += this.itemHeights[i];
4111
- }
4129
+ else {
4130
+ item.style.transform = "translate3d(0px, " + this.placeholderHeight + "px, 0px)";
4131
+ placeholderOffset += this.itemHeights[i];
4112
4132
  }
4113
4133
  }
4114
4134
  this.placeholderEl.style.transform = "translate3d(0px, -" + placeholderOffset + "px, 0px)";
4115
- if (this.first) {
4116
- setTimeout(function () { return allChildren.forEach(function (item) { return item.classList.add("slick-drop-list-item-animation"); }); });
4117
- this.first = false;
4135
+ };
4136
+ SlickDropListDirective.prototype.newItemReady = function (idx) {
4137
+ var _this = this;
4138
+ setTimeout(function () {
4139
+ _this.currentIdx = idx;
4140
+ _this.originalIdx = idx;
4141
+ var dropListItem = _this.el.querySelectorAll(".slick-drop-list-item").item(idx);
4142
+ _this.mouseDown(_this.isAddingMouseEvent, dropListItem);
4143
+ });
4144
+ };
4145
+ SlickDropListDirective.prototype.findElementIdx = function (mouseY, useTopAndBottom) {
4146
+ var dropListItems = this.el.querySelectorAll(".slick-drop-list-item");
4147
+ for (var i = 0; i < dropListItems.length; i++) {
4148
+ var dropListItem = dropListItems[i];
4149
+ var boundingRect = dropListItem.getBoundingClientRect();
4150
+ if (useTopAndBottom) {
4151
+ var topHalfTop = boundingRect.top;
4152
+ var topHalfBottom = topHalfTop + (boundingRect.height / 2);
4153
+ var bottomHalfTop = topHalfBottom + 1;
4154
+ var bottomHalfBottom = boundingRect.bottom;
4155
+ if (mouseY >= topHalfTop && mouseY <= topHalfBottom)
4156
+ return i;
4157
+ if (mouseY >= bottomHalfTop && mouseY <= bottomHalfBottom)
4158
+ return i + 1;
4159
+ }
4160
+ else {
4161
+ if (mouseY >= boundingRect.top && mouseY <= boundingRect.bottom)
4162
+ return i;
4163
+ }
4118
4164
  }
4119
4165
  };
4166
+ SlickDropListDirective.prototype.startMove = function (dropListItem) {
4167
+ var _this = this;
4168
+ this.el.style.userSelect = "none";
4169
+ this.placeholderEl = dropListItem;
4170
+ this.placeholderEl.classList.add("slick-drop-list-placeholder");
4171
+ this.placeholderEl.classList.remove("slick-drop-list-item");
4172
+ this.placeholderEl.style.boxShadow = "4px 12px 6px rgba(0,0,0,.24)";
4173
+ this.placeholderHeight = this.placeholderEl.getBoundingClientRect().height;
4174
+ this.el.removeChild(this.placeholderEl);
4175
+ this.el.appendChild(this.placeholderEl);
4176
+ this.itemHeights = [];
4177
+ this.el.querySelectorAll(".slick-drop-list-item").forEach(function (item) { return _this.itemHeights.push(item.getBoundingClientRect().height); });
4178
+ this.redraw();
4179
+ // Don't start the animation until after the first click because it looks weird
4180
+ setTimeout(function () {
4181
+ var allChildren = _this.el.querySelectorAll(".slick-drop-list-item");
4182
+ allChildren.forEach(function (item) { return item.classList.add("slick-drop-list-item-animation"); });
4183
+ });
4184
+ };
4120
4185
  return SlickDropListDirective;
4121
4186
  }());
4122
4187
  SlickDropListDirective.decorators = [
@@ -4129,7 +4194,9 @@
4129
4194
  { type: core.ElementRef }
4130
4195
  ]; };
4131
4196
  SlickDropListDirective.propDecorators = {
4132
- onSlickDropListReorder: [{ type: core.Output, args: ["onSlickDropListReorder",] }]
4197
+ onSlickDropListReorder: [{ type: core.Output, args: ["onSlickDropListReorder",] }],
4198
+ onSlickDropListEnter: [{ type: core.Output, args: ["onSlickDropListEnter",] }],
4199
+ onSlickDropListLeave: [{ type: core.Output, args: ["onSlickDropListLeave",] }]
4133
4200
  };
4134
4201
 
4135
4202
  var SlickDropListItemDirective = /** @class */ (function () {
@@ -9751,18 +9818,18 @@
9751
9818
  exports.ɵa = SlickContainerHeaderComponent;
9752
9819
  exports.ɵb = SlickContainerBodyComponent;
9753
9820
  exports.ɵc = SlickContainerFooterComponent;
9754
- exports.ɵd = SlickGridColumnTemplateDirective;
9755
- exports.ɵe = SlickPagingComponent;
9756
- exports.ɵf = SlickFunctionLockService;
9757
- exports.ɵg = SlickCardComponent;
9758
- exports.ɵh = SlickCardHeaderComponent;
9759
- exports.ɵi = SlickDialogService;
9760
- exports.ɵj = SlickDialogFooterComponent;
9761
- exports.ɵk = SlickDragDropDirective;
9762
- exports.ɵl = SlickDraggableDirective;
9763
- exports.ɵm = SlickDropDownService;
9764
- exports.ɵn = SlickLogService;
9765
- exports.ɵo = SlickDropListDirective;
9821
+ exports.ɵd = SlickDropListDirective;
9822
+ exports.ɵe = SlickGridColumnTemplateDirective;
9823
+ exports.ɵf = SlickPagingComponent;
9824
+ exports.ɵg = SlickFunctionLockService;
9825
+ exports.ɵh = SlickCardComponent;
9826
+ exports.ɵi = SlickCardHeaderComponent;
9827
+ exports.ɵj = SlickDialogService;
9828
+ exports.ɵk = SlickDialogFooterComponent;
9829
+ exports.ɵl = SlickDragDropDirective;
9830
+ exports.ɵm = SlickDraggableDirective;
9831
+ exports.ɵn = SlickDropDownService;
9832
+ exports.ɵo = SlickLogService;
9766
9833
  exports.ɵp = SlickDropListItemDirective;
9767
9834
  exports.ɵq = SlickDropListGrabDirective;
9768
9835
  exports.ɵr = SlickFileListItemComponent;