<commit_before>const default_order = [
  {id: 1, w:1, h:1, col:1, row:1},
  {id: 2, w:1, h:1, col:2, row:1},
  {id: 3, w:2, h:2, col:3, row:1},
  {id: 4, w:1, h:1, col:5, row:1},
  {id: 5, w:1, h:1, col:6, row:1},

  {id: 11, w:1, h:1, col:1, row:2},
  {id: 12, w:1, h:1, col:2, row:2},
  {id: 13, w:1, h:1, col:5, row:2},
  {id: 14, w:1, h:1, col:6, row:2},

  {id: 21, w:1, h:1, col:1, row:3},
  {id: 22, w:1, h:1, col:2, row:3},
  // {id: 23, w:1, h:1, col:3, row:3},
]

class Sortable{
  constructor(step_x, step_y, delta, sortable_mode, order){
    order = order ? order : default_order
    this.state = {
      sortable_mode: sortable_mode ? sortable_mode: "default", // default, left_right
      size_mode: "default", // default, stick
      delta: delta ? delta: 5,
      step_x: step_x ? step_x: 90,
      step_y: step_y ? step_y: 90,
      mouseX: 0,
      mouseY: 0,
      lastPress: null,
      isPressed: false,
      currentRow:null,
      currentCol:null,
      order: order,
      init_size: this.get_init_size(order)
    };
  }

  get_init_size(order){
    let result = {}
    const copy_order = Object.assign([], order);
    copy_order.forEach((value, key) => {
      if(value.h > 1 || value.w > 1){
        result[`${value.row}_${value.col}`] = {w: value.w, h: value.h};
      }
    })
    console.log("get_init_size::", result)
    return result
  }

  clamp(n, min, max) {
    return Math.max(Math.min(n, max), min);
  }

  get_state(){
    // let temp = this.state
    let res_order = []
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key) => {
      let ttm = value
      ttm.width = ttm.w * copy.step_x + (ttm.w-1)*copy.delta
      ttm.height = ttm.h * copy.step_y + (ttm.h-1)*copy.delta
      ttm.y = ttm.row * (copy.step_y + copy.delta)
      ttm.x = ttm.col * (copy.step_x + copy.delta)
      res_order.push(ttm)
    })
    copy.order = res_order
    return copy
  }

  get_right_column_without_cur(row){
    let max_column = 0;
    const {lastPress} = this.state;
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key_y) => {
      if(row === value.row ){
        if(value.col >= max_column){
          if(lastPress.id !== value.id){
            max_column = value.col
          }
        }
      }
    })
    return max_column
  }

  get_right_column(row){
    let max_column = 0;
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key_y) => {
      if(row === value.row ){
        if(value.col >= max_column){
          max_column = value.col
        }
      }
    })
    return max_column
  }

  get_right_column_average(row){
    let max_column = 0;
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key_y) => {
      if(row >= value.row ){
        if(value.col >= max_column){
          max_column = value.col
        }
      }
    })
    return max_column
  }

  move_item_right(item, width){
    console.log("move_item_right", item, ">>>", width)
    this.state.order.forEach((value, key) => {
      if(item.id === value.id){
        if(this.state.sortable_mode === "left_right"){
          const max_column = this.get_right_column(value.row)
          if(max_column === value.col){
            value.col = 1
            value.row += 1
          }else{
            value.col += width
          }
          value.w = 1
          value.h = 1
        }else{
          value.col += width
        }
      }
    })
  }

  move_item_left(item, width){
    console.log("move_item_right", item, ">>>", width)
    this.state.order.forEach((value, key) => {
      if(item.id === value.id){
        if(this.state.sortable_mode === "left_right"){
          if(value.col === 1){
            value.row -= 1
            value.col = (this.get_right_column_without_cur(value.row) + 1)
          }else{
            value.col -= width
          }
          value.w = 1
          value.h = 1
        }else{
          value.col -= width
        }
      }
    })
  }

  move_item_bottom(item, width){
    console.log("move_item_bottom", item, "-----", width)<commit_msg>continue work with big size items<commit_after>const default_order = [
  {id: 1, w:1, h:1, col:1, row:1},
  {id: 2, w:1, h:1, col:2, row:1},
  {id: 3, w:2, h:2, col:3, row:1},
  {id: 4, w:1, h:1, col:5, row:1},
  {id: 5, w:1, h:1, col:6, row:1},

  {id: 11, w:1, h:1, col:1, row:2},
  {id: 12, w:1, h:1, col:2, row:2},
  {id: 13, w:1, h:1, col:5, row:2},
  {id: 14, w:1, h:1, col:6, row:2},

  {id: 21, w:1, h:1, col:1, row:3},
  {id: 22, w:1, h:1, col:2, row:3},
  // {id: 23, w:1, h:1, col:3, row:3},
]

class Sortable{
  constructor(step_x, step_y, delta, sortable_mode, order){
    order = order ? order : default_order
    this.state = {
      sortable_mode: sortable_mode ? sortable_mode: "default", // default, left_right
      size_mode: "default", // default, stick
      delta: delta ? delta: 5,
      step_x: step_x ? step_x: 90,
      step_y: step_y ? step_y: 90,
      mouseX: 0,
      mouseY: 0,
      lastPress: null,
      isPressed: false,
      currentRow:null,
      currentCol:null,
      order: order,
      init_size: this.get_init_size(order)
    };
  }

  get_init_size(order){
    let result = {}
    const copy_order = Object.assign([], order);
    copy_order.forEach((value, key) => {
      if(value.h > 1 || value.w > 1){
        result[`${value.row}_${value.col}`] = {w: value.w, h: value.h};
      }
    })
    console.log("get_init_size::", result)
    return result
  }

  clamp(n, min, max) {
    return Math.max(Math.min(n, max), min);
  }

  get_state(){
    // let temp = this.state
    let res_order = []
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key) => {
      let ttm = value
      ttm.width = ttm.w * copy.step_x + (ttm.w-1)*copy.delta
      ttm.height = ttm.h * copy.step_y + (ttm.h-1)*copy.delta
      ttm.y = ttm.row * (copy.step_y + copy.delta)
      ttm.x = ttm.col * (copy.step_x + copy.delta)
      res_order.push(ttm)
    })
    copy.order = res_order
    return copy
  }

  get_right_column_without_cur(row){
    let max_column = 0;
    const {lastPress} = this.state;
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key_y) => {
      if(row === value.row ){
        if(value.col >= max_column){
          if(lastPress.id !== value.id){
            max_column = value.col
          }
        }
      }
    })
    return max_column
  }

  get_right_column(row){
    let max_column = 0;
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key_y) => {
      if(row === value.row ){
        if(value.col >= max_column){
          max_column = value.col
        }
      }
    })
    return max_column
  }

  get_right_column_average(row){
    let max_column = 0;
    let copy = Object.assign({}, this.state);
    copy.order.forEach((value, key_y) => {
      if(row >= value.row ){
        if(value.col >= max_column){
          max_column = value.col
        }
      }
    })
    return max_column
  }

  move_item_right(item, width){
    console.log("move_item_right", item, ">>>", width)
    this.state.order.forEach((value, key) => {
      if(item.id === value.id){
        if(this.state.sortable_mode === "left_right"){
          const max_column = this.get_right_column(value.row)
          if(max_column === value.col){
            value.col = 1
            value.row += 1
          }else{
            value.col += width
          }
          value.w = 1
          value.h = 1
        }else{
          value.col += width
        }
      }
    })
  }

  move_item_left(item, width){
    console.log("move_item_right", item, ">>>", width)
    this.state.order.forEach((value, key) => {
      if(item.id === value.id){
        if(this.state.sortable_mode === "left_right"){
          if(value.col === 1){
            value.row -= 1
            value.col = (this.get_right_column_without_cur(value.row) + 1)
          }else{
            value.col -= width
          }
          value.w = 1
          value.h = 1
          let size, is_not_move;
          if(this.state.init_size[`${value.row}_${value.col-1}`]){
            size = this.state.init_size[`${value.row}_${value.col-1}`]
            is_not_move = false
          }
          if(this.state.init_size[`${value.row}_${value.col}`]){
            size = this.state.init_size[`${value.row}_${value.col}`]
            is_not_move = true
          }
          if(size){
            value.h = size.h
            value.w = size.w
            value.width = value.w * this.state.step_x + (value.w-1)*this.state.delta
            value.height = value.h * this.state.step_y + (value.h-1)*this.state.delta
            if(!is_not_move){
              this.move_item_left(value, 1)
            }
          }
        }else{
          value.col -= width
        }
      }
    })
  }

  move_item_bottom(item, width){
    console.log("move_item_bottom", item, "-----", width)
{'fraction_non_alphanumeric': 0.16981553940749022, 'fraction_numerical': 0.02068194522079374, 'mean_word_length': 2.02638700947226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3659126', 'n_tokens_mistral': 3444, 'n_tokens_neox': 3339, 'n_words': 651}