This commit is contained in:
55
node_modules/decap-cms-widget-markdown/dist/esm/MarkdownControl/plugins/Link.js
generated
vendored
Normal file
55
node_modules/decap-cms-widget-markdown/dist/esm/MarkdownControl/plugins/Link.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
function Link({
|
||||
type
|
||||
}) {
|
||||
return {
|
||||
commands: {
|
||||
toggleLink(editor, getUrl) {
|
||||
const selection = editor.value.selection;
|
||||
const isCollapsed = selection && selection.isCollapsed;
|
||||
if (editor.hasInline(type)) {
|
||||
const inlines = editor.value.inlines.toJSON();
|
||||
const link = inlines.find(item => item.type === type);
|
||||
const url = getUrl(link.data.url);
|
||||
if (url) {
|
||||
// replace the old link
|
||||
return editor.setInlines({
|
||||
data: {
|
||||
url
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// remove url if it was removed by the user
|
||||
return editor.unwrapInline(type);
|
||||
}
|
||||
} else {
|
||||
const url = getUrl();
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
return isCollapsed ? editor.insertInline({
|
||||
type,
|
||||
data: {
|
||||
url
|
||||
},
|
||||
nodes: [{
|
||||
object: 'text',
|
||||
text: url
|
||||
}]
|
||||
}) : editor.wrapInline({
|
||||
type,
|
||||
data: {
|
||||
url
|
||||
}
|
||||
}).moveToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
var _default = exports.default = Link;
|
||||
Reference in New Issue
Block a user