diff --git a/djangocms_text/editors.py b/djangocms_text/editors.py index b7fdffb..212c9bc 100644 --- a/djangocms_text/editors.py +++ b/djangocms_text/editors.py @@ -320,6 +320,12 @@ def default(self, obj): "Styles": { "title": _("Styles"), }, + "InlineStyles": { + "title": _("Styles"), + }, + "BlockStyles": { + "title": _("Blocks"), + }, "Font": { "title": _("Font"), }, @@ -367,7 +373,7 @@ def default(self, obj): DEFAULT_TOOLBAR_CMS = [ ["Undo", "Redo"], ["CMSPlugins", "cmswidget", "-", "ShowBlocks"], - ["Format", "Styles"], + ["Format", "Styles", "BlockStyles", "InlineStyles"], ["TextColor", "Highlight", "BGColor", "-", "PasteText", "PasteFromWord"], ["Maximize"], [ @@ -393,7 +399,7 @@ def default(self, obj): DEFAULT_TOOLBAR_HTMLField = [ ["Undo", "Redo"], ["ShowBlocks"], - ["Format", "Styles"], + ["Format", "Styles", "BlockStyles", "InlineStyles"], ["TextColor", "Highlight", "BGColor", "-", "PasteText", "PasteFromWord"], ["Maximize"], [ @@ -439,7 +445,7 @@ def __init__( config: str, js: Iterable[str] | None = None, css: dict | None = None, - admin_css: dict | None = None, + admin_css: Iterable[str] | None = None, inline_editing: bool = False, child_plugin_support: bool = False, ): diff --git a/private/js/cms.tiptap.js b/private/js/cms.tiptap.js index fc5c92c..d62e338 100644 --- a/private/js/cms.tiptap.js +++ b/private/js/cms.tiptap.js @@ -19,7 +19,7 @@ import TableRow from '@tiptap/extension-table-row'; import {TextAlign, TextAlignOptions} from '@tiptap/extension-text-align'; import TiptapToolbar from "./tiptap_plugins/cms.tiptap.toolbar"; -import {TextColor, Small, Var, Kbd, Samp, Highlight, InlineQuote} from "./tiptap_plugins/cms.styles"; +import {TextColor, Highlight, InlineQuote, InlineStyle, BlockStyle} from "./tiptap_plugins/cms.styles"; import CmsFormExtension from "./tiptap_plugins/cms.formextension"; import CmsToolbarPlugin from "./tiptap_plugins/cms.toolbar"; @@ -49,7 +49,8 @@ class CMSTipTapPlugin { TableHeader, TableCell, CmsDynLink, - Small, Var, Kbd, Samp, Highlight, InlineQuote, + Highlight, InlineQuote, + InlineStyle, BlockStyle, TextAlign.configure({ types: ['heading', 'paragraph'], }), @@ -119,6 +120,9 @@ class CMSTipTapPlugin { save_callback: save_callback, settings: settings, toolbar: options.toolbar || options.toolbar_HTMLField, + inlineStyles: options.inlineStyles, + blockStyles: options.blockStyles, + textColors: options.textColors, separator_markup: this.separator_markup, space_markup: this.space_markup, }); diff --git a/private/js/tiptap_plugins/cms.dynlink.js b/private/js/tiptap_plugins/cms.dynlink.js index bbda49e..e82a0ed 100644 --- a/private/js/tiptap_plugins/cms.dynlink.js +++ b/private/js/tiptap_plugins/cms.dynlink.js @@ -41,7 +41,6 @@ function DynLinkClickHandler(editor) { const CmsDynLink = Link.extend({ addAttributes() { - 'use strict'; return { 'data-cms-href': { default: null diff --git a/private/js/tiptap_plugins/cms.plugin.js b/private/js/tiptap_plugins/cms.plugin.js index cfca2e8..bbdff1b 100644 --- a/private/js/tiptap_plugins/cms.plugin.js +++ b/private/js/tiptap_plugins/cms.plugin.js @@ -127,6 +127,9 @@ TiptapToolbar.CMSPlugins.render = renderCmsPluginMenu; // Common node properties for both inline and block nodes const cmsPluginNodes = { + atom: true, + draggable: true, + addAttributes() { 'use strict'; return { @@ -144,10 +147,6 @@ const cmsPluginNodes = { }; }, - atom: true, - - draggable: true, - parseHTML() { 'use strict'; return [ diff --git a/private/js/tiptap_plugins/cms.styles.js b/private/js/tiptap_plugins/cms.styles.js index a1d13e2..7eb27be 100644 --- a/private/js/tiptap_plugins/cms.styles.js +++ b/private/js/tiptap_plugins/cms.styles.js @@ -2,21 +2,19 @@ /* jshint esversion: 11 */ /* global document, window, console */ +'use strict'; -import {Mark, mergeAttributes,} from '@tiptap/core'; +import {Mark, Node, mergeAttributes} from '@tiptap/core'; +import TiptapToolbar from "./cms.tiptap.toolbar"; const _markElement = { addOptions() { - 'use strict'; - return { HTMLAttributes: {}, }; }, parseHTML() { - 'use strict'; - return [ { tag: this.name.toLowerCase() @@ -28,7 +26,6 @@ const _markElement = { }, addCommands() { - 'use strict'; let commands = {}; commands[`set${this.name}`] = () => ({ commands }) => { @@ -44,26 +41,6 @@ const _markElement = { }, }; -const Small = Mark.create({ - name: 'Small', - ..._markElement, -}); - -const Kbd = Mark.create({ - name: 'Kbd', - ..._markElement, -}); - -const Var = Mark.create({ - name: 'Var', - ..._markElement, -}); - -const Samp = Mark.create({ - name: 'Samp', - ..._markElement, -}); - const InlineQuote = Mark.create({ name: 'Q', ..._markElement, @@ -72,7 +49,6 @@ const InlineQuote = Mark.create({ const Highlight = Mark.create({ name: 'Highlight', parseHTML() { - 'use strict'; return [{tag: 'mark'}]; }, renderHTML({ HTMLAttributes }) { @@ -80,10 +56,20 @@ const Highlight = Mark.create({ }, }); + +function renderColorMenu(editor) { + const items = []; + for (const [cls, def] of Object.entries(editor.options?.textColors || TextColor.options.textColors)) { + items.push(``); + } + return items.join(''); + +} + const TextColor = Mark.create({ name: 'textcolor', addOptions() { - 'use strict'; + console.log(this.editor); return { textColors: { 'text-primary': {name: "Primary"}, @@ -100,30 +86,18 @@ const TextColor = Mark.create({ }; }, - onCreate() { - 'use strict'; - - if (this.editor.options.textColors) { - // Let editor options overwrite the default colors - this.options.textColors = this.editor.options.textColors; - } - }, - addAttributes() { - 'use strict'; - return { - class: { - default: null, - }, - style: { - default: null, - } + class: { default: null }, + style: { default: null} }; }, parseHTML() { - 'use strict'; + if (this.editor.options.textColors) { + // Let editor options overwrite the default colors + this.options.textColors = this.editor.options.textColors; + } return [ { @@ -150,12 +124,10 @@ const TextColor = Mark.create({ }, renderHTML: attributes => { - 'use strict'; return ['span', mergeAttributes({}, attributes.HTMLAttributes), 0]; }, addCommands() { - 'use strict'; return { setTextColor: (cls) => ({commands}) => { if (!(cls in this.options.textColors)) { @@ -182,4 +154,226 @@ const TextColor = Mark.create({ } }); -export {TextColor, Small, Var, Kbd, Samp, Highlight, InlineQuote, TextColor as default}; + +const blockTags = ((str) => str.toUpperCase().substring(1, str.length-1).split("><"))( + "