module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "/dist/";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 157);
/******/ })
/************************************************************************/
/******/ ({

/***/ 0:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
/* globals __VUE_SSR_CONTEXT__ */

// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.

function normalizeComponent(
  scriptExports,
  render,
  staticRenderFns,
  functionalTemplate,
  injectStyles,
  scopeId,
  moduleIdentifier /* server only */,
  shadowMode /* vue-cli only */
) {
  // Vue.extend constructor export interop
  var options =
    typeof scriptExports === 'function' ? scriptExports.options : scriptExports

  // render functions
  if (render) {
    options.render = render
    options.staticRenderFns = staticRenderFns
    options._compiled = true
  }

  // functional template
  if (functionalTemplate) {
    options.functional = true
  }

  // scopedId
  if (scopeId) {
    options._scopeId = 'data-v-' + scopeId
  }

  var hook
  if (moduleIdentifier) {
    // server build
    hook = function (context) {
      // 2.3 injection
      context =
        context || // cached call
        (this.$vnode && this.$vnode.ssrContext) || // stateful
        (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
      // 2.2 with runInNewContext: true
      if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
        context = __VUE_SSR_CONTEXT__
      }
      // inject component styles
      if (injectStyles) {
        injectStyles.call(this, context)
      }
      // register component module identifier for async chunk inferrence
      if (context && context._registeredComponents) {
        context._registeredComponents.add(moduleIdentifier)
      }
    }
    // used by ssr in case component is cached and beforeCreate
    // never gets called
    options._ssrRegister = hook
  } else if (injectStyles) {
    hook = shadowMode
      ? function () {
          injectStyles.call(
            this,
            (options.functional ? this.parent : this).$root.$options.shadowRoot
          )
        }
      : injectStyles
  }

  if (hook) {
    if (options.functional) {
      // for template-only hot-reload because in that case the render fn doesn't
      // go through the normalizer
      options._injectStyles = hook
      // register for functional component in vue file
      var originalRender = options.render
      options.render = function renderWithStyleInjection(h, context) {
        hook.call(context)
        return originalRender(h, context)
      }
    } else {
      // inject component registration as beforeCreate hook
      var existing = options.beforeCreate
      options.beforeCreate = existing ? [].concat(existing, hook) : [hook]
    }
  }

  return {
    exports: scriptExports,
    options: options
  }
}


/***/ }),

/***/ 157:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/insert-input/src/main.vue?vue&type=template&id=83e0a936&
var render = function () {
  var _vm = this
  var _h = _vm.$createElement
  var _c = _vm._self._c || _h
  return _c("div", { staticClass: "el-insert-input" }, [
    _c(
      "div",
      { staticClass: "el-insert-input__add-field" },
      [
        _c(
          "el-dropdown",
          { on: { command: _vm.handleCommand } },
          [
            _c("span", { staticClass: "el-dropdown-link" }, [
              _c("i", { staticClass: "bi-iconfont-add-circle-fill" }),
              _vm._v("插入变量\n      "),
            ]),
            _c(
              "el-dropdown-menu",
              { attrs: { slot: "dropdown" }, slot: "dropdown" },
              _vm._l(_vm.dropList, function (item) {
                return _c(
                  "el-dropdown-item",
                  {
                    key: item.key,
                    attrs: {
                      command: item,
                      disabled: !_vm.multiple && _vm.tagArr.includes(item.key),
                    },
                  },
                  [_vm._v(_vm._s(item.value) + "\n        ")]
                )
              }),
              1
            ),
          ],
          1
        ),
        _c(
          "span",
          {
            class: [
              "el-insert-input__maxlength",
              _vm.length > _vm.maxLength && "el-insert-input__maxlength-max",
            ],
          },
          [
            _vm._v(
              "\n      " +
                _vm._s(_vm.length) +
                "/" +
                _vm._s(_vm.maxLength) +
                "\n    "
            ),
          ]
        ),
      ],
      1
    ),
    _c("div", {
      ref: "textRef",
      staticClass: "el-insert-input__textarea",
      attrs: { id: "text" },
      on: {
        keydown: function ($event) {
          if (
            !("button" in $event) &&
            _vm._k($event.keyCode, "delete", [8, 46], $event.key, [
              "Backspace",
              "Delete",
              "Del",
            ])
          ) {
            return null
          }
          return _vm.deleteContent($event)
        },
        input: _vm.notify,
      },
    }),
  ])
}
var staticRenderFns = []
render._withStripped = true


// CONCATENATED MODULE: ./packages/insert-input/src/main.vue?vue&type=template&id=83e0a936&

// CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/insert-input/src/main.vue?vue&type=script&lang=js&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

var uuid = __webpack_require__(36);
/* harmony default export */ var mainvue_type_script_lang_js_ = ({
  name: 'ElInsertInput',
  props: {
    multiple: {
      type: Boolean,
      default: false
    },
    dropList: {
      type: Array,
      default: function _default() {
        return [];
      }
    },
    value: {
      type: String,
      default: ''
    },
    validContent: {
      // 格式校验提示语
      type: String,
      default: '格式错误!'
    },
    maxLength: {
      // 文本最大长度
      type: Number,
      default: 10000
    },
    defaultAddFn: {
      // 点击插入后默认触发事件
      type: Boolean,
      default: true
    }
  },
  data: function data() {
    return {
      length: 0,
      selectedList: [],
      show: false,
      beforeRange: null, // 存储上一次的range
      range: null,
      areaId: 'text',
      rangeId: null,
      beforeRangeId: null,
      currentRangeId: null,
      endOffset: null,
      tagArr: [] // 插入后获取所有的icon
    };
  },
  mounted: function mounted() {
    if (this.value) this.insertVal(this.value);
    document.addEventListener('selectionchange', this.selectionHandler);
  },
  beforeDestroy: function beforeDestroy() {
    document.removeEventListener('selectionchange', this.selectionHandler);
  },

  methods: {
    /**
     * @description: 删除标签时，连同空格一起删除
     * @return {*}
     */
    deleteContent: function deleteContent() {
      var _this = this;

      this.selectionHandler(); // 手动获取光标移动

      var rangeEle = this.range.commonAncestorContainer;


      var range = document.createRange();
      this.$refs.textRef.childNodes.forEach(function (element) {
        var node = element.attributes ? element.attributes['tag-data-id'] : null;
        var text = element.attributes ? element.attributes['text-data-id'] : null;
        if (node && node.nodeValue === _this.beforeRangeId) {
          // 当该node前面是标签时 删除前方标签
          range.selectNode(rangeEle);
          range.deleteContents();
        } else if (text && text.nodeValue === _this.currentRangeId && (rangeEle.length === 1 || rangeEle.textContent === '\n') && _this.endOffset !== 0) {
          // 此处判断当node为span且其中只有一个字符时，清空内容但阻止删除该span空标签
          console.log(_this.endOffset);
          if (element.innerHTML.length === 1 || rangeEle.textContent === '\n') {
            _this.beforeDel(element);
          }
        }
      });
      this.notify();
    },
    beforeDel: function beforeDel(element) {
      var dom = this.range.createContextualFragment(' ');
      this.range.insertNode(dom);
      setTimeout(function () {
        element.innerHTML = '';
      }, 0);
    },

    /**
     * @description: 通知修改内容
     * @return {*}
     */
    notify: function notify() {
      var _this2 = this;

      var arr = document.querySelectorAll('#text i'); // 插入后获取所有的icon
      this.tagArr = [];

      arr.forEach(function (ele) {
        if (ele.attributes) {
          _this2.tagArr.push(ele.attributes['icon-id'].nodeValue);
        }
      });

      this.$emit('input', this.$refs.textRef.innerHTML);
      this.$emit('getValue', this.getTextWithTem());
      this.$emit('getLength', this.length);
    },


    /**
     * @description: 移动光标
     * @param {*} lastUUID
     * @return {*}
     */
    manualHandler: function manualHandler(lastUUID) {
      var _this3 = this;

      var range = document.createRange();

      this.$refs.textRef.childNodes.forEach(function (element) {
        if (element.attributes && element.attributes['text-data-id'] && element.attributes['text-data-id'].nodeValue === lastUUID) {
          // const sel = window.getSelection();
          // sel.collapse(element, 0);// 光标移动至最后
          range.selectNodeContents(element);
          _this3.range = range;
        }
      });
    },


    /**
     * @description: 校验是否含有关键字
     * @return {*}
     */
    valid: function valid() {
      var TEXT = this.$refs.textRef.innerText;
      if (!TEXT) return true;

      // if (this.length > this.maxLength) return false;

      var contentWithNoSpace = TEXT.split('\n').join('');
      return !/\$\{.*?\}/g.test(contentWithNoSpace);
    },

    /**
     * @description: 生成模板字符
     * @return {*}
     */
    getTextWithTem: function getTextWithTem() {
      if (this.validContent && !this.valid()) {
        this.$message({
          message: this.validContent,
          type: 'warning'
        });
      }
      var arr = [];
      var length = 0;

      this.$refs.textRef.childNodes.forEach(function (element) {
        switch (element.className) {
          case 'text':
            arr.push(element.innerText);
            length += element.innerText.length;
            break;
          case 'text-var':
            arr.push(element.attributes.key.nodeValue);
            length += 5;
            break;
          default:
            break;
        }

        if (element.className === undefined) {
          arr.push(element.data);
          length += element.length;
        }
      });

      this.length = length;
      return arr.join('');
    },

    /**
     * @description: 移动光标 记录位置
     * @return {*}
     */
    selectionHandler: function selectionHandler() {
      this.endOffset = null;
      var sel = window.getSelection();

      var range = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
      var endOffset = range.endOffset,
          commonAncestorContainer = range.commonAncestorContainer;
      var ownerDocument = commonAncestorContainer.ownerDocument,
          textContent = commonAncestorContainer.textContent,
          data = commonAncestorContainer.data,
          previousElementSibling = commonAncestorContainer.previousElementSibling,
          className = commonAncestorContainer.className,
          parentElement = commonAncestorContainer.parentElement,
          innerText = commonAncestorContainer.innerText;
      // nodeName

      if (range && ownerDocument.activeElement.id === this.areaId) {
        // 判断是是否作用于该输入框，避免出现一个页面多个相同输入框冲突
        this.range = range;

        // 父级classList 用了就无法记录
        // const arr = Array.from(parentElement.classList);

        if (className !== 'text') {
          // 判断当用户直接点到text文本本身 此时是没有text样式的。
          this.endOffset = endOffset;

          this.beforeRangeId = null;
          this.currentRangeId = parentElement.className === 'text' ? parentElement.attributes['text-data-id'].nodeValue : null;
        } else if (innerText === '\n\n') {
          // 排除class为text的换行符innerText;
          this.currentRangeId = commonAncestorContainer.attributes['text-data-id'].nodeValue;
        } else {
          // textContent内容以判断换行内容，data只能记录每一行的内容
          this.beforeRangeId = !data && textContent === '' ? previousElementSibling && previousElementSibling.attributes ? previousElementSibling.attributes['tag-data-id'].nodeValue : null : null;
        }
      }
    },

    /**
     * @description: 未选中时初始化range
     * @return {*}
     */
    initRange: function initRange() {
      this.range = document.createRange();
      this.range.selectNodeContents(this.$refs.textRef);
    },

    /**
     * @description: 插入模块
     * @param {*} node
     * @return {*}
     */
    insertVal: function insertVal(node) {
      var _this4 = this;

      if (!this.range) this.initRange();

      var _range$commonAncestor = this.range.commonAncestorContainer,
          parentElement = _range$commonAncestor.parentElement,
          nodeValue = _range$commonAncestor.nodeValue,
          className = _range$commonAncestor.className;

      if (parentElement.parentElement.className === 'text-var') return; // 点击到了标签内，不作处理

      var dom = ''; // 要插入的节点
      var placeholderDom = function placeholderDom(val, uuid) {
        return '<span text-data-id="' + uuid + '" class="text">' + val + '</span>';
      }; // 占位标签模板
      var lastUUID = ''; // 随机ID

      if (nodeValue && nodeValue.length > 0 || className === 'text') {
        // 选中的位置为span
        var index = this.range.endOffset;

        var start = !nodeValue ? '' : nodeValue.substring(0, index);
        var end = !nodeValue ? '' : nodeValue.substring(index, nodeValue.length);
        lastUUID = uuid.v1();

        dom = this.range.createContextualFragment('' + placeholderDom(start, uuid.v1()) + node + placeholderDom(end, lastUUID));

        var range = document.createRange();
        [parentElement.className].includes('text') ? range.selectNode(parentElement) : range.selectNode(this.range.commonAncestorContainer);
        range.deleteContents();
      } else {
        // 选中的node为初始化文本
        lastUUID = uuid.v1();
        dom = this.range.createContextualFragment('' + node + placeholderDom('', lastUUID));

        if ([parentElement.className].includes('text')) {
          dom = parentElement.innerText.length > 1 ? this.range.createContextualFragment('' + node + placeholderDom('', lastUUID)) : this.range.createContextualFragment('' + placeholderDom('', uuid.v1()) + node + placeholderDom('', lastUUID));
          // dom = this.range.createContextualFragment(`${placeholderDom('', uuid.v1())}${node}${placeholderDom('', lastUUID)}`);
          var _range = document.createRange();
          _range.selectNode(parentElement);
          _range.deleteContents();
        }
      }

      this.range.insertNode(dom);
      var arr = document.querySelectorAll('.text-var .bi-iconfont-setting'); // 插入后获取所有的icon

      this.manualHandler(lastUUID); // 光标位置移动
      this.notify(); // 通知

      arr.forEach(function (item) {
        var id = item.getAttribute('icon-id');
        if (!item.onclick) {
          item.onclick = function () {
            _this4.clickIcon(id);
          };
        }
      });
    },


    /**
     * @description: 点击icon回调
     * @param {*} e
     * @return {*}
     */
    clickIcon: function clickIcon(e) {
      this.$emit('getTagId', e);
    },


    /**
     * @description: 生成HTML并添加
     * @param {*} val
     * @return {*}
     */
    handleCommand: function handleCommand(val) {
      var div = '<span class="text-var" tag-data-id="' + uuid.v1() + '" contentEditable="false" key="' + val.key + '"><span class="text">' + val.value + '</span><i icon-id=' + val.key + ' class="bi-iconfont-setting"></i></span>';
      this.insertVal(div);
      if (this.defaultAddFn) this.clickIcon(val.key);
    }
  }
});
// CONCATENATED MODULE: ./packages/insert-input/src/main.vue?vue&type=script&lang=js&
 /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_); 
// EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
var componentNormalizer = __webpack_require__(0);

// CONCATENATED MODULE: ./packages/insert-input/src/main.vue





/* normalize component */

var component = Object(componentNormalizer["a" /* default */])(
  src_mainvue_type_script_lang_js_,
  render,
  staticRenderFns,
  false,
  null,
  null,
  null
  
)

/* harmony default export */ var main = (component.exports);
// CONCATENATED MODULE: ./packages/insert-input/index.js


/* istanbul ignore next */
main.install = function (Vue) {
  Vue.component(main.name, main);
};

/* harmony default export */ var insert_input = __webpack_exports__["default"] = (main);

/***/ }),

/***/ 36:
/***/ (function(module, exports) {

module.exports = require("uuid");

/***/ })

/******/ });