You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

83 lines
2.5 KiB

  1. "use strict";
  2. exports.__esModule = true;
  3. exports.isSelected = isSelected;
  4. exports.slotWidth = slotWidth;
  5. exports.getSlotAtX = getSlotAtX;
  6. exports.pointInBox = pointInBox;
  7. exports.dateCellSelection = dateCellSelection;
  8. function isSelected(event, selected) {
  9. if (!event || selected == null) return false;
  10. return [].concat(selected).indexOf(event) !== -1;
  11. }
  12. function slotWidth(rowBox, slots) {
  13. var rowWidth = rowBox.right - rowBox.left;
  14. var cellWidth = rowWidth / slots;
  15. return cellWidth;
  16. }
  17. function getSlotAtX(rowBox, x, rtl, slots) {
  18. var cellWidth = slotWidth(rowBox, slots);
  19. return rtl ? slots - 1 - Math.floor((x - rowBox.left) / cellWidth) : Math.floor((x - rowBox.left) / cellWidth);
  20. }
  21. function pointInBox(box, _ref) {
  22. var x = _ref.x,
  23. y = _ref.y;
  24. return y >= box.top && y <= box.bottom && x >= box.left && x <= box.right;
  25. }
  26. function dateCellSelection(start, rowBox, box, slots, rtl) {
  27. var startIdx = -1;
  28. var endIdx = -1;
  29. var lastSlotIdx = slots - 1;
  30. var cellWidth = slotWidth(rowBox, slots); // cell under the mouse
  31. var currentSlot = getSlotAtX(rowBox, box.x, rtl, slots); // Identify row as either the initial row
  32. // or the row under the current mouse point
  33. var isCurrentRow = rowBox.top < box.y && rowBox.bottom > box.y;
  34. var isStartRow = rowBox.top < start.y && rowBox.bottom > start.y; // this row's position relative to the start point
  35. var isAboveStart = start.y > rowBox.bottom;
  36. var isBelowStart = rowBox.top > start.y;
  37. var isBetween = box.top < rowBox.top && box.bottom > rowBox.bottom; // this row is between the current and start rows, so entirely selected
  38. if (isBetween) {
  39. startIdx = 0;
  40. endIdx = lastSlotIdx;
  41. }
  42. if (isCurrentRow) {
  43. if (isBelowStart) {
  44. startIdx = 0;
  45. endIdx = currentSlot;
  46. } else if (isAboveStart) {
  47. startIdx = currentSlot;
  48. endIdx = lastSlotIdx;
  49. }
  50. }
  51. if (isStartRow) {
  52. // select the cell under the initial point
  53. startIdx = endIdx = rtl ? lastSlotIdx - Math.floor((start.x - rowBox.left) / cellWidth) : Math.floor((start.x - rowBox.left) / cellWidth);
  54. if (isCurrentRow) {
  55. if (currentSlot < startIdx) startIdx = currentSlot;else endIdx = currentSlot; //select current range
  56. } else if (start.y < box.y) {
  57. // the current row is below start row
  58. // select cells to the right of the start cell
  59. endIdx = lastSlotIdx;
  60. } else {
  61. // select cells to the left of the start cell
  62. startIdx = 0;
  63. }
  64. }
  65. return {
  66. startIdx: startIdx,
  67. endIdx: endIdx
  68. };
  69. }