{"size": 1190, "ext": "js", "max_stars_repo_path": "src/DraggableAreasGroup.js", "max_stars_repo_name": "manutero/react-draggable-tags", "max_stars_repo_stars_event_min_datetime": "2018-05-27T17:14:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T09:27:58.000Z", "max_issues_repo_path": "src/DraggableAreasGroup.js", "max_issues_repo_name": "chenYvv/react-draggable-tags", "max_issues_repo_issues_event_min_datetime": "2018-06-26T15:09:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T03:58:34.000Z", "max_forks_repo_path": "src/DraggableAreasGroup.js", "max_forks_repo_name": "chenYvv/react-draggable-tags", "max_forks_repo_forks_event_min_datetime": "2018-05-29T03:14:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T06:31:44.000Z"}
{"max_stars_count": 292, "max_issues_count": 77, "max_forks_count": 89, "avg_line_length": 25.3191489362, "max_line_length": 83, "alphanum_fraction": 0.5134453782}
import React from 'react';
import { fromJS, List, is } from 'immutable';
import buildDraggableArea from './DraggableAreaBuilder';



export default class DraggableTagsGroup {
  constructor() {
    this.isInAreas = [];
  }

  addArea(areaId) {
    return buildDraggableArea({
      isInAnotherArea: (tagRect, tag, shouldAdd = true) => {
        let x = tagRect.left + tagRect.width / 2;
        let y = tagRect.top + tagRect.height / 2;

        let result = {isIn: false};
        this.isInAreas.forEach(isInArea => {
          const r = isInArea({tag, x, y, areaId}, shouldAdd);
          if (r.isIn) {
            result = r;
          }
        });

        return result
      },
      passAddFunc: (ele, addTag) => {
        this.isInAreas.push(function({tag, x, y, areaId: fromAreaId}, shouldAdd) {

          const rect = ele.getBoundingClientRect();
          if (x > rect.left && x < rect.right && y > rect.top && y < rect.bottom) {
            shouldAdd && addTag({tag, fromAreaId, x, y});
            return {
              isIn: true,
              id: areaId
            };
          }

          return {
            isIn: false,
          };
        });
      }
    });
  }
}