创建一个Tinymce插件:如何使元素可选且可编辑

发布于 2025-02-04 12:00:15 字数 540 浏览 5 评论 0 原文

我正在尝试为„ bootstrap卡“ 基本上基本上是”只是一个div元素。一旦用户单击我的新插件按钮,我该如何使已插入的卡可选卡当然可以编辑?奖励问题:;-)是否有任何关于Tinymce插件撰写的全面教程的建议?

I'm trying to author my very first plugin for tinymce. Now, how do I make an element selectable? With the official image-plugin for example the user can click on a already inserted image, it visually gets focused and the image-plugin-button gets focused as well - see gif. Let's say I want to write a plugin that inserts a „Bootstrap Card“ which basically is just a div element. How do I make an already inserted Card selectable plus of course editable once the users clicks my new plugin button? Bonus question: ;-) Any suggestion for a comprehensive tutorial on tinymce plugin authoring?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情徒 2025-02-11 12:00:15

首先要回答奖励问题,在Tinymce博客上有一篇文章浏览创建自己的Tinymce插件,示例是

本文中降低转换的HTML,在“将插件添加到编辑器”标题下,Shahed Nasser写下了将自定义插件按钮添加到中的步骤工具栏。在该标题下检查有关获取自定义工具栏图标启动和运行的更多信息。

对于Bootstrap卡项目问题 - 因此,听起来您的用户选择卡片时,您需要以下内容:

  1. 专注于文档中的现有卡,
  2. 使能够编辑,调整或修改卡片以获取他们想要在卡中写或表达的内容。

第一步是识别卡项。 Tinymce.html.domparser API具有一种方法,该方法将过滤编辑器中的特定节点,并允许您在匹配过滤器的任何节点上运行一个函数。您可以在此处找到API文档 -

这正达到我对做什么的知识的限制为了使您的自定义插件运行。

To answer the bonus question first, there is an article on the TinyMCE blog that walks through creating your own TinyMCE plugin, with the example being an HTML to Markdown transformation

In the article, under the "Add the plugin to the editor" heading, Shahed Nasser writes the steps for adding the custom plugin button to the toolbar. Check under that heading for more information on getting the custom toolbar icon up and running.

For the Bootstrap Card item question – so it sounds like when your users select the Card, you need the following:

  1. Focus on the existing cards in the document
  2. Enable the ability to edit, adjust, or modify the cards in to get what they want written or expressed in the card done.

The first step would be to identify the card items. The TinyMCE.html.DOMparser API has a method that will filter for a specific node within the editor, and allow you to run a function on any nodes that match the filter. You can find the API docs here - https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.html.domparser/#addNodeFilter

That's reaching the limits of my knowledge of what to do, hopefully the docs and article help give you the first steps to get your custom plugin going.

静待花开 2025-02-11 12:00:15

我正在开发与您所描述的类似的东西,并且发现此示例代码及其readme.md文件有用

使一个元素可选:

只需添加可满足的属性设置为false,这将使元素成为元素,并且它的内容是不可编辑的,因此您可以t在Tinymce编辑器中单击它的内部,然后编辑内容,但仅选择整个Div。

在选择元素时将插件按钮“ active”:

要定义插件按钮时使用“ statelector”:

import Dialog from './Dialog';

const plugin = (editor) => {
  editor.addButton("profCard", {
    text: "Profile Card",
    icon: false,
    stateSelector: ['div[data-prof-card]'],
    onclick: e => Dialog.open(e, editor)
  });
};

export default plugin;

政治主管是您在按钮应何时配置的选项
通过将其与CSS选择器一起提供一系列字符串,从而“活动”。
如果选择在编辑器中的元素上,与其中一个
数组中的选择器按钮将显示活跃。

我强烈建议在继续之前阅读整个读数文件。

I am developing something similar to what u described and I found this example code and its README.md file helpful

to make an element selectable:

just add contenteditable attribute set to false, which will make the element and it's content uneditable, so you can’t click inside of it in the TinyMCE editor and edit the contents, but only select the whole div.

to make plugin button "active" when element is selected :

when you want to define your plugin button use "stateSelector":

import Dialog from './Dialog';

const plugin = (editor) => {
  editor.addButton("profCard", {
    text: "Profile Card",
    icon: false,
    stateSelector: ['div[data-prof-card]'],
    onclick: e => Dialog.open(e, editor)
  });
};

export default plugin;

stateSelector is an option where you configure when the button should
appear “active” by giving it an array of strings with css selectors.
If the selection is on an element in the editor that matches one of
the selectors in the array the button will appear active.

I highly recommend reading the entire readme file before proceeding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文