'use strict'; var engine = require('@aomao/engine'); var vue = require('vue'); var AConfigProvider = require('ant-design-vue/es/config-provider'); var AInput = require('ant-design-vue/es/input'); var AButton = require('ant-design-vue/es/button'); require('ant-design-vue/es/input/style/css'); require('ant-design-vue/es/button/style/css'); var ATooltip = require('ant-design-vue/es/tooltip'); require('ant-design-vue/es/tooltip/style/css'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var AConfigProvider__default = /*#__PURE__*/_interopDefaultLegacy(AConfigProvider); var AInput__default = /*#__PURE__*/_interopDefaultLegacy(AInput); var AButton__default = /*#__PURE__*/_interopDefaultLegacy(AButton); var ATooltip__default = /*#__PURE__*/_interopDefaultLegacy(ATooltip); function _regeneratorRuntime() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function () { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function (obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function (skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function () { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function (exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function (type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function (record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function (finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function (tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function (iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } var script = vue.defineComponent({ name: 'am-link-editor', components: { AConfigProvider: AConfigProvider__default['default'], AInput: AInput__default['default'], AButton: AButton__default['default'], }, props: { language: { type: Object, required: true, }, defaultText: String, defaultLink: String, className: String, onLoad: Function, onOk: Function, }, setup(props) { const text = vue.ref(props.defaultText); const link = vue.ref(props.defaultLink); const linkRef = vue.ref(null); const textTitle = props.language.get('link', 'text'); const textPlaceholder = props.language.get('link', 'text_placeholder'); const linkTitle = props.language.get('link', 'link'); const linkPlaceholder = props.language.get('link', 'link_placeholder'); const buttonTitle = props.language.get('link', 'ok_button'); const onTextChange = (value) => { text.value = value; }; const onLinkChange = (value) => { link.value = value; }; vue.onMounted(() => { if (linkRef.value) linkRef.value.focus(); setTimeout(() => { if (props.onLoad) props.onLoad(); }, 200); }); return { text, link, textTitle, textPlaceholder, linkTitle, linkPlaceholder, buttonTitle, onTextChange, onLinkChange, linkRef, }; }, }); function render(_ctx, _cache, $props, $setup, $data, $options) { const _component_a_input = vue.resolveComponent("a-input"); const _component_a_button = vue.resolveComponent("a-button"); const _component_a_config_provider = vue.resolveComponent("a-config-provider"); return (vue.openBlock(), vue.createBlock(_component_a_config_provider, { "auto-insert-space-in-button": false }, { default: vue.withCtx(() => [ vue.createElementVNode("div", { "data-element": "ui", class: vue.normalizeClass(['data-link-editor', _ctx.className]) }, [ vue.createElementVNode("p", null, vue.toDisplayString(_ctx.textTitle), 1 /* TEXT */), vue.createElementVNode("p", null, [ vue.createVNode(_component_a_input, { class: "data-link-input", value: _ctx.text, placeholder: _ctx.textPlaceholder, onChange: _cache[0] || (_cache[0] = $event => (_ctx.onTextChange($event.target.value))) }, null, 8 /* PROPS */, ["value", "placeholder"]) ]), vue.createElementVNode("p", null, vue.toDisplayString(_ctx.linkTitle), 1 /* TEXT */), vue.createElementVNode("p", null, [ vue.createVNode(_component_a_input, { ref: "linkRef", class: "data-link-input", value: _ctx.link, placeholder: _ctx.linkPlaceholder, onChange: _cache[1] || (_cache[1] = $event => (_ctx.onLinkChange($event.target.value))) }, null, 8 /* PROPS */, ["value", "placeholder"]) ]), vue.createElementVNode("p", null, [ vue.createVNode(_component_a_button, { class: "data-link-button", onClick: _cache[2] || (_cache[2] = $event => (_ctx.onOk(_ctx.text, _ctx.link))), disabled: _ctx.link.trim() === '' }, { default: vue.withCtx(() => [ vue.createTextVNode(vue.toDisplayString(_ctx.buttonTitle), 1 /* TEXT */) ]), _: 1 /* STABLE */ }, 8 /* PROPS */, ["disabled"]) ]) ], 2 /* CLASS */) ]), _: 1 /* STABLE */ })) } script.render = render; script.__file = "src/toolbar/editor.vue"; var script$1 = vue.defineComponent({ name: 'am-link-preview', components: { ATooltip: ATooltip__default['default'], }, props: { language: { type: Object, required: true, }, readonly: { type: Boolean, required: true, }, href: String, className: String, onEdit: Function, onRemove: Function, onLoad: Function, }, setup(props) { const openTitle = props.language.get('link', 'link_open'); const editTitle = props.language.get('link', 'link_edit'); const removeTitle = props.language.get('link', 'link_remove'); vue.onMounted(() => { if (props.onLoad) props.onLoad(); }); return { openTitle, editTitle, removeTitle, isMobile: engine.isMobile, }; }, }); const _hoisted_1 = { class: "data-link-preview", "data-element": "ui" }; const _hoisted_2 = ["href"]; const _hoisted_3 = { key: 0, class: "data-link-op" }; function render$1(_ctx, _cache, $props, $setup, $data, $options) { const _component_a_tooltip = vue.resolveComponent("a-tooltip"); return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [ vue.createVNode(_component_a_tooltip, { title: _ctx.openTitle }, { default: vue.withCtx(() => [ vue.createElementVNode("a", { class: "data-icon data-icon-link data-link-preview-open", href: _ctx.href, target: "_blank" }, vue.toDisplayString(_ctx.href), 9 /* TEXT, PROPS */, _hoisted_2) ]), _: 1 /* STABLE */ }, 8 /* PROPS */, ["title"]), (!_ctx.readonly) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3, [ (!_ctx.isMobile) ? (vue.openBlock(), vue.createBlock(_component_a_tooltip, { key: 0, title: _ctx.editTitle }, { default: vue.withCtx(() => [ vue.createElementVNode("a", { class: "data-icon data-icon-edit", onClick: _cache[0] || (_cache[0] = (...args) => (_ctx.onEdit && _ctx.onEdit(...args))) }) ]), _: 1 /* STABLE */ }, 8 /* PROPS */, ["title"])) : vue.createCommentVNode("v-if", true), (_ctx.isMobile) ? (vue.openBlock(), vue.createElementBlock("a", { key: 1, class: "data-icon data-icon-edit", onClick: _cache[1] || (_cache[1] = (...args) => (_ctx.onEdit && _ctx.onEdit(...args))) })) : vue.createCommentVNode("v-if", true), (!_ctx.isMobile) ? (vue.openBlock(), vue.createBlock(_component_a_tooltip, { key: 2, title: _ctx.removeTitle }, { default: vue.withCtx(() => [ vue.createElementVNode("a", { class: "data-icon data-icon-unlink", onClick: _cache[2] || (_cache[2] = (...args) => (_ctx.onRemove && _ctx.onRemove(...args))) }) ]), _: 1 /* STABLE */ }, 8 /* PROPS */, ["title"])) : vue.createCommentVNode("v-if", true), (_ctx.isMobile) ? (vue.openBlock(), vue.createElementBlock("a", { key: 3, class: "data-icon data-icon-unlink", onClick: _cache[3] || (_cache[3] = (...args) => (_ctx.onRemove && _ctx.onRemove(...args))) })) : vue.createCommentVNode("v-if", true) ])) : vue.createCommentVNode("v-if", true) ])) } script$1.render = render$1; script$1.__file = "src/toolbar/preview.vue"; var Toolbar = /*#__PURE__*/function () { function Toolbar(engine$1, options) { var _this = this; _classCallCheck(this, Toolbar); this.engine = void 0; this.root = void 0; this.target = void 0; this.options = void 0; this.mouseInContainer = false; this.vm = void 0; this.position = void 0; this.engine = engine$1; var change = this.engine.change; this.options = options; this.position = new engine.Position(this.engine); change.event.onWindow('mousedown', function (event) { if (!event.target) return; var target = engine.$(event.target); var container = target.closest('.data-link-container'); _this.mouseInContainer = container && container.length > 0; if (!target.inEditor() && !_this.mouseInContainer) _this.hide(); }); } _createClass(Toolbar, [{ key: "create", value: function create() { var _this$target$get; if (!this.target) return; var root = engine.$('.data-link-container'); if (root.length === 0) { root = engine.$("
")); } this.root = root; var rect = (_this$target$get = this.target.get()) === null || _this$target$get === void 0 ? void 0 : _this$target$get.getBoundingClientRect(); if (!rect) return; this.root.css({ top: "".concat(window.pageYOffset + rect.bottom + 4, "px"), left: "".concat(window.pageXOffset, "px"), position: 'absolute', 'z-index': 125 }); } }, { key: "onOk", value: function () { var _onOk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(text, link) { var change, range, _ref, onConfirm, result, oldText, _children$eq, children, element, _child$eq, child; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (this.target) { _context.next = 2; break; } return _context.abrupt("return"); case 2: change = this.engine.change; range = change.range.get(); if (!change.rangePathBeforeCommand) { if (!range.startNode.inEditor()) { range.select(this.target, true); change.range.select(range); } change.cacheRangeBeforeCommand(); } _ref = this.options || {}, onConfirm = _ref.onConfirm; if (!onConfirm) { _context.next = 12; break; } _context.next = 9; return onConfirm(text, link); case 9: result = _context.sent; text = result.text; link = result.link; case 12: this.target.attributes('href', link); text = text.trim() === '' ? link : text; oldText = this.target.text(); if (!(oldText !== text)) { _context.next = 45; break; } children = this.target.children(); // 左右两侧有零宽字符 if (!(children.length < 3)) { _context.next = 21; break; } this.target.text(text); _context.next = 45; break; case 21: if (!(children.length === 3 && ((_children$eq = children.eq(1)) === null || _children$eq === void 0 ? void 0 : _children$eq.isText()))) { _context.next = 25; break; } this.target.text(text); _context.next = 45; break; case 25: if (!(children.length === 3)) { _context.next = 44; break; } element = children.eq(1); case 27: if (!element) { _context.next = 42; break; } child = element.children(); // 有多个子节点就直接设置文本,覆盖里面的mark样式 if (!(child.length > 1 || child.length === 0)) { _context.next = 34; break; } element.text(text); return _context.abrupt("break", 42); case 34: if (!((_child$eq = child.eq(0)) === null || _child$eq === void 0 ? void 0 : _child$eq.isText())) { _context.next = 39; break; } element.text(text); return _context.abrupt("break", 42); case 39: element = child; case 40: _context.next = 27; break; case 42: _context.next = 45; break; case 44: this.target.text(text); case 45: this.engine.inline.repairCursor(this.target); range.setStart(this.target.next(), 1); range.setEnd(this.target.next(), 1); change.apply(range); this.mouseInContainer = false; this.hide(); case 51: case "end": return _context.stop(); } } }, _callee, this); })); function onOk(_x, _x2) { return _onOk.apply(this, arguments); } return onOk; }() }, { key: "editor", value: function editor(text, href, callback) { var _this2 = this; var vm = vue.createApp(script, { language: this.engine.language, defaultText: text, defaultLink: href, onLoad: function onLoad() { _this2.mouseInContainer = true; if (callback) callback(); }, onOk: function onOk(text, link) { return _this2.onOk(text, link); } }); return vm; } }, { key: "preview", value: function preview(href, callback) { var _this3 = this; var _this$engine = this.engine, change = _this$engine.change, inline = _this$engine.inline, language = _this$engine.language; var vm = vue.createApp(script$1, { language: language, href: href, readonly: this.engine.readonly, onLoad: function onLoad() { if (callback) callback(); }, onEdit: function onEdit() { if (!_this3.target) return; _this3.mouseInContainer = false; _this3.hide(undefined, false); _this3.show(_this3.target, true); }, onRemove: function onRemove() { if (!_this3.target) return; var range = change.range.get(); range.select(_this3.target, true); inline.repairRange(range); change.range.select(range); change.cacheRangeBeforeCommand(); inline.unwrap(); _this3.mouseInContainer = false; _this3.target = undefined; _this3.hide(); } }); return vm; } }, { key: "show", value: function show(target, forceEdit) { var _this$target, _this$root, _this$root$parent, _this4 = this; if (((_this$target = this.target) === null || _this$target === void 0 ? void 0 : _this$target.equal(target)) && !!((_this$root = this.root) === null || _this$root === void 0 ? void 0 : (_this$root$parent = _this$root.parent()) === null || _this$root$parent === void 0 ? void 0 : _this$root$parent.length)) return; this.target = target; this.create(); var text = target.text().replace(/\u200B/g, ''); var href = target.attributes('href'); var container = this.root.get(); var name = (!href || forceEdit) && !this.engine.readonly ? 'am-link-editor' : 'am-link-preview'; if (this.vm && this.vm._component.name === name) { var _this$position, _this$position2; if (!this.root || !this.target) return; (_this$position = this.position) === null || _this$position === void 0 ? void 0 : _this$position.destroy(); (_this$position2 = this.position) === null || _this$position2 === void 0 ? void 0 : _this$position2.bind(this.root, this.target); return; } else if (this.vm) { var _this$position3; this.vm.unmount(); this.vm = undefined; (_this$position3 = this.position) === null || _this$position3 === void 0 ? void 0 : _this$position3.destroy(); } setTimeout(function () { var _this4$position, _this4$position2; (_this4$position = _this4.position) === null || _this4$position === void 0 ? void 0 : _this4$position.destroy(); (_this4$position2 = _this4.position) === null || _this4$position2 === void 0 ? void 0 : _this4$position2.bind(_this4.root, _this4.target); _this4.vm = (!href || forceEdit) && !_this4.engine.readonly ? _this4.editor(text, href, function () { var _this4$position3; (_this4$position3 = _this4.position) === null || _this4$position3 === void 0 ? void 0 : _this4$position3.update(); }) : _this4.preview(href, function () { var _this4$position4; (_this4$position4 = _this4.position) === null || _this4$position4 === void 0 ? void 0 : _this4$position4.update(); }); _this4.vm.mount(container); }, 20); } }, { key: "hide", value: function hide(target, clearTarget) { var _this$root2; if (target && this.target && target.equal(this.target)) return; var element = (_this$root2 = this.root) === null || _this$root2 === void 0 ? void 0 : _this$root2.get(); if (element && !this.mouseInContainer) { if (this.vm) { var _this$position4; this.vm.unmount(); this.vm = undefined; (_this$position4 = this.position) === null || _this$position4 === void 0 ? void 0 : _this$position4.destroy(); } this.root = undefined; if (this.target && !this.target.attributes('href')) { var _this$engine2 = this.engine, change = _this$engine2.change, inline = _this$engine2.inline; var range = change.range.get(); range.select(this.target, true); inline.unwrap(range); change.apply(range.collapse(true)); } if (clearTarget !== false) this.target = undefined; } } }]); return Toolbar; }(); var en = { link: { text: 'Text', link: 'Link', text_placeholder: 'Description text', link_placeholder: 'Link address', link_open: 'Open link', link_edit: 'Edit link', link_remove: 'Remove link', ok_button: 'OK' } }; var cn = { link: { text: '文本', link: '链接', text_placeholder: '描述文本', link_placeholder: '链接地址', link_open: '打开链接', link_edit: '编辑链接', link_remove: '移除链接', ok_button: '确定' } }; var locales = { 'en-US': en, 'zh-CN': cn }; function styleInject(css, ref) { if ( ref === void 0 ) ref = {}; var insertAt = ref.insertAt; if (!css || typeof document === 'undefined') { return; } var head = document.head || document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css'; if (insertAt === 'top') { if (head.firstChild) { head.insertBefore(style, head.firstChild); } else { head.appendChild(style); } } else { head.appendChild(style); } if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } } var css_248z = ".data-link-container {\r\n max-width: 398px;\r\n display: inline-block;\r\n border: 1px solid #E8E8E8;\r\n border-radius: 4px;\r\n box-shadow: rgba(221, 221, 221, 0.5) 0px 1px 3px;\r\n background: white;\r\n}\r\n\r\n.data-link-container-mobile {\r\n max-width: calc(100vw - 20px);;\r\n}\r\n\r\n.data-link-container .data-link-editor {\r\n min-width: 365px;\r\n padding: 16px 12px;\r\n padding-bottom: 4px;\r\n}\r\n\r\n.data-link-container-mobile .data-link-editor {\r\n min-width: calc(100vw - 40px);\r\n padding: 8px 6px;\r\n}\r\n\r\n.data-link-container p {\r\n margin-top: 0;\r\n margin-bottom: 14px;\r\n}\r\n\r\n.data-link-container .itellyou-icon {\r\n color: #8590A6;\r\n font-size: 16px;\r\n}\r\n.data-link-preview {\r\n line-height: 16px;\r\n padding: 6px 8px;\r\n vertical-align: middle;\r\n white-space: nowrap;\r\n display: flex;\r\n justify-content:space-between;\r\n}\r\n.data-link-preview > * {\r\n display: block;\r\n}\r\n\r\n.data-link-preview a {\r\n display: inline-block;\r\n color: #595959;\r\n margin: 0px 0px 0px 8px;\r\n padding: 4px;\r\n}\r\n.data-link-preview a:hover {\r\n background: #F4F4F4;\r\n cursor: pointer;\r\n}\r\n.data-link-preview a.data-link-preview-open {\r\n color: #1890FF;\r\n max-width: 292px;\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n white-space: nowrap;\r\n text-decoration: none;\r\n font-size: 14px;\r\n letter-spacing: 1.2px;\r\n vertical-align: middle;\r\n margin: 0;\r\n}\r\n.data-link-container-mobile .data-link-preview a.data-link-preview-open {\r\n max-width: 70%;\r\n}\r\n.data-link-preview a.data-link-preview-open::before\r\n{\r\n vertical-align: middle;\r\n margin-right: 2px;\r\n}\r\n\r\n.data-link-preview a.data-link-preview-open:hover{\r\n background: transparent;\r\n}"; styleInject(css_248z); var PASTE_EACH = 'paste:each'; var MARKDOWN_IT = 'markdown-it'; var PARSE_HTML = 'parse:html'; var SELECT = 'select'; var _default = /*#__PURE__*/function (_InlinePlugin) { _inherits(_default, _InlinePlugin); var _super = _createSuper(_default); function _default() { var _this; _classCallCheck(this, _default); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _this.toolbar = void 0; _this.attributes = { target: '@var0', href: '@var1' }; _this.variable = { '@var0': ['_blank', '_parent', '_top', '_self'], '@var1': { required: true, value: '*' } }; _this.tagName = 'a'; _this.handleClick = function (e) { if (!e.target) return; var onLinkClick = _this.options.onLinkClick; if (!onLinkClick) return; var target = engine.$(e.target).closest("".concat(_this.tagName)); if (target.name === _this.tagName) { onLinkClick(e, target.attributes('href')); } }; _this.bindQuery = function () { _this.query(); }; _this.query = function () { var _this$toolbar; var editor = _this.editor; if (!engine.isEngine(editor)) return; var change = editor.change; var inlineNode = change.inlines.find(function (node) { return _this.isSelf(node); }); (_this$toolbar = _this.toolbar) === null || _this$toolbar === void 0 ? void 0 : _this$toolbar.hide(inlineNode); if (inlineNode && inlineNode.length > 0 && !inlineNode.isCard()) { var range = change.range.get(); if (range.collapsed || inlineNode.contains(range.startNode) && inlineNode.contains(range.endNode)) { var _this$toolbar2; (_this$toolbar2 = _this.toolbar) === null || _this$toolbar2 === void 0 ? void 0 : _this$toolbar2.show(inlineNode); return true; } else { var _this$toolbar3; (_this$toolbar3 = _this.toolbar) === null || _this$toolbar3 === void 0 ? void 0 : _this$toolbar3.hide(); } } return false; }; _this.markdownIt = function (mardown) { if (_this.options.markdown !== false) { mardown.enable('link'); mardown.enable('linkify'); } }; _this.pasteHtml = function (child) { if (child.isText()) { var text = child.text(); var _this$editor = _this.editor, node = _this$editor.node, inline = _this$editor.inline; if (/^https?:\/\/\S+$/.test(text.toLowerCase().trim()) && inline.closest(child).equal(child)) { var newNode = node.wrap(child, engine.$("<".concat(_this.tagName, " target=\"_blank\" href=\"").concat(decodeURI(text).trim().replace(/\u200b/g, ''), "\">"))); inline.repairCursor(newNode); return false; } } else if (child.name === 'a') { var href = child.attributes('href'); child.attributes('target', '_blank'); child.attributes('href', decodeURI(href).trim().replace(/\u200b/g, '')); } return true; }; _this.parseHtml = function (root) { root.find(_this.tagName).css({ 'font-family': 'monospace', 'font-size': 'inherit', 'background-color': 'rgba(0,0,0,.06)', padding: '0 2px', border: '1px solid rgba(0,0,0,.08)', 'border-radius': '2px 2px', 'line-height': 'inherit', 'overflow-wrap': 'break-word', 'text-indent': '0' }); }; return _this; } _createClass(_default, [{ key: "init", value: function init() { _get(_getPrototypeOf(_default.prototype), "init", this).call(this); var editor = this.editor; if (engine.isEngine(editor)) { if (this.options.enableToolbar !== false) { this.toolbar = new Toolbar(editor, { onConfirm: this.options.onConfirm }); } editor.container.on('click', this.handleClick); editor.on(MARKDOWN_IT, this.markdownIt); editor.on(PASTE_EACH, this.pasteHtml); } editor.on(PARSE_HTML, this.parseHtml); editor.on(SELECT, this.bindQuery); editor.language.add(locales); } }, { key: "hotkey", value: function hotkey() { return this.options.hotkey || { key: 'mod+k', args: ['_blank'] }; } }, { key: "execute", value: function execute() { var _this2 = this; var editor = this.editor; if (!engine.isEngine(editor)) return; var inline = editor.inline, change = editor.change; if (!this.queryState()) { var inlineNode = engine.$("<".concat(this.tagName, " />")); this.setStyle.apply(this, [inlineNode].concat(Array.prototype.slice.call(arguments))); this.setAttributes.apply(this, [inlineNode].concat(Array.prototype.slice.call(arguments))); var text = arguments.length > 2 ? arguments[2] : ''; if (!!text) { inlineNode.text(text); inline.insert(inlineNode); } else { inline.wrap(inlineNode); } var range = change.range.get(); if (!range.collapsed && change.inlines.length > 0) { var _this$toolbar4; (_this$toolbar4 = this.toolbar) === null || _this$toolbar4 === void 0 ? void 0 : _this$toolbar4.show(change.inlines[0]); } } else { var _inlineNode = change.inlines.find(function (node) { return _this2.isSelf(node); }); if (_inlineNode && _inlineNode.length > 0) { inline.unwrap(_inlineNode); } } } }, { key: "queryState", value: function queryState() { return this.query(); } }, { key: "destroy", value: function destroy() { var editor = this.editor; editor.container.off('click', this.handleClick); editor.off(PASTE_EACH, this.pasteHtml); editor.off(PARSE_HTML, this.parseHtml); editor.off(SELECT, this.bindQuery); editor.off(MARKDOWN_IT, this.markdownIt); } }], [{ key: "pluginName", get: function get() { return 'link'; } }]); return _default; }(engine.InlinePlugin); module.exports = _default;