<commit_before>define(
  'ephox.alloy.api.ui.FormCoupledInputs',

  [
    'ephox.alloy.api.behaviour.Composing',
    'ephox.alloy.api.behaviour.Toggling',
    'ephox.alloy.api.ui.Button',
    'ephox.alloy.api.ui.CompositeBuilder',
    'ephox.alloy.api.ui.FormField',
    'ephox.alloy.api.ui.Input',
    'ephox.alloy.construct.EventHandler',
    'ephox.alloy.data.Fields',
    'ephox.alloy.parts.PartType',
    'ephox.boulder.api.FieldSchema',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option'
  ],

  function (Composing, Toggling, Button, CompositeBuilder, FormField, Input, EventHandler, Fields, PartType, FieldSchema, Fun, Option) {
    var schema = [
      FieldSchema.strict('onLockedChange'),
      Fields.markers([ 'lockClass' ])
    ];

    var formInput = {
      build: function (spec) {
        return FormField.build(Input, spec);
      }
    };

    var getPart = function (comp, detail, partName) {
      return comp.getSystem().getByUid(detail.partUids()[partName]).fold(Option.none, Option.some);
    };

    var getField = function (comp, detail, partName) {
      return getPart(comp, detail, partName).bind(Composing.getCurrent);
    };

    var partTypes = [
      PartType.internal(
        formInput,
        'field1',
        '<alloy.coupled-inputs.field1>',
        Fun.constant({ }),
        function (detail) {
          return {
            events: {
              'input': EventHandler.nu({
                run: function (field1) {
                  getField(field1, detail, 'field2').each(function (field2) {
                    getPart(field1, detail, 'lock').each(function (lock) {
                      if (Toggling.isSelected(lock)) detail.onLockedChange()(field1, field1, field2, lock);
                    });
                  });
                }
              })
            }
          };
        }
      ),

      // FIX: Dupe
      PartType.internal(
        formInput,
        'field2',
        '<alloy.coupled-inputs.field2>',
        Fun.constant({ }),
        function (detail) {
          return {
            events: {
              'input': EventHandler.nu({
                run: function (field2) {
                  getField(field2, detail, 'field1').each(function (field1) {
                    getPart(field2, detail, 'lock').each(function (lock) {
                      if (Toggling.isSelected(lock)) detail.onLockedChange()(field1, field2, field1, lock);
                    });
                  });
                }
              })
            }
          };
        }
      ),

      PartType.internal(
        Button,
        'lock',
        '<alloy.coupled-inputs.lock>',
        Fun.constant({ }),
        function (detail) {
          return {
            behaviours: {
              toggling: {
                toggleClass: detail.markers().lockClass()
              }
            }
          };
        }
      )
    ];

    /*
         '<alloy.form.lock>': UiSubstitutes.single(true,  
          Merger.deepMerge(
            info.parts().lock(),
            {
              uid: info.partUids().lock,
              toggling: {
                toggleClass: info.markers().lockClass()
              }
            }
          )
        )
        */

    var build = function (f) {
      return CompositeBuilder.build('coupled-inputs', schema, partTypes, make, f);
    };

    var make = function (detail, components, spec, externals) { 
      return {
        uiType: 'custom',
        uid: detail.uid(),
        dom: detail.dom(),
        components: components
      };
    };

    var parts = PartType.generate('coupled-inputs', partTypes);

    return {
      build: build,
      parts: Fun.constant(parts)
    };
  }
);<commit_msg>VAN-44-wheel-hackery-apis-2: FormCoupledInputs Uibuilder<commit_after>define(
  'ephox.alloy.api.ui.FormCoupledInputs',

  [
    'ephox.alloy.api.behaviour.Composing',
    'ephox.alloy.api.behaviour.Toggling',
    'ephox.alloy.api.ui.Button',
    'ephox.alloy.api.ui.FormField',
    'ephox.alloy.api.ui.Input',
    'ephox.alloy.api.ui.UiBuilder',
    'ephox.alloy.construct.EventHandler',
    'ephox.alloy.data.Fields',
    'ephox.alloy.parts.PartType',
    'ephox.boulder.api.FieldSchema',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option'
  ],

  function (Composing, Toggling, Button, FormField, Input, UiBuilder, EventHandler, Fields, PartType, FieldSchema, Fun, Option) {
    var schema = [
      FieldSchema.strict('onLockedChange'),
      Fields.markers([ 'lockClass' ])
    ];

    var formInput = {
      build: function (spec) {
        return FormField.build(Input, spec);
      }
    };

    var getPart = function (comp, detail, partName) {
      return comp.getSystem().getByUid(detail.partUids()[partName]).fold(Option.none, Option.some);
    };

    var getField = function (comp, detail, partName) {
      return getPart(comp, detail, partName).bind(Composing.getCurrent);
    };

    var partTypes = [
      PartType.internal(
        formInput,
        'field1',
        '<alloy.coupled-inputs.field1>',
        Fun.constant({ }),
        function (detail) {
          return {
            events: {
              'input': EventHandler.nu({
                run: function (field1) {
                  getField(field1, detail, 'field2').each(function (field2) {
                    getPart(field1, detail, 'lock').each(function (lock) {
                      if (Toggling.isSelected(lock)) detail.onLockedChange()(field1, field1, field2, lock);
                    });
                  });
                }
              })
            }
          };
        }
      ),

      // FIX: Dupe
      PartType.internal(
        formInput,
        'field2',
        '<alloy.coupled-inputs.field2>',
        Fun.constant({ }),
        function (detail) {
          return {
            events: {
              'input': EventHandler.nu({
                run: function (field2) {
                  getField(field2, detail, 'field1').each(function (field1) {
                    getPart(field2, detail, 'lock').each(function (lock) {
                      if (Toggling.isSelected(lock)) detail.onLockedChange()(field1, field2, field1, lock);
                    });
                  });
                }
              })
            }
          };
        }
      ),

      PartType.internal(
        Button,
        'lock',
        '<alloy.coupled-inputs.lock>',
        Fun.constant({ }),
        function (detail) {
          return {
            behaviours: {
              toggling: {
                toggleClass: detail.markers().lockClass()
              }
            }
          };
        }
      )
    ];

    var build = function (spec) {
      return UiBuilder.composite('coupled-inputs', schema, partTypes, make, spec);
    };

    var make = function (detail, components, spec, externals) { 
      return {
        uiType: 'custom',
        uid: detail.uid(),
        dom: detail.dom(),
        components: components
      };
    };

    var parts = PartType.generate('coupled-inputs', partTypes);

    return {
      build: build,
      parts: Fun.constant(parts)
    };
  }
);
{'fraction_non_alphanumeric': 0.13745075970737197, 'fraction_numerical': 0.006049521665728756, 'mean_word_length': 1.6417688591601636, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '249940', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2145, 'n_words': 343}