<commit_before><link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-a11y-keys/iron-a11y-keys.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-dialog-behavior/paper-dialog-behavior.html">
<link rel="import" href="../paper-dialog-behavior/demo/simple-dialog.html">

<!--
`<simplye-editable-content>` is a simple contenteditable wrapper
inteded on lending itself to a basic WYSIWYG editor

It is currently naive in many regards, perhaps relying too heavily
on native browser support. It has only been tested in chrome

For example,
  - Consider undo.js to manage undo and redo (if any platforms lack support)

@demo demo/index.html
-->
<dom-module id="simply-editable-content">
  <template>
    <style>
      #content {
        padding: 16px;
      }
      [contenteditable=true]:empty:before {
        color: var(--secondary-text-color, #737373);
        content: attr(placeholder);
        display: block;
      }
    </style>
    <div id="content" contenteditable="true" placeholder$="[[placeholder]]"></div>
    <iron-a11y-keys target="[[target]]" keys="enter:keyup space:keyup tab ctrl+v:keyup"
            on-keys-pressed="_sanitizationHandler">
    </iron-a11y-keys>
    <iron-a11y-keys target="[[target]]" keys="up:keyup down:keyup left:keyup right:keyup pageup:keyup pagedown:keyup home end arrow:keyup ctrl+v ctrl+x"
            on-keys-pressed="_selectionHandler">
    </iron-a11y-keys>
    <simple-dialog id="linkDialog" modal role="alertdialog">
      <h2>Edit Link</h2>
      <div>
        <paper-input label="[[settings.link.textLabel]]" placeholder="[[settings.link.textPlaceholder]]"
                value="{{_tempLink.text}}"></paper-input>
        <paper-input label="[[settings.link.label]]" placeholder="[[settings.link.placeholder]]"
                value="{{_tempLink.href}}" auto-validate pattern="[[settings.link.pattern]]"
                error-message="Invalid URL!"></paper-input>
      </div>
      <div class="buttons">
        <paper-button dialog-dismiss>Cancel</paper-button>
        <paper-button dialog-confirm autofocus on-tap="_onTapLinkOk" disabled="[[!_isValidUrl(_tempLink.href)]]">OK</paper-button>
      </div>
    </simple-dialog>
  </template>
  <script>
    Polymer({
      is: 'simply-editable-content',

      properties: {
        /**
         * the content editable element
         */
        target: {
          type: Object,
          value: function() {
            return this.$.content;
          }
        },
        /**
         * Placeholder text
         */
        placeholder: {
          type: String,
          value: "Enter content"
        },
        /**
         * Meta-data about the current selection
         */<commit_msg>bind to input events for url entry<commit_after><link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-a11y-keys/iron-a11y-keys.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-dialog-behavior/paper-dialog-behavior.html">
<link rel="import" href="../paper-dialog-behavior/demo/simple-dialog.html">

<!--
`<simplye-editable-content>` is a simple contenteditable wrapper
inteded on lending itself to a basic WYSIWYG editor

It is currently naive in many regards, perhaps relying too heavily
on native browser support. It has only been tested in chrome

For example,
  - Consider undo.js to manage undo and redo (if any platforms lack support)

@demo demo/index.html
-->
<dom-module id="simply-editable-content">
  <template>
    <style>
      #content {
        padding: 16px;
      }
      [contenteditable=true]:empty:before {
        color: var(--secondary-text-color, #737373);
        content: attr(placeholder);
        display: block;
      }
    </style>
    <div id="content" contenteditable="true" placeholder$="[[placeholder]]"></div>
    <iron-a11y-keys target="[[target]]" keys="enter:keyup space:keyup tab ctrl+v:keyup"
            on-keys-pressed="_sanitizationHandler">
    </iron-a11y-keys>
    <iron-a11y-keys target="[[target]]" keys="up:keyup down:keyup left:keyup right:keyup pageup:keyup pagedown:keyup home end arrow:keyup ctrl+v ctrl+x"
            on-keys-pressed="_selectionHandler">
    </iron-a11y-keys>
    <simple-dialog id="linkDialog" modal role="alertdialog">
      <h2>Edit Link</h2>
      <div>
        <paper-input label="[[settings.link.textLabel]]" placeholder="[[settings.link.textPlaceholder]]"
                value="{{_tempLink.text::input}}"></paper-input>
        <paper-input label="[[settings.link.label]]" placeholder="[[settings.link.placeholder]]"
                value="{{_tempLink.href::input}}" invalid$="[[!_isValidUrl(_tempLink.href)]]" error-message="Invalid URL!"></paper-input>
      </div>
      <div class="buttons">
        <paper-button dialog-dismiss>Cancel</paper-button>
        <paper-button dialog-confirm autofocus on-tap="_onTapLinkOk" disabled="[[!_isValidUrl(_tempLink.href)]]">OK</paper-button>
      </div>
    </simple-dialog>
  </template>
  <script>
    Polymer({
      is: 'simply-editable-content',

      properties: {
        /**
         * the content editable element
         */
        target: {
          type: Object,
          value: function() {
            return this.$.content;
          }
        },
        /**
         * Placeholder text
         */
        placeholder: {
          type: String,
          value: "Enter content"
        },
        /**
         * Meta-data about the current selection
         */
{'fraction_non_alphanumeric': 0.1595872742906277, 'fraction_numerical': 0.007566638005159072, 'mean_word_length': 2.836411609498681, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, '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': '5297396', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1738, 'n_words': 361}