<commit_before>/**
 * @author    : <NAME>
 * @version   : 5.0.0
 * @copyright : 2019
 * @license   : MIT
 */

import { bindable, bindingMode, computedFrom, customElement, inlineView } from "aurelia-framework";
import { UIInternal } from "../utils/ui-internal";
import view from "./ui-dialog.html";

@customElement("ui-dialog")
@inlineView(view)
export class UIDialogElement {
  @bindable()
  public label = "Dialog";
  @bindable()
  public icon = "";

  @bindable()
  public width: string = "50vw";
  @bindable()
  public minWidth: string = "36rem";
  @bindable()
  public maxWidth: string = "100%";
  @bindable()
  public height: string = "50vh";
  @bindable()
  public minHeight: string = "32rem";
  @bindable()
  public maxHeight: string = "100%";

  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public help: boolean | (() => void) = false;
  @bindable({ defaultBindingMode: bindingMode.oneTime })
  public modal: boolean = false;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public closeable: boolean = true;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public maximizable: boolean = true;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public minimizable: boolean = true;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public hideToolbox: boolean = false;

  @bindable()
  public beforeclose: () => Promise<boolean> | boolean;

  public returnPromise: (arg: { result?: AnyObject; cancelled?: boolean }) => void;

  protected active: boolean = true;
  protected minimized: boolean = false;
  protected maximized: boolean = false;

  private dialogEl: Element;

  private position = {
    bottom: "auto",
    left: "0",
    right: "auto",
    top: "0"
  };

  private taskButton;
  private previousPosition;

  constructor(protected element: Element) {
    this.help = element.hasAttribute("help.trigger");
  }

  public cancel(): void {
    this.close();
  }

  public close(result?: AnyObject): void {
    UIInternal.broadcast("dlg:close", { dialog: this, result });
  }

  public minimize(): void {
    this.minimized = !this.minimized;
    this.active = !this.minimized;
    UIInternal.broadcast("dlg:minimize", { dialog: this });
  }

  public activate(): void {
    UIInternal.broadcast("dlg:activate", { dialog: this });
  }

  protected bind(): void {
    if (this.modal) {
      this.position = { bottom: "auto", left: "auto", right: "auto", top: "auto" };
    }
  }

  protected attached(): void {
    if (!this.modal) {
      const iconEl = this.element.querySelector(".ui-header__icon .ui-icon");
      const labelEl = this.element.querySelector(".ui-header__title") as HTMLElement;
      if (iconEl) {
        this.icon = iconEl.au.controller.viewModel.icon;
      }
      // if (labelEl) {
      //   this.label = labelEl.innerText;
      // }
      this.taskButton = UIInternal.compileTemplate(
        `<template><ui-button size="sm" ui-theme="primary" type.bind="active?'solid':'default'" label.bind="label" icon.bind="icon"></ui-button></template>`,
        this
      );
    }
  }

  protected startDrag($event: MouseEvent): void {
    $event.stopEvent();
    UIInternal.broadcast("dlg:drag", {
      dialog: this,
      startX: $event.x || $event.clientX,
      startY: $event.y || $event.clientY
    });
  }

  @computedFrom(
    "width",
    "minWidth",
    "maxWidth",
    "height",<commit_msg>Enable dialog drag on left click only<commit_after>/**
 * @author    : <NAME>
 * @version   : 5.0.0
 * @copyright : 2019
 * @license   : MIT
 */

import { bindable, bindingMode, computedFrom, customElement, inlineView } from "aurelia-framework";
import { UIInternal } from "../utils/ui-internal";
import view from "./ui-dialog.html";

@customElement("ui-dialog")
@inlineView(view)
export class UIDialogElement {
  @bindable()
  public label = "Dialog";
  @bindable()
  public icon = "";

  @bindable()
  public width: string = "50vw";
  @bindable()
  public minWidth: string = "36rem";
  @bindable()
  public maxWidth: string = "100%";
  @bindable()
  public height: string = "50vh";
  @bindable()
  public minHeight: string = "32rem";
  @bindable()
  public maxHeight: string = "100%";

  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public help: boolean | (() => void) = false;
  @bindable({ defaultBindingMode: bindingMode.oneTime })
  public modal: boolean = false;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public closeable: boolean = true;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public maximizable: boolean = true;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public minimizable: boolean = true;
  @bindable({ defaultBindingMode: bindingMode.oneWay })
  public hideToolbox: boolean = false;

  @bindable()
  public beforeclose: () => Promise<boolean> | boolean;

  public returnPromise: (arg: { result?: AnyObject; cancelled?: boolean }) => void;

  protected active: boolean = true;
  protected minimized: boolean = false;
  protected maximized: boolean = false;

  private dialogEl: Element;

  private position = {
    bottom: "auto",
    left: "0",
    right: "auto",
    top: "0"
  };

  private taskButton;
  private previousPosition;

  constructor(protected element: Element) {
    this.help = element.hasAttribute("help.trigger");
  }

  public cancel(): void {
    this.close();
  }

  public close(result?: AnyObject): void {
    UIInternal.broadcast("dlg:close", { dialog: this, result });
  }

  public minimize(): void {
    this.minimized = !this.minimized;
    this.active = !this.minimized;
    UIInternal.broadcast("dlg:minimize", { dialog: this });
  }

  public activate(): void {
    UIInternal.broadcast("dlg:activate", { dialog: this });
  }

  protected bind(): void {
    if (this.modal) {
      this.position = { bottom: "auto", left: "auto", right: "auto", top: "auto" };
    }
  }

  protected attached(): void {
    if (!this.modal) {
      const iconEl = this.element.querySelector(".ui-header__icon .ui-icon");
      const labelEl = this.element.querySelector(".ui-header__title") as HTMLElement;
      if (iconEl) {
        this.icon = iconEl.au.controller.viewModel.icon;
      }
      // if (labelEl) {
      //   this.label = labelEl.innerText;
      // }
      this.taskButton = UIInternal.compileTemplate(
        `<template><ui-button size="sm" ui-theme="primary" type.bind="active?'solid':'default'" label.bind="label" icon.bind="icon"></ui-button></template>`,
        this
      );
    }
  }

  protected startDrag($event: MouseEvent): void {
    if ($event.button === 0) {
      $event.stopEvent();
      UIInternal.broadcast("dlg:drag", {
        dialog: this,
        startX: $event.x || $event.clientX,
        startY: $event.y || $event.clientY
      });
    }
  }

  @computedFrom(
    "width",
    "minWidth",
    "maxWidth",
    "height",
{'fraction_non_alphanumeric': 0.15385741472697995, 'fraction_numerical': 0.00688039818474601, 'mean_word_length': 3.4191461836998704, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '4404990', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2134, 'n_words': 506}