@seafile/sdoc-editor 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/css/textlink-hovermenu.css +51 -0
- package/dist/config.js +16 -0
- package/dist/editor.js +13 -20
- package/dist/{slate-extension → extension}/constants/index.js +4 -0
- package/dist/{slate-extension → extension}/core/queries/index.js +44 -15
- package/dist/{slate-extension → extension}/core/transforms/focus-editor.js +2 -2
- package/dist/extension/core/transforms/index.js +3 -0
- package/dist/{slate-extension → extension}/core/transforms/move-children.js +1 -1
- package/dist/extension/core/transforms/remove-node-children.js +24 -0
- package/dist/{slate-extension → extension}/core/utils/index.js +10 -0
- package/dist/{slate-extension → extension}/index.js +2 -2
- package/dist/{slate-extension → extension}/plugins/blockquote/helpers.js +1 -1
- package/dist/{slate-extension → extension}/plugins/blockquote/menu/index.js +1 -2
- package/dist/{slate-extension → extension}/plugins/blockquote/plugin.js +5 -9
- package/dist/extension/plugins/blockquote/render-elem.js +10 -0
- package/dist/{slate-extension → extension}/plugins/check-list/helpers.js +1 -1
- package/dist/{slate-extension → extension}/plugins/check-list/plugin.js +1 -1
- package/dist/{slate-extension → extension}/plugins/check-list/render-elem.js +5 -3
- package/dist/{slate-extension → extension}/plugins/header/helpers.js +1 -1
- package/dist/{slate-extension → extension}/plugins/header/plugin.js +4 -7
- package/dist/{slate-extension → extension}/plugins/header/render-elem.js +3 -1
- package/dist/extension/plugins/index.js +9 -0
- package/dist/extension/plugins/link/helpers.js +152 -0
- package/dist/extension/plugins/link/index.js +14 -0
- package/dist/extension/plugins/link/menu/add-link-dialog.js +146 -0
- package/dist/extension/plugins/link/menu/hover-link-dialog.js +49 -0
- package/dist/extension/plugins/link/menu/index.js +67 -0
- package/dist/extension/plugins/link/model.js +13 -0
- package/dist/extension/plugins/link/plugin.js +60 -0
- package/dist/extension/plugins/link/render-elem.js +114 -0
- package/dist/{slate-extension → extension}/plugins/list/helpers.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/menu/index.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/plugin/normalize-list.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/plugin/on-tab-handle.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/queries/index.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/render-elem.js +11 -4
- package/dist/{slate-extension → extension}/plugins/list/transforms/insert-list-item.js +17 -22
- package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-item-down.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-item-up.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-items-to-list.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-items.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/normalize-list-item.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/normalize-nested-list.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/toggle-list.js +1 -1
- package/dist/{slate-extension → extension}/plugins/list/transforms/unwrap-list.js +1 -1
- package/dist/{slate-extension → extension}/plugins/text-style/render-elem.js +3 -1
- package/dist/{slate-extension → extension}/render/render-element.js +14 -4
- package/dist/{slate-extension → extension}/toolbar/index.js +4 -1
- package/dist/index.js +2 -1
- package/dist/node-id/constants.js +18 -0
- package/dist/node-id/helpers.js +80 -0
- package/dist/node-id/index.js +11 -0
- package/dist/socket/helpers.js +258 -0
- package/dist/socket/index.js +3 -0
- package/dist/socket/socket-client.js +138 -0
- package/dist/socket/socket-manager.js +180 -0
- package/dist/socket/with-socket-io.js +18 -0
- package/dist/viewer.js +81 -0
- package/package.json +9 -6
- package/public/locales/en/seafile-editor.json +4 -1
- package/public/locales/zh-CN/seafile-editor.json +4 -1
- package/dist/slate-extension/core/transforms/index.js +0 -2
- package/dist/slate-extension/plugins/blockquote/render-elem.js +0 -7
- package/dist/slate-extension/plugins/index.js +0 -9
- package/dist/slate-extension/plugins/socket/index.js +0 -6
- package/dist/slate-extension/plugins/socket/plugin.js +0 -23
- package/dist/slate-extension/socket/socket-client.js +0 -94
- package/dist/slate-extension/socket/socket-manager.js +0 -63
- /package/dist/{slate-extension → extension}/core/index.js +0 -0
- /package/dist/{slate-extension → extension}/menu/index.js +0 -0
- /package/dist/{slate-extension → extension}/menu/menu-group.js +0 -0
- /package/dist/{slate-extension → extension}/menu/menu-item.js +0 -0
- /package/dist/{slate-extension → extension}/menu/menu.css +0 -0
- /package/dist/{slate-extension → extension}/plugins/blockquote/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/blockquote/model.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/check-list/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/check-list/menu/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/check-list/model.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/header/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/header/menu/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/list/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/list/model.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/list/plugin/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/list/plugin/insert-break-list.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/list/transforms/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/list/transforms/remove-first-list-item.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/text-style/index.js +0 -0
- /package/dist/{slate-extension → extension}/plugins/text-style/model.js +0 -0
- /package/dist/{slate-extension → extension}/render/render-leaf.js +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $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 define(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 defineProperty(generator, "_invoke", { value: makeInvokeMethod(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; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(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); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), 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, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), 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 (val) { var object = Object(val), 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 reset(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 stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(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 abrupt(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 complete(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 finish(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 _catch(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 delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
|
+
import { Editor, Transforms, Range } from '@seafile/slate';
|
|
5
|
+
import { LINK } from '../../constants';
|
|
6
|
+
import { getNodeType, getSelectedElems, removeNodeChildren, getAboveNode, getEditorString } from '../../core';
|
|
7
|
+
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
8
|
+
if (editor.selection == null) return true;
|
|
9
|
+
var selectedElems = getSelectedElems(editor);
|
|
10
|
+
var notMatch = selectedElems.some(function (elem) {
|
|
11
|
+
var type = elem.type;
|
|
12
|
+
if (editor.isVoid(elem)) return true;
|
|
13
|
+
if (['pre', 'code', 'link'].includes(type)) return true;
|
|
14
|
+
return false;
|
|
15
|
+
});
|
|
16
|
+
if (notMatch) return true; // disabled
|
|
17
|
+
return false; // enable
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export var checkLink = function checkLink(url) {
|
|
21
|
+
if (url.indexOf('http') !== 0) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
export var genLinkNode = function genLinkNode(url, text) {
|
|
27
|
+
var linkNode = {
|
|
28
|
+
type: 'link',
|
|
29
|
+
href: url,
|
|
30
|
+
title: text,
|
|
31
|
+
children: text ? [{
|
|
32
|
+
text: text
|
|
33
|
+
}] : []
|
|
34
|
+
};
|
|
35
|
+
return linkNode;
|
|
36
|
+
};
|
|
37
|
+
export var getLinkType = function getLinkType(editor) {
|
|
38
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
39
|
+
match: function match(n) {
|
|
40
|
+
return getNodeType(n) === LINK;
|
|
41
|
+
},
|
|
42
|
+
universal: true
|
|
43
|
+
}),
|
|
44
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
45
|
+
match = _Editor$nodes2[0];
|
|
46
|
+
if (!match) return 'paragraph';
|
|
47
|
+
var _match = _slicedToArray(match, 1),
|
|
48
|
+
n = _match[0];
|
|
49
|
+
return getNodeType(n);
|
|
50
|
+
};
|
|
51
|
+
export var insertLink = function insertLink(editor, text, url) {
|
|
52
|
+
if (isMenuDisabled(editor)) return;
|
|
53
|
+
|
|
54
|
+
// Selection folded or not
|
|
55
|
+
var selection = editor.selection;
|
|
56
|
+
if (selection == null) return;
|
|
57
|
+
var isCollapsed = Range.isCollapsed(selection);
|
|
58
|
+
if (isCollapsed) {
|
|
59
|
+
// Insert Spaces before and after links for easy operation
|
|
60
|
+
editor.insertText(' ');
|
|
61
|
+
var linkNode = genLinkNode(url, text);
|
|
62
|
+
Transforms.insertNodes(editor, linkNode);
|
|
63
|
+
|
|
64
|
+
// Not being able to use insertText directly causes the added Spaces to be added to the linked text, as in the issue above, replaced by insertFragment
|
|
65
|
+
editor.insertFragment([{
|
|
66
|
+
text: ' '
|
|
67
|
+
}]);
|
|
68
|
+
} else {
|
|
69
|
+
var selectedText = Editor.string(editor, selection); // Selected text
|
|
70
|
+
if (selectedText !== text) {
|
|
71
|
+
// If the selected text is different from the typed text, delete the text and insert the link
|
|
72
|
+
editor.deleteFragment();
|
|
73
|
+
var _linkNode = genLinkNode(url, text);
|
|
74
|
+
Transforms.insertNodes(editor, _linkNode);
|
|
75
|
+
} else {
|
|
76
|
+
// If the selected text is the same as the entered text, only the link can be wrapped
|
|
77
|
+
var _linkNode2 = genLinkNode(url, text);
|
|
78
|
+
Transforms.wrapNodes(editor, _linkNode2, {
|
|
79
|
+
split: true
|
|
80
|
+
});
|
|
81
|
+
Transforms.collapse(editor, {
|
|
82
|
+
edge: 'end'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export var updateLink = function updateLink(editor, newText, newUrl) {
|
|
88
|
+
// Update children
|
|
89
|
+
var oldLink = getAboveNode(editor, {
|
|
90
|
+
match: {
|
|
91
|
+
type: 'link'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
if (oldLink) {
|
|
95
|
+
var _oldLink = _slicedToArray(oldLink, 2),
|
|
96
|
+
oldLinkNode = _oldLink[0],
|
|
97
|
+
oldLinkPath = _oldLink[1];
|
|
98
|
+
var oldUrl = oldLinkNode.href;
|
|
99
|
+
if (newText !== getEditorString(editor, oldLinkPath) || newUrl !== oldUrl) {
|
|
100
|
+
// Remove link children
|
|
101
|
+
removeNodeChildren(editor, oldLinkPath, {
|
|
102
|
+
select: true
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// insert link node
|
|
106
|
+
var linkNode = genLinkNode(newUrl, newText);
|
|
107
|
+
Transforms.insertNodes(editor, linkNode, {
|
|
108
|
+
select: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export var unWrapLinkNode = /*#__PURE__*/function () {
|
|
114
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(editor) {
|
|
115
|
+
var _Editor$nodes3, _Editor$nodes4, nodeEntry;
|
|
116
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
117
|
+
while (1) switch (_context.prev = _context.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
if (!(editor.selection == null)) {
|
|
120
|
+
_context.next = 2;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return _context.abrupt("return");
|
|
124
|
+
case 2:
|
|
125
|
+
_Editor$nodes3 = Editor.nodes(editor, {
|
|
126
|
+
match: function match(n) {
|
|
127
|
+
return getNodeType(n) === 'link';
|
|
128
|
+
},
|
|
129
|
+
universal: true
|
|
130
|
+
}), _Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1), nodeEntry = _Editor$nodes4[0]; // If the selection is not in a link node, it is disabled
|
|
131
|
+
if (!(nodeEntry == null || nodeEntry[0] == null)) {
|
|
132
|
+
_context.next = 5;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
return _context.abrupt("return");
|
|
136
|
+
case 5:
|
|
137
|
+
// unlink
|
|
138
|
+
Transforms.unwrapNodes(editor, {
|
|
139
|
+
match: function match(n) {
|
|
140
|
+
return getNodeType(n) === 'link';
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
case 6:
|
|
144
|
+
case "end":
|
|
145
|
+
return _context.stop();
|
|
146
|
+
}
|
|
147
|
+
}, _callee);
|
|
148
|
+
}));
|
|
149
|
+
return function unWrapLinkNode(_x) {
|
|
150
|
+
return _ref.apply(this, arguments);
|
|
151
|
+
};
|
|
152
|
+
}();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LINK } from '../../constants';
|
|
2
|
+
import LinkMenu from './menu';
|
|
3
|
+
import Link from './model';
|
|
4
|
+
import withLink from './plugin';
|
|
5
|
+
import renderLink from './render-elem';
|
|
6
|
+
var LinkPlugin = {
|
|
7
|
+
type: LINK,
|
|
8
|
+
nodeType: 'element',
|
|
9
|
+
model: Link,
|
|
10
|
+
editorMenus: [LinkMenu],
|
|
11
|
+
editorPlugin: withLink,
|
|
12
|
+
renderElements: [renderLink]
|
|
13
|
+
};
|
|
14
|
+
export default LinkPlugin;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React, { Fragment } from 'react';
|
|
6
|
+
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Alert } from 'reactstrap';
|
|
7
|
+
import { withTranslation } from 'react-i18next';
|
|
8
|
+
import { insertLink, updateLink, checkLink } from '../helpers';
|
|
9
|
+
var AddLinkDialog = /*#__PURE__*/function (_React$PureComponent) {
|
|
10
|
+
_inherits(AddLinkDialog, _React$PureComponent);
|
|
11
|
+
var _super = _createSuper(AddLinkDialog);
|
|
12
|
+
function AddLinkDialog(props) {
|
|
13
|
+
var _this;
|
|
14
|
+
_classCallCheck(this, AddLinkDialog);
|
|
15
|
+
_this = _super.call(this, props);
|
|
16
|
+
_this.handleUrlChange = function (event) {
|
|
17
|
+
_this.setState({
|
|
18
|
+
url: event.target.value.trim()
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
_this.handleTitleChange = function (event) {
|
|
22
|
+
_this.setState({
|
|
23
|
+
title: event.target.value.trim()
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
_this.handleSubmit = function (event) {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
_this.setState({
|
|
29
|
+
linkErrorMessage: '',
|
|
30
|
+
titleErrorMessage: ''
|
|
31
|
+
});
|
|
32
|
+
var t = _this.props.t;
|
|
33
|
+
var _this$state = _this.state,
|
|
34
|
+
_this$state$title = _this$state.title,
|
|
35
|
+
title = _this$state$title === void 0 ? '' : _this$state$title,
|
|
36
|
+
_this$state$url = _this$state.url,
|
|
37
|
+
url = _this$state$url === void 0 ? '' : _this$state$url;
|
|
38
|
+
if (url.length === 0) {
|
|
39
|
+
_this.setState({
|
|
40
|
+
linkErrorMessage: t('The_link_address_is_required')
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (title.length === 0) {
|
|
45
|
+
_this.setState({
|
|
46
|
+
titleErrorMessage: t('The_link_title_is_required')
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (checkLink(url)) {
|
|
51
|
+
_this.setState({
|
|
52
|
+
linkErrorMessage: t('The_link_address_is_invalid')
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
var _this$props = _this.props,
|
|
57
|
+
editor = _this$props.editor,
|
|
58
|
+
propsUrl = _this$props.url,
|
|
59
|
+
propsTitle = _this$props.title;
|
|
60
|
+
var isEdit = propsUrl && propsTitle;
|
|
61
|
+
if (isEdit) {
|
|
62
|
+
updateLink(editor, title, url);
|
|
63
|
+
} else {
|
|
64
|
+
insertLink(editor, title, url);
|
|
65
|
+
}
|
|
66
|
+
_this.props.onLinkDialogToggle();
|
|
67
|
+
};
|
|
68
|
+
_this.onKeyDown = function (e) {
|
|
69
|
+
if (e.keyCode === 13) {
|
|
70
|
+
_this.handleSubmit(e);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
_this.state = {
|
|
74
|
+
url: props.url,
|
|
75
|
+
title: props.title,
|
|
76
|
+
linkErrorMessage: '',
|
|
77
|
+
titleErrorMessage: ''
|
|
78
|
+
};
|
|
79
|
+
return _this;
|
|
80
|
+
}
|
|
81
|
+
_createClass(AddLinkDialog, [{
|
|
82
|
+
key: "render",
|
|
83
|
+
value: function render() {
|
|
84
|
+
var _this$props2 = this.props,
|
|
85
|
+
className = _this$props2.className,
|
|
86
|
+
t = _this$props2.t;
|
|
87
|
+
var _this$state2 = this.state,
|
|
88
|
+
_this$state2$url = _this$state2.url,
|
|
89
|
+
url = _this$state2$url === void 0 ? '' : _this$state2$url,
|
|
90
|
+
_this$state2$title = _this$state2.title,
|
|
91
|
+
title = _this$state2$title === void 0 ? '' : _this$state2$title,
|
|
92
|
+
linkErrorMessage = _this$state2.linkErrorMessage,
|
|
93
|
+
titleErrorMessage = _this$state2.titleErrorMessage;
|
|
94
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
95
|
+
isOpen: true,
|
|
96
|
+
autoFocus: false,
|
|
97
|
+
toggle: this.props.onLinkDialogToggle,
|
|
98
|
+
className: className,
|
|
99
|
+
zIndex: 1071,
|
|
100
|
+
returnFocusAfterClose: false
|
|
101
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, {
|
|
102
|
+
toggle: this.props.onLinkDialogToggle
|
|
103
|
+
}, t('insert_link')), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
104
|
+
className: "form-group"
|
|
105
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
106
|
+
className: "form-check-label",
|
|
107
|
+
htmlFor: "addLink"
|
|
108
|
+
}, t('link_address')), /*#__PURE__*/React.createElement("input", {
|
|
109
|
+
onKeyDown: this.onKeyDown,
|
|
110
|
+
autoFocus: true,
|
|
111
|
+
type: "url",
|
|
112
|
+
className: "form-control",
|
|
113
|
+
id: "addLink",
|
|
114
|
+
value: url,
|
|
115
|
+
onChange: this.handleUrlChange
|
|
116
|
+
}), linkErrorMessage && /*#__PURE__*/React.createElement(Alert, {
|
|
117
|
+
color: "danger",
|
|
118
|
+
className: "mt-2"
|
|
119
|
+
}, t(linkErrorMessage))), /*#__PURE__*/React.createElement("div", {
|
|
120
|
+
className: "form-group"
|
|
121
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
122
|
+
className: "form-check-label",
|
|
123
|
+
htmlFor: "addTitle"
|
|
124
|
+
}, t('link_title')), /*#__PURE__*/React.createElement("input", {
|
|
125
|
+
onKeyDown: this.onKeyDown,
|
|
126
|
+
type: "text",
|
|
127
|
+
className: "form-control",
|
|
128
|
+
id: "addTitle",
|
|
129
|
+
value: title,
|
|
130
|
+
onChange: this.handleTitleChange
|
|
131
|
+
}), titleErrorMessage && /*#__PURE__*/React.createElement(Alert, {
|
|
132
|
+
color: "danger",
|
|
133
|
+
className: "mt-2"
|
|
134
|
+
}, t(titleErrorMessage))))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
135
|
+
color: "secondary",
|
|
136
|
+
onClick: this.props.onLinkDialogToggle
|
|
137
|
+
}, t('cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
138
|
+
color: "primary",
|
|
139
|
+
disabled: false,
|
|
140
|
+
onClick: this.handleSubmit
|
|
141
|
+
}, t('add_link'))));
|
|
142
|
+
}
|
|
143
|
+
}]);
|
|
144
|
+
return AddLinkDialog;
|
|
145
|
+
}(React.PureComponent);
|
|
146
|
+
export default withTranslation('seafile-editor')(AddLinkDialog);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
import '../../../../assets/css/textlink-hovermenu.css';
|
|
8
|
+
var LinkHoverComponent = /*#__PURE__*/function (_React$Component) {
|
|
9
|
+
_inherits(LinkHoverComponent, _React$Component);
|
|
10
|
+
var _super = _createSuper(LinkHoverComponent);
|
|
11
|
+
function LinkHoverComponent() {
|
|
12
|
+
_classCallCheck(this, LinkHoverComponent);
|
|
13
|
+
return _super.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
_createClass(LinkHoverComponent, [{
|
|
16
|
+
key: "render",
|
|
17
|
+
value: function render() {
|
|
18
|
+
var _this$props = this.props,
|
|
19
|
+
menuPosition = _this$props.menuPosition,
|
|
20
|
+
href = _this$props.href;
|
|
21
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, createPortal( /*#__PURE__*/React.createElement("div", {
|
|
22
|
+
id: "loading",
|
|
23
|
+
className: "seafile-ed-hovermenu",
|
|
24
|
+
style: menuPosition
|
|
25
|
+
}, /*#__PURE__*/React.createElement("a", {
|
|
26
|
+
href: href,
|
|
27
|
+
target: "_blank",
|
|
28
|
+
rel: "noopener noreferrer",
|
|
29
|
+
className: "seafile-ed-hovermenu-link"
|
|
30
|
+
}, href), /*#__PURE__*/React.createElement("button", {
|
|
31
|
+
color: "",
|
|
32
|
+
className: "seafile-ed-hovermenu-btn",
|
|
33
|
+
onClick: this.props.onDeleteLink
|
|
34
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
35
|
+
className: "iconfont icon-delete"
|
|
36
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
37
|
+
color: "",
|
|
38
|
+
className: "seafile-ed-hovermenu-btn",
|
|
39
|
+
onClick: this.props.onEditLink
|
|
40
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
41
|
+
className: "iconfont icon-edit"
|
|
42
|
+
})), /*#__PURE__*/React.createElement("span", {
|
|
43
|
+
className: "seafile-ed-hovermenu-triangle"
|
|
44
|
+
})), document.body));
|
|
45
|
+
}
|
|
46
|
+
}]);
|
|
47
|
+
return LinkHoverComponent;
|
|
48
|
+
}(React.Component);
|
|
49
|
+
export default LinkHoverComponent;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { LINK, MENUS_CONFIG_MAP } from '../../../constants';
|
|
8
|
+
import { getEditorString } from '../../../core';
|
|
9
|
+
import { MenuItem } from '../../../menu';
|
|
10
|
+
import { getLinkType, isMenuDisabled } from '../helpers';
|
|
11
|
+
import AddLinkDialog from './add-link-dialog';
|
|
12
|
+
var LinkMenu = /*#__PURE__*/function (_React$Component) {
|
|
13
|
+
_inherits(LinkMenu, _React$Component);
|
|
14
|
+
var _super = _createSuper(LinkMenu);
|
|
15
|
+
function LinkMenu(props) {
|
|
16
|
+
var _this;
|
|
17
|
+
_classCallCheck(this, LinkMenu);
|
|
18
|
+
_this = _super.call(this, props);
|
|
19
|
+
_this.isActive = function () {
|
|
20
|
+
var editor = _this.props.editor;
|
|
21
|
+
return getLinkType(editor) === LINK;
|
|
22
|
+
};
|
|
23
|
+
_this.isDisabled = function () {
|
|
24
|
+
var editor = _this.props.editor;
|
|
25
|
+
return isMenuDisabled(editor);
|
|
26
|
+
};
|
|
27
|
+
_this.onLinkDialogToggle = function () {
|
|
28
|
+
_this.setState({
|
|
29
|
+
isShowLinkDialog: !_this.state.isShowLinkDialog
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
_this.onMouseDown = function () {
|
|
33
|
+
_this.onLinkDialogToggle();
|
|
34
|
+
};
|
|
35
|
+
_this.state = {
|
|
36
|
+
isShowLinkDialog: false
|
|
37
|
+
};
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
_createClass(LinkMenu, [{
|
|
41
|
+
key: "render",
|
|
42
|
+
value: function render() {
|
|
43
|
+
var _this$props = this.props,
|
|
44
|
+
isRichEditor = _this$props.isRichEditor,
|
|
45
|
+
className = _this$props.className,
|
|
46
|
+
editor = _this$props.editor;
|
|
47
|
+
var isShowLinkDialog = this.state.isShowLinkDialog;
|
|
48
|
+
var menuConfig = MENUS_CONFIG_MAP[LINK];
|
|
49
|
+
var props = _objectSpread(_objectSpread({
|
|
50
|
+
isRichEditor: isRichEditor,
|
|
51
|
+
className: className
|
|
52
|
+
}, menuConfig), {}, {
|
|
53
|
+
disabled: this.isDisabled(),
|
|
54
|
+
isActive: this.isActive(),
|
|
55
|
+
onMouseDown: this.onMouseDown
|
|
56
|
+
});
|
|
57
|
+
var selectedText = getEditorString(editor, editor.selection);
|
|
58
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MenuItem, props), isShowLinkDialog && /*#__PURE__*/React.createElement(AddLinkDialog, {
|
|
59
|
+
editor: editor,
|
|
60
|
+
title: selectedText,
|
|
61
|
+
onLinkDialogToggle: this.onLinkDialogToggle
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}]);
|
|
65
|
+
return LinkMenu;
|
|
66
|
+
}(React.Component);
|
|
67
|
+
export default LinkMenu;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import { LINK as LINKTRENAME } from '../../constants';
|
|
4
|
+
var Link = /*#__PURE__*/_createClass(function Link(options) {
|
|
5
|
+
_classCallCheck(this, Link);
|
|
6
|
+
this.type = options.type || LINKTRENAME;
|
|
7
|
+
this.children = options.children || [{
|
|
8
|
+
text: ''
|
|
9
|
+
}];
|
|
10
|
+
this.href = options.href || '';
|
|
11
|
+
this.title = options.title || '';
|
|
12
|
+
});
|
|
13
|
+
export default Link;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { Editor, Transforms, Node } from '@seafile/slate';
|
|
3
|
+
import isUrl from 'is-url';
|
|
4
|
+
import { isMenuDisabled, insertLink } from './helpers';
|
|
5
|
+
import { getNodeType } from '../../core';
|
|
6
|
+
var withLink = function withLink(editor) {
|
|
7
|
+
var normalizeNode = editor.normalizeNode,
|
|
8
|
+
isInline = editor.isInline,
|
|
9
|
+
insertData = editor.insertData;
|
|
10
|
+
var newEditor = editor;
|
|
11
|
+
|
|
12
|
+
// Rewrite isInline
|
|
13
|
+
newEditor.isInline = function (elem) {
|
|
14
|
+
var type = elem.type;
|
|
15
|
+
if (type === 'link') {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return isInline(elem);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Rewrite insertData, Paste insert link
|
|
22
|
+
newEditor.insertData = function (data) {
|
|
23
|
+
var text = data.getData('text/plain');
|
|
24
|
+
if (!isUrl(text)) {
|
|
25
|
+
// unlinked
|
|
26
|
+
insertData(data);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Insert link
|
|
31
|
+
if (isMenuDisabled(newEditor)) return; // disabled
|
|
32
|
+
var selection = newEditor.selection;
|
|
33
|
+
if (selection == null) return;
|
|
34
|
+
var selectedText = Editor.string(newEditor, selection); // Gets the selected text
|
|
35
|
+
insertLink(newEditor, selectedText, text);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Rewrite normalizeNode
|
|
39
|
+
newEditor.normalizeNode = function (_ref) {
|
|
40
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
41
|
+
node = _ref2[0],
|
|
42
|
+
path = _ref2[1];
|
|
43
|
+
var type = getNodeType(node);
|
|
44
|
+
if (type !== 'link') {
|
|
45
|
+
// If the type is not link, perform default normalizeNode
|
|
46
|
+
return normalizeNode([node, path]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If the link is empty, delete it
|
|
50
|
+
var str = Node.string(node);
|
|
51
|
+
if (str === '') {
|
|
52
|
+
return Transforms.removeNodes(newEditor, {
|
|
53
|
+
at: path
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return normalizeNode([node, path]);
|
|
57
|
+
};
|
|
58
|
+
return newEditor;
|
|
59
|
+
};
|
|
60
|
+
export default withLink;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { unWrapLinkNode } from './helpers';
|
|
7
|
+
import AddLinkDialog from './menu/add-link-dialog';
|
|
8
|
+
import LinkHoverComponent from './menu/hover-link-dialog';
|
|
9
|
+
var LinkHoverMenuComponent = /*#__PURE__*/function (_React$Component) {
|
|
10
|
+
_inherits(LinkHoverMenuComponent, _React$Component);
|
|
11
|
+
var _super = _createSuper(LinkHoverMenuComponent);
|
|
12
|
+
function LinkHoverMenuComponent(props) {
|
|
13
|
+
var _this;
|
|
14
|
+
_classCallCheck(this, LinkHoverMenuComponent);
|
|
15
|
+
_this = _super.call(this, props);
|
|
16
|
+
_this.registerEventHandle = function () {
|
|
17
|
+
document.addEventListener('click', _this.onHideLinkMenu);
|
|
18
|
+
};
|
|
19
|
+
_this.unregisterEventHandle = function () {
|
|
20
|
+
document.removeEventListener('click', _this.onHideLinkMenu);
|
|
21
|
+
};
|
|
22
|
+
_this.onHideLinkMenu = function () {
|
|
23
|
+
_this.setState({
|
|
24
|
+
isShowLinkMenu: false
|
|
25
|
+
}, function () {
|
|
26
|
+
_this.unregisterEventHandle();
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
_this.onLinkClick = function (e) {
|
|
30
|
+
var _e$target$getBounding = e.target.getBoundingClientRect(),
|
|
31
|
+
top = _e$target$getBounding.top,
|
|
32
|
+
left = _e$target$getBounding.left,
|
|
33
|
+
width = _e$target$getBounding.width;
|
|
34
|
+
// top = top distance - menu height
|
|
35
|
+
var menuTop = top - 50;
|
|
36
|
+
// left = left distance - (menu width / 2) + (link with / 2)
|
|
37
|
+
var menuLeft = left - 250 / 2 + width / 2;
|
|
38
|
+
_this.setState({
|
|
39
|
+
isShowLinkMenu: true,
|
|
40
|
+
menuPosition: {
|
|
41
|
+
top: menuTop,
|
|
42
|
+
left: menuLeft
|
|
43
|
+
}
|
|
44
|
+
}, function () {
|
|
45
|
+
_this.registerEventHandle();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
_this.onLinkDialogToggle = function () {
|
|
49
|
+
_this.setState({
|
|
50
|
+
isShowLinkDialog: !_this.state.isShowLinkDialog
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
_this.onEditToggle = function () {
|
|
54
|
+
_this.setState({
|
|
55
|
+
isShowLinkDialog: true
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
_this.deleteLink = function () {
|
|
59
|
+
var editor = _this.props.editor;
|
|
60
|
+
unWrapLinkNode(editor);
|
|
61
|
+
};
|
|
62
|
+
_this.state = {
|
|
63
|
+
isShowLinkMenu: false,
|
|
64
|
+
isShowLinkDialog: false
|
|
65
|
+
};
|
|
66
|
+
return _this;
|
|
67
|
+
}
|
|
68
|
+
_createClass(LinkHoverMenuComponent, [{
|
|
69
|
+
key: "componentWillUnmount",
|
|
70
|
+
value: function componentWillUnmount() {
|
|
71
|
+
this.unregisterEventHandle();
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "render",
|
|
75
|
+
value: function render() {
|
|
76
|
+
var _this$props = this.props,
|
|
77
|
+
attributes = _this$props.attributes,
|
|
78
|
+
children = _this$props.children,
|
|
79
|
+
element = _this$props.element,
|
|
80
|
+
editor = _this$props.editor;
|
|
81
|
+
var _this$state = this.state,
|
|
82
|
+
isShowLinkDialog = _this$state.isShowLinkDialog,
|
|
83
|
+
isShowLinkMenu = _this$state.isShowLinkMenu,
|
|
84
|
+
menuPosition = _this$state.menuPosition;
|
|
85
|
+
var className = isShowLinkMenu ? 'seafile-ed-hovermenu-mouseclick' : null;
|
|
86
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", Object.assign({
|
|
87
|
+
className: className
|
|
88
|
+
}, attributes, {
|
|
89
|
+
onClick: this.onLinkClick
|
|
90
|
+
}), /*#__PURE__*/React.createElement("a", {
|
|
91
|
+
href: element.href,
|
|
92
|
+
title: element.title
|
|
93
|
+
}, children)), isShowLinkDialog && /*#__PURE__*/React.createElement(AddLinkDialog, {
|
|
94
|
+
editor: editor,
|
|
95
|
+
url: element.href,
|
|
96
|
+
title: element.title,
|
|
97
|
+
onLinkDialogToggle: this.onLinkDialogToggle
|
|
98
|
+
}), isShowLinkMenu && /*#__PURE__*/React.createElement(LinkHoverComponent, {
|
|
99
|
+
menuPosition: menuPosition,
|
|
100
|
+
editor: editor,
|
|
101
|
+
href: element.href,
|
|
102
|
+
onEditLink: this.onEditToggle,
|
|
103
|
+
onDeleteLink: this.deleteLink
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
return LinkHoverMenuComponent;
|
|
108
|
+
}(React.Component);
|
|
109
|
+
var renderLink = function renderLink(props, editor) {
|
|
110
|
+
return /*#__PURE__*/React.createElement(LinkHoverMenuComponent, Object.assign({}, props, {
|
|
111
|
+
editor: editor
|
|
112
|
+
}));
|
|
113
|
+
};
|
|
114
|
+
export default renderLink;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
-
import { Editor, Element } from 'slate';
|
|
3
|
+
import { Editor, Element } from '@seafile/slate';
|
|
4
4
|
import { PARAGRAPH } from '../../constants';
|
|
5
5
|
import { getSelectedNodeByType } from '../../core';
|
|
6
6
|
import { toggleList } from './transforms';
|
|
@@ -6,7 +6,7 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import { MENUS_CONFIG_MAP, ORDERED_LIST, UNORDERED_LIST } from '../../../constants';
|
|
8
8
|
import { focusEditor } from '../../../core';
|
|
9
|
-
import { MenuItem } from '../../../menu
|
|
9
|
+
import { MenuItem } from '../../../menu';
|
|
10
10
|
import { getListType, isMenuDisabled, setListType } from '../helpers';
|
|
11
11
|
var ListMenu = /*#__PURE__*/function (_React$Component) {
|
|
12
12
|
_inherits(ListMenu, _React$Component);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import { Node, Element, Transforms, Path } from 'slate';
|
|
2
|
+
import { Node, Element, Transforms, Path } from '@seafile/slate';
|
|
3
3
|
import { LIST_ITEM, LIST_LIC, PARAGRAPH } from '../../../constants';
|
|
4
4
|
import { getChildren, getNode, getPreviousPath, match } from '../../../core';
|
|
5
5
|
import { getListTypes } from '../queries';
|