<commit_before>/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.u2.view',
  name: 'RichChoiceView',
  extends: 'foam.u2.View',

  documentation: `
    This is similar to foam.u2.view.ChoiceView, but lets you provide views for
    the selection and options instead of strings. This allows you to create
    dropdowns with rich content like images and formatting using CSS.

    Example usage for a Reference property on a model:

      {
        class: 'Reference',
        of: 'foam.nanos.auth.User',
        name: 'exampleProperty',
        view: function(_, X) {
          return {
            class: 'foam.u2.view.RichChoiceView',
            selectionView: { class: 'a.b.c.MyCustomSelectionView' }, // Optional
            rowView: { class: 'a.b.c.MyCustomCitationView' }, // Optional
            sections: [
              {
                heading: 'Users',
                dao: X.userDAO.orderBy(foam.nanos.auth.User.LEGAL_NAME)
              },
              // Set "disabled: true" to render each object as non-selectable row
              // Set hideIfEmpty: true" to hide headers if not objects are present in dao provided.
              {
                disabled: true,
                heading: 'Disabled users',
                hideIfEmpty: true,
                dao: X.userDAO.where(this.EQ(foam.nanos.auth.User.STATUS, this.AccountStatus.DISABLED)),
              },
            ]
          };
        }
      }
  `,

  implements: [
    'foam.mlang.Expressions'
  ],

  exports: [
    'of'
  ],

  css: `
    ^ {
      position: relative;
      display: inline-block;
    }

    ^container {
      position: absolute;
      top: 18px;
      left: 0;
      background: white;
      border: 1px solid #bdbdbd;
      max-height: 378px;
      overflow-y: scroll;
      box-sizing: border-box;
      width: 100%;
      min-width: fit-content;
      -webkit-appearance: textfield;
    }

    ^heading {
      border-bottom: 1px solid #f4f4f9;
      font-size: 12px;
      font-weight: 900;
      padding: 1px 2px;
    }

    ^selection-view {
      background-color: white;
      display: inline-flex;
      align-items: center;
      justify-content: space-between;
      font-size: 11px;
      box-sizing: border-box;
      -webkit-appearance: textfield;
      padding: 1px 2px;
      cursor: default;<commit_msg>Properly position dropdown below RichChoiceView<commit_after>/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.u2.view',
  name: 'RichChoiceView',
  extends: 'foam.u2.View',

  documentation: `
    This is similar to foam.u2.view.ChoiceView, but lets you provide views for
    the selection and options instead of strings. This allows you to create
    dropdowns with rich content like images and formatting using CSS.

    Example usage for a Reference property on a model:

      {
        class: 'Reference',
        of: 'foam.nanos.auth.User',
        name: 'exampleProperty',
        view: function(_, X) {
          return {
            class: 'foam.u2.view.RichChoiceView',
            selectionView: { class: 'a.b.c.MyCustomSelectionView' }, // Optional
            rowView: { class: 'a.b.c.MyCustomCitationView' }, // Optional
            sections: [
              {
                heading: 'Users',
                dao: X.userDAO.orderBy(foam.nanos.auth.User.LEGAL_NAME)
              },
              // Set "disabled: true" to render each object as non-selectable row
              // Set hideIfEmpty: true" to hide headers if not objects are present in dao provided.
              {
                disabled: true,
                heading: 'Disabled users',
                hideIfEmpty: true,
                dao: X.userDAO.where(this.EQ(foam.nanos.auth.User.STATUS, this.AccountStatus.DISABLED)),
              },
            ]
          };
        }
      }
  `,

  implements: [
    'foam.mlang.Expressions'
  ],

  exports: [
    'of'
  ],

  css: `
    ^ {
      position: relative;
      display: inline-block;
    }

    ^container {
      position: absolute;
      bottom: 0;
      left: 0;
      transform: translateY(100%);
      background: white;
      border: 1px solid #bdbdbd;
      max-height: 378px;
      overflow-y: scroll;
      box-sizing: border-box;
      width: 100%;
      min-width: fit-content;
      -webkit-appearance: textfield;
    }

    ^heading {
      border-bottom: 1px solid #f4f4f9;
      font-size: 12px;
      font-weight: 900;
      padding: 1px 2px;
    }

    ^selection-view {
      background-color: white;
      display: inline-flex;
      align-items: center;
      justify-content: space-between;
      font-size: 11px;
      box-sizing: border-box;
      -webkit-appearance: textfield;
      padding: 1px 2px;
      cursor: default;
{'fraction_non_alphanumeric': 0.11138161898965307, 'fraction_numerical': 0.014607425441265977, 'mean_word_length': 1.8382268278641336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6182399', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1487, 'n_words': 377}