Skip to content

Commit 8426926

Browse files
authored
feat: Add text color from list of options (#48)
1 parent 733bd84 commit 8426926

File tree

10 files changed

+290
-91
lines changed

10 files changed

+290
-91
lines changed

djangocms_text/editors.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ def default(self, obj):
7070
+ ' <path d="m4.266 12.496.96-2.853H8.76l.96 2.853H11L7.62 3H6.38L3 12.496zm2.748-8.063 1.419 4.23h-2.88l1.426-4.23zm5.132-1.797v-.075c0-.332.234-.618.619-.618.354 0 .618.256.618.58 0 .362-.271.649-.52.898l-1.788 1.832V6h3.59v-.958h-1.923v-.045l.973-1.04c.415-.438.867-.845.867-1.547 0-.8-.701-1.41-1.787-1.41C11.565 1 11 1.8 11 2.576v.06z"/>\n'
7171
+ "</svg>",
7272
},
73+
"TextColor": {
74+
"title": _("Text color"),
75+
},
76+
"InlineQuote": {
77+
"title": _("Inline quote"),
78+
},
79+
"Highlight": {
80+
"title": _("Mark"),
81+
},
7382
"RemoveFormat": {
7483
"title": _("Remove formatting"),
7584
"icon": '<svg width="16" height="16" fill="currentColor" viewBox="0 0 16 16" '
@@ -149,17 +158,6 @@ def default(self, obj):
149158
"Link": {
150159
"title": _("Link"),
151160
"form": [
152-
# {
153-
# "type": "link",
154-
# "url": '#',
155-
# "label": '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" '
156-
# 'class="bi bi-box-arrow-up-left" viewBox="0 0 16 16">'
157-
# '<path fill-rule="evenodd" d="M7.364 3.5a.5.5 0 0 1 .5-.5H14.5A1.5 1.5 0 0 1 16 4.5v10a1.5 '
158-
# '1.5 0 0 1-1.5 1.5h-10A1.5 1.5 0 0 1 3 14.5V7.864a.5.5 0 1 1 1 0V14.5a.5.5 0 0 0 .5.5h10a.5.5 '
159-
# '0 0 0 .5-.5v-10a.5.5 0 0 0-.5-.5H7.864a.5.5 0 0 1-.5-.5"/><path fill-rule="evenodd" '
160-
# 'd="M0 .5A.5.5 0 0 1 .5 0h5a.5.5 0 0 1 0 1H1.707l8.147 8.146a.5.5 0 0 1-.708.708L1 '
161-
# '1.707V5.5a.5.5 0 0 1-1 0z"/></svg>',
162-
# },
163161
{
164162
"name": "href_select",
165163
"type": "hidden",
@@ -316,12 +314,10 @@ def default(self, obj):
316314
"title": _("Anchor"),
317315
},
318316
"Format": {
319-
"title": _("Block format"),
320-
"class": "vertical",
317+
"title": _("Format"),
321318
},
322319
"Styles": {
323320
"title": _("Styles"),
324-
"menu": [],
325321
},
326322
"Font": {
327323
"title": _("Font"),
@@ -371,13 +367,14 @@ def default(self, obj):
371367
["Undo", "Redo"],
372368
["CMSPlugins", "cmswidget", "-", "ShowBlocks"],
373369
["Format", "Styles"],
374-
["TextColor", "BGColor", "-", "PasteText", "PasteFromWord"],
370+
["TextColor", "Highlight", "BGColor", "-", "PasteText", "PasteFromWord"],
375371
["Maximize"],
376372
[
377373
"Bold",
378374
"Italic",
379375
"Underline",
380376
"-",
377+
"InlineQuote",
381378
"Code",
382379
"-",
383380
"Subscript",
@@ -396,13 +393,14 @@ def default(self, obj):
396393
["Undo", "Redo"],
397394
["ShowBlocks"],
398395
["Format", "Styles"],
399-
["TextColor", "BGColor", "-", "PasteText", "PasteFromWord"],
396+
["TextColor", "Highlight", "BGColor", "-", "PasteText", "PasteFromWord"],
400397
["Maximize"],
401398
[
402399
"Bold",
403400
"Italic",
404401
"Underline",
405402
"-",
403+
"InlineQuote",
406404
"Code",
407405
"-",
408406
"Subscript",
@@ -512,7 +510,7 @@ def get_editor_base_config(editor: Optional[str] = None) -> dict:
512510
name="tiptap",
513511
config="TIPTAP",
514512
js=("djangocms_text/bundles/bundle.tiptap.min.js",),
515-
css={"all": ("djangocms_text/css/bundle.tiptap.min.css",)},
513+
css={"all": ("djangocms_text/css/bundle.tiptap.min.css", "djangocms_text/css/tiptap.admin.css")},
516514
inline_editing=True,
517515
child_plugin_support=True,
518516
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
.cms-admin {
2+
.text-secondary {
3+
color: gray;
4+
}
5+
6+
.text-primary {
7+
color: mediumblue;
8+
}
9+
10+
.text-success {
11+
color: green;
12+
}
13+
14+
.text-danger {
15+
color: red;
16+
}
17+
18+
.text-warning {
19+
color: orange;
20+
}
21+
22+
.text-info {
23+
color: deepskyblue;
24+
}
25+
26+
.text-light {
27+
color: lightgrey;
28+
}
29+
30+
.text-dark {
31+
color: black;
32+
}
33+
34+
.text-body {
35+
color: var(--body-fg);
36+
}
37+
38+
.text-muted {
39+
color: dimgrey;
40+
}
41+
42+
.text-secondary {
43+
color: gray;
44+
}
45+
46+
.bg-primary {
47+
background-color: mediumblue;
48+
}
49+
50+
.bg-success {
51+
background-color: green;
52+
}
53+
54+
.bg-danger {
55+
background-color: red;
56+
}
57+
58+
.bg-warning {
59+
background-color: orange;
60+
}
61+
62+
.bg-info {
63+
background-color: deepskyblue;
64+
}
65+
66+
.bg-light {
67+
background-color: lightgrey;
68+
}
69+
70+
.bg-dark {
71+
background-color: black;
72+
}
73+
74+
.bg-body {
75+
background-color: var(--body-bg);
76+
}
77+
}

djangocms_text_ckeditor/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
1010
"djangocms_text_ckeditor.widgets.TextEditorWidget is deprecated. "
1111
"Use djangocms_text.widgets.TextEditorWidget instead.",
1212
DeprecationWarning,
13-
stacklevel=2,
13+
stacklevel=3,
1414
)
1515
super().__init__(*args, **kwargs)

private/css/cms.toolbar.css

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
&:active, &.active {
137137
background: var(--dca-gray-lighter, var(--selected-bg)) !important;
138138
}
139-
&:hover:not(:disabled),&.show {
139+
&:hover:not(:disabled):not([data-action="TextColor"]),&.show {
140140
color: var(--dca-white, var(--button-fg)) !important;
141141
background: var(--dca-primary, var(--button-bg)) !important;
142142
}
@@ -151,9 +151,28 @@
151151
&:after{
152152
content: "▼";
153153
margin-block-start: 3px;
154-
margin-inline-start: 6px;
154+
margin-inline-start: 2px;
155+
margin-inline-end: 4px;
155156
font-size: 0.8rem;
156157
}
158+
span {
159+
margin-top: 0.1rem;
160+
}
161+
&:has([data-action="TextColor"]) > svg {
162+
border-bottom: 2px solid currentColor;
163+
}
164+
button[data-action="TextColor"] {
165+
background: currentColor;
166+
border: 1px solid var(--dca-gray-lighter, var(--hairline-color)) !important;
167+
margin-inline-end: 0.5rem;
168+
width: 1.6rem !important;
169+
height: 1.2rem;
170+
&:hover, &.active {
171+
background-color: currentColor !important;
172+
outline: 3px solid var(--dca-primary, var(--primary));
173+
};
174+
175+
}
157176
}
158177
svg {
159178
display: inline;
@@ -306,6 +325,4 @@
306325
}
307326
}
308327
}
309-
310328
}
311-

private/js/cms.tiptap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import TableRow from '@tiptap/extension-table-row';
1919
import {TextAlign, TextAlignOptions} from '@tiptap/extension-text-align';
2020
import TiptapToolbar from "./tiptap_plugins/cms.tiptap.toolbar";
2121

22-
import {InlineColors, Small, Var, Kbd, Samp} from "./tiptap_plugins/cms.styles";
22+
import {TextColor, Small, Var, Kbd, Samp, Highlight, InlineQuote} from "./tiptap_plugins/cms.styles";
2323
import CmsFormExtension from "./tiptap_plugins/cms.formextension";
2424
import CmsToolbarPlugin from "./tiptap_plugins/cms.toolbar";
2525

@@ -35,7 +35,7 @@ class CMSTipTapPlugin {
3535
Underline,
3636
CharacterCount,
3737
Image,
38-
InlineColors,
38+
TextColor,
3939
Placeholder,
4040
Subscript,
4141
Superscript,
@@ -49,7 +49,7 @@ class CMSTipTapPlugin {
4949
TableHeader,
5050
TableCell,
5151
CmsDynLink,
52-
Small, Var, Kbd, Samp,
52+
Small, Var, Kbd, Samp, Highlight, InlineQuote,
5353
TextAlign.configure({
5454
types: ['heading', 'paragraph'],
5555
}),

private/js/tiptap_plugins/cms.dynlink.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ function DynLinkClickHandler(editor) {
1111
return new Plugin({
1212
props: {
1313
handleDOMEvents: {
14-
click(view, event) {
15-
console.log(view);
14+
click (view, event) {
15+
const target = event.target.closest('a[href]');
16+
if (target) {
17+
event.preventDefault();
18+
return true;
19+
}
20+
return false;
21+
},
22+
dblclick(view, event) {
1623
const target = event.target.closest('a[href]');
1724
if (target) {
1825
event.preventDefault();

0 commit comments

Comments
 (0)