<commit_before>/**
  * Copyright (C) 2017 Orbeon, Inc.
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the
  * GNU Lesser General Public License as published by the Free Software Foundation; either version
  *  2.1 of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU Lesser General Public License for more details.
  *
  * The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
  */
package org.orbeon.xbl

import org.scalajs.jquery.JQueryPromise

import scala.scalajs.js

@js.native
trait Fancytree extends js.Object {
  val activeNode: FancytreeNode = js.native
  def activateKey(key: String): FancytreeNode = js.native
  def reload(source: js.Object): JQueryPromise = js.native
}

@js.native
trait FancytreeNode extends js.Object {
  val key: String = js.native
}

@js.native
trait FancytreeJsonNode extends js.Object {
  val title        : String                                  = js.native
  val key          : String                                  = js.native
  val folder       : js.UndefOr[Boolean]                     = js.native
  val children     : js.UndefOr[js.Array[FancytreeJsonNode]] = js.native
  val expanded     : js.UndefOr[Boolean]                     = js.native
  val extraClasses : js.UndefOr[String]                      = js.native
}

@js.native
trait FancytreeEventData extends js.Object {
  val tree: Fancytree                = js.native
  val node: FancytreeJsonNode        = js.native
  val targetType: js.UndefOr[String] = js.native
}

object FancytreeJsonNode {
  def apply(
    label           : String,
    value           : String,
    open            : Boolean,
    classesOrUndef  : js.UndefOr[String]                      = js.undefined,
    childrenOrUndef : js.UndefOr[js.Array[FancytreeJsonNode]] = js.undefined
  ): FancytreeJsonNode = {

    val result = (new js.Object).asInstanceOf[js.Dynamic]

    // https://github.com/mar10/fancytree/wiki/TutorialLoadData
    // "expanded, extraClasses, folder, hideCheckbox, key, lazy, selected, title, tooltip, unselectable"

    result.title = label
    result.key   = value

    childrenOrUndef foreach { children ⇒
      result.folder   = true
      result.children = children
    }

    if (open)
      result.expanded = true

    classesOrUndef foreach { classes ⇒
      result.extraClasses = classes
    }

    result.asInstanceOf[FancytreeJsonNode]
  }
}<commit_msg>Indent<commit_after>/**
  * Copyright (C) 2017 Orbeon, Inc.
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the
  * GNU Lesser General Public License as published by the Free Software Foundation; either version
  *  2.1 of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU Lesser General Public License for more details.
  *
  * The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
  */
package org.orbeon.xbl

import org.scalajs.jquery.JQueryPromise

import scala.scalajs.js

@js.native
trait Fancytree extends js.Object {
  val activeNode                : FancytreeNode = js.native
  def activateKey(key: String)  : FancytreeNode = js.native
  def reload(source: js.Object) : JQueryPromise = js.native
}

@js.native
trait FancytreeNode extends js.Object {
  val key: String = js.native
}

@js.native
trait FancytreeJsonNode extends js.Object {
  val title        : String                                  = js.native
  val key          : String                                  = js.native
  val folder       : js.UndefOr[Boolean]                     = js.native
  val children     : js.UndefOr[js.Array[FancytreeJsonNode]] = js.native
  val expanded     : js.UndefOr[Boolean]                     = js.native
  val extraClasses : js.UndefOr[String]                      = js.native
}

@js.native
trait FancytreeEventData extends js.Object {
  val tree       : Fancytree          = js.native
  val node       : FancytreeJsonNode  = js.native
  val targetType : js.UndefOr[String] = js.native
}

object FancytreeJsonNode {
  def apply(
    label           : String,
    value           : String,
    open            : Boolean,
    classesOrUndef  : js.UndefOr[String]                      = js.undefined,
    childrenOrUndef : js.UndefOr[js.Array[FancytreeJsonNode]] = js.undefined
  ): FancytreeJsonNode = {

    val result = (new js.Object).asInstanceOf[js.Dynamic]

    // https://github.com/mar10/fancytree/wiki/TutorialLoadData
    // "expanded, extraClasses, folder, hideCheckbox, key, lazy, selected, title, tooltip, unselectable"

    result.title = label
    result.key   = value

    childrenOrUndef foreach { children ⇒
      result.folder   = true
      result.children = children
    }

    if (open)
      result.expanded = true

    classesOrUndef foreach { classes ⇒
      result.extraClasses = classes
    }

    result.asInstanceOf[FancytreeJsonNode]
  }
}
{'fraction_non_alphanumeric': 0.0819702951682647, 'fraction_numerical': 0.003008084226358338, 'mean_word_length': 2.4168272318561335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6080161', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1554, 'n_words': 464}