<commit_before>define(
  'ephox.alloy.spec.ModalDialogSpec',

  [
    'ephox.alloy.behaviour.Behaviour',
    'ephox.alloy.dom.DomModification',
    'ephox.alloy.spec.SpecSchema',
    'ephox.alloy.spec.UiSubstitutes',
    'ephox.boulder.api.FieldPresence',
    'ephox.boulder.api.FieldSchema',
    'ephox.boulder.api.ValueSchema',
    'ephox.highway.Merger',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option',
    'ephox.sugar.api.SelectorFind',
    'ephox.sugar.api.Traverse'
  ],

  function (Behaviour, DomModification, SpecSchema, UiSubstitutes, FieldPresence, FieldSchema, ValueSchema, Merger, Fun, Option, SelectorFind, Traverse) {
    var schema = [
      FieldSchema.strict('dom'),
      FieldSchema.strict('onEscape'),
      FieldSchema.strict('sink'),
      FieldSchema.defaulted('draggable', false)
    ];

    var make = function (spec) {
      var detail = SpecSchema.asStructOrDie('modal-dialog', schema, spec, [
        'title',
        'close',
        'draghandle',
        'body',
        'footer'
      ]);

      var extra = detail.draggable() ? {
        '<alloy.dialog.draghandle>': UiSubstitutes.single(
          Merger.deepMerge(
            detail.parts().draghandle(),
            detail.parts().draghandle().base,
            {
              uid: detail.partUids().draghandle,
              dragging: {
                mode: 'mouse',
                getTarget: function (handle) {
                  return SelectorFind.ancestor(handle, '[role="dialog"]').getOr(handle);
                }
              }
            }
          )
        )
      } : { };

      var placeholders = Merger.deepMerge(
        {
          '<alloy.dialog.title>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().title(),
              detail.parts().title().base,
              {
                uid: detail.partUids().title
              }
            )
          ),
          '<alloy.dialog.close>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().close(),
              detail.parts().close().base,
              {
                uid: detail.partUids().close
              }
            )
          ),
          '<alloy.dialog.body>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().body(),
              detail.parts().body().base,
              {
                uid: detail.partUids().body
              }
            )
          ),
          '<alloy.dialog.footer>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().footer(),
              detail.parts().footer().base,
              {
                uid: detail.partUids().footer
              }
            )
          )
        },
        extra
      );

      var components = UiSubstitutes.substitutePlaces(
        Option.some('modal-dialog'),
        detail,
        detail.components(),
        placeholders,
        { }
      );

      return Merger.deepMerge(
        spec,
        {
          uiType: 'custom',
          dom: detail.dom(),
          components: components,
          keying: {
            mode: 'cyclic',
            onEscape: detail.onEscape()
          },
          behaviours: [
            Behaviour.contract({
              name: Fun.constant('modal-dialog-spec'),
              exhibit: Fun.constant(DomModification.nu({})),
              handlers: Fun.constant({ }),
              apis: function () {
                return {
                  showDialog: function (dialog) {
                    var blocker = detail.sink().getSystem().build({
                      uiType: 'custom',
                      dom: {
                        tag: 'div',
                        styles: {
                          'position': 'fixed',
                          'left': '0px',
                          'top': '0px',
                          'right': '0px',
                          'bottom': '0px',
                          'background-color': 'rgba(20,20,20,0.5)',
                          'z-index': '100000000'
                        },
                        // FIX: Remove hard-coding
                        classes: [ 'ephox-gel-centered-dialog', 'ephox-gel-modal' ]
                      },
                      components: [
                        { built: dialog }
                      ]
                    });
                    detail.sink().getSystem().addToWorld(blocker);
                    detail.sink().apis().addContainer(blocker);
                    dialog.apis().focusIn();
                  },
                  hideDialog: function (dialog) {
                    console.log('hiding dialog');
                    Traverse.parent(dialog.element()).each(function (parent) {
                      dialog.getSystem().getByDom(parent).each(function (blocker) {
                        detail.sink().apis().removeContainer(blocker);
                        detail.sink().getSystem().removeFromWorld(blocker);
                      });
                    });
                  }
                };
              },
              schema: Fun.constant(FieldSchema.field('_', '_', FieldPresence.asOption(), ValueSchema.anyValue()))
            })
<commit_msg>VAN-44-wheel-hackery: modal dialog getBody<commit_after>define(
  'ephox.alloy.spec.ModalDialogSpec',

  [
    'ephox.alloy.behaviour.Behaviour',
    'ephox.alloy.dom.DomModification',
    'ephox.alloy.spec.SpecSchema',
    'ephox.alloy.spec.UiSubstitutes',
    'ephox.boulder.api.FieldPresence',
    'ephox.boulder.api.FieldSchema',
    'ephox.boulder.api.ValueSchema',
    'ephox.highway.Merger',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option',
    'ephox.sugar.api.SelectorFind',
    'ephox.sugar.api.Traverse'
  ],

  function (Behaviour, DomModification, SpecSchema, UiSubstitutes, FieldPresence, FieldSchema, ValueSchema, Merger, Fun, Option, SelectorFind, Traverse) {
    var schema = [
      FieldSchema.strict('dom'),
      FieldSchema.strict('onEscape'),
      FieldSchema.strict('sink'),
      FieldSchema.defaulted('draggable', false)
    ];

    var make = function (spec) {
      var detail = SpecSchema.asStructOrDie('modal-dialog', schema, spec, [
        'title',
        'close',
        'draghandle',
        'body',
        'footer'
      ]);

      var extra = detail.draggable() ? {
        '<alloy.dialog.draghandle>': UiSubstitutes.single(
          Merger.deepMerge(
            detail.parts().draghandle(),
            detail.parts().draghandle().base,
            {
              uid: detail.partUids().draghandle,
              dragging: {
                mode: 'mouse',
                getTarget: function (handle) {
                  return SelectorFind.ancestor(handle, '[role="dialog"]').getOr(handle);
                }
              }
            }
          )
        )
      } : { };

      var placeholders = Merger.deepMerge(
        {
          '<alloy.dialog.title>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().title(),
              detail.parts().title().base,
              {
                uid: detail.partUids().title
              }
            )
          ),
          '<alloy.dialog.close>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().close(),
              detail.parts().close().base,
              {
                uid: detail.partUids().close
              }
            )
          ),
          '<alloy.dialog.body>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().body(),
              detail.parts().body().base,
              {
                uid: detail.partUids().body
              }
            )
          ),
          '<alloy.dialog.footer>': UiSubstitutes.single(
            Merger.deepMerge(
              detail.parts().footer(),
              detail.parts().footer().base,
              {
                uid: detail.partUids().footer
              }
            )
          )
        },
        extra
      );

      var components = UiSubstitutes.substitutePlaces(
        Option.some('modal-dialog'),
        detail,
        detail.components(),
        placeholders,
        { }
      );

      return Merger.deepMerge(
        spec,
        {
          uiType: 'custom',
          dom: detail.dom(),
          components: components,
          keying: {
            mode: 'cyclic',
            onEscape: detail.onEscape()
          },
          behaviours: [
            Behaviour.contract({
              name: Fun.constant('modal-dialog-spec'),
              exhibit: Fun.constant(DomModification.nu({})),
              handlers: Fun.constant({ }),
              apis: function () {
                return {
                  showDialog: function (dialog) {
                    var blocker = detail.sink().getSystem().build({
                      uiType: 'custom',
                      dom: {
                        tag: 'div',
                        styles: {
                          'position': 'fixed',
                          'left': '0px',
                          'top': '0px',
                          'right': '0px',
                          'bottom': '0px',
                          'background-color': 'rgba(20,20,20,0.5)',
                          'z-index': '100000000'
                        },
                        // FIX: Remove hard-coding
                        classes: [ 'ephox-gel-centered-dialog', 'ephox-gel-modal' ]
                      },
                      components: [
                        { built: dialog }
                      ]
                    });
                    detail.sink().getSystem().addToWorld(blocker);
                    detail.sink().apis().addContainer(blocker);
                    dialog.apis().focusIn();
                  },
                  hideDialog: function (dialog) {
                    console.log('hiding dialog');
                    Traverse.parent(dialog.element()).each(function (parent) {
                      dialog.getSystem().getByDom(parent).each(function (blocker) {
                        detail.sink().apis().removeContainer(blocker);
                        detail.sink().getSystem().removeFromWorld(blocker);
                      });
                    });
                  },
                  getBody: function (dialog) {
                    return dialog.getSystem().getByUid(detail.partUids().body);
                  }
                };
              },
              schema: Fun.constant(FieldSchema.field('_', '_', FieldPresence.asOption(), ValueSchema.anyValue()))
            })

{'fraction_non_alphanumeric': 0.13045939062352607, 'fraction_numerical': 0.004150551834732573, 'mean_word_length': 1.2357654997891185, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5135947', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2774, 'n_words': 376}