我正在尝试根据我的需要自定义Quill编辑器.我设法实现并插入自定义墨迹,如https://quilljs.com/guides/cloning-medium-with-parchment/中所述但我需要编辑数据,这些数据附加到我的墨点,如链接的URL例如.Quill的默认实现显示链接的小"内联"编辑框.我想自己实现类似的东西,但只是不明白.我没有在文档和指南中找到任何暗示.阅读Quill的源代码,我无法弄清楚链接的编辑对话框的实现位置.任何起点都将非常感激.
我试过类似的东西。正确的做法应该是创建一个模块。不幸的是,正如您已经知道的那样,这并不像看起来那么容易。
让我向您指出一些有用的资源,它们对我理解如何为 quill 创建扩展有很大帮助。Quills 维护者正在策划很棒的羽毛笔列表。
我建议特别关注
这是我使用自定义 quill 模块对其进行的尝试。
const InlineBlot = Quill.import('blots/inline');
class NamedLinkBlot extends InlineBlot {
static create(value) {
const node = super.create(value);
node.setAttribute('href', value);
node.setAttribute('target', '_blank');
return node;
}
}
NamedLinkBlot.blotName = 'namedlink';
NamedLinkBlot.tagName = 'A';
Quill.register('formats/namedlink', NamedLinkBlot);
const Tooltip = Quill.import('ui/tooltip');
class NamedLinkTooltip extends Tooltip {
show() {
super.show();
this.root.classList.add('ql-editing');
}
}
NamedLinkTooltip.TEMPLATE = [
'<a class="ql-preview" target="_blank" href="about:blank"></a>',
'<input type="text" data-link="https://quilljs.com">',
'Url displayed',
'<input type="text" data-name="Link name">',
'<a class="ql-action"></a>',
'<a class="ql-remove"></a>',
].join('');
const QuillModule = Quill.import('core/module');
class NamedLinkModule extends QuillModule {
constructor(quill, options) {
super(quill, options);
this.tooltip = new NamedLinkTooltip(this.quill, options.bounds);
this.quill.getModule('toolbar').addHandler('namedlink', this.namedLinkHandler.bind(this));
}
namedLinkHandler(value) {
if (value) {
var range = this.quill.getSelection();
if (range == null || range.length === 0) return;
var preview = this.quill.getText(range);
this.tooltip.show();
}
}
}
Quill.register('modules/namedlink', NamedLinkModule);
const quill = new Quill('#editor', {
theme: 'snow',
modules: {
namedlink: {},
toolbar: {
container: [
'bold',
'link',
'namedlink'
]
}
}
});
Run Code Online (Sandbox Code Playgroud)
要查看工具提示:
需要解决的主要问题:
| 归档时间: |
|
| 查看次数: |
2986 次 |
| 最近记录: |