Skip to content

Commit c627113

Browse files
ZytenBreadGenie
andauthored
feat: add support for tiptap task-item (#179)
* feat: add support for tiptap task-item * fix: save state when task-item is updated in View mode * fix: disable task-list checkbox in View mode Issue ueberdosis/tiptap#3676 means changes in View mode will not be saved * fix: mock tiptap edit mode for task-list Will be made redundant once ueberdosis/tiptap#4044 is fixed * style(task-item): minor style changes * chore: format using prettier --------- Co-authored-by: Bread Genie <msuhailbh07@gmail.com>
1 parent 5c2917a commit c627113

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"@tiptap/extension-table-cell": "^2.0.2",
1212
"@tiptap/extension-table-header": "^2.0.2",
1313
"@tiptap/extension-table-row": "^2.0.2",
14+
"@tiptap/extension-task-item": "^2.0.2",
15+
"@tiptap/extension-task-list": "^2.0.2",
1416
"@tiptap/extension-text-align": "^2.0.2",
1517
"@tiptap/pm": "^2.0.2",
1618
"@tiptap/starter-kit": "^2.0.2",

wiki/public/js/editor.js

+19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Editor, InputRule } from "@tiptap/core";
1111
import Placeholder from "@tiptap/extension-placeholder";
1212
import TableHeader from "@tiptap/extension-table-header";
1313
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
14+
import TaskItem from "@tiptap/extension-task-item";
15+
import TaskList from "@tiptap/extension-task-list";
1416

1517
const CustomDocument = Document.extend({
1618
content: "heading block*",
@@ -47,6 +49,9 @@ const saveWikiPage = (draft = false) => {
4749
const isEmptyEditor = !!urlParams.get("newWiki");
4850

4951
const title = $(`.wiki-editor .ProseMirror h1`).html();
52+
// mock tiptap edit mode for task-list
53+
// will be made redundant once editor.getHTML() is used to load content for saving
54+
$('[data-type="taskList"] > li').attr("data-type", "taskItem");
5055
// markdown=1 tag is needed for older wiki content to properly render
5156
// TODO: use editor.getHTML() instead of this when ueberdosis/tiptap#4044 is fixed
5257
const content = `<div markdown="1">${$(".editor-space .ProseMirror")
@@ -110,6 +115,13 @@ const editor = new Editor({
110115
CodeBlockLowlight.configure({
111116
lowlight,
112117
}),
118+
TaskList,
119+
TaskItem.configure({
120+
nested: true,
121+
//Save state when task-item is updated in View mode
122+
//TODO: Enable once ueberdosis/tiptap#3676 is fixed
123+
//onReadOnlyChecked: () => true,
124+
}),
113125
],
114126
inputRules: [disableMarkdownShortcut("#", "#")],
115127
content: getContent(),
@@ -409,3 +421,10 @@ $(".edit-wiki-btn").on("click", () => {
409421
editor.commands.setContent(getContent());
410422
editor.commands.focus("start");
411423
});
424+
425+
// TODO: Remove once ueberdosis/tiptap#3676 is fixed
426+
$("ul[data-type=taskList] input[type=checkbox]").click(function () {
427+
const urlParams = new URLSearchParams(window.location.search);
428+
429+
if (!urlParams.get("newWiki") && !urlParams.get("editWiki")) return false;
430+
});

wiki/public/scss/edit_wiki.scss

+47
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ $font-sizes-mobile: (
487487
code {
488488
padding: 0.75rem 1rem;
489489
}
490+
491+
// tiptap task-list
492+
ul[data-type="taskList"] p {
493+
margin: 0 !important;
494+
}
490495
}
491496

492497
// button
@@ -501,3 +506,45 @@ $font-sizes-mobile: (
501506
background-color: #0b5ed7;
502507
border-color: #0a58ca;
503508
}
509+
510+
// tiptap task-list
511+
ul[data-type="taskList"] {
512+
list-style: none;
513+
padding: 0;
514+
515+
p {
516+
margin: 0;
517+
}
518+
519+
li {
520+
display: flex;
521+
522+
> label {
523+
flex: 0 0 auto;
524+
margin-right: 0.25rem;
525+
margin-bottom: 0;
526+
user-select: none;
527+
}
528+
529+
> div {
530+
flex: 1 1 auto;
531+
}
532+
533+
ul li,
534+
ol li {
535+
display: list-item;
536+
}
537+
538+
ul[data-type="taskList"] > li {
539+
display: flex;
540+
}
541+
542+
input {
543+
color: #000;
544+
margin: .1rem;
545+
margin-top: 0.4rem;
546+
border: 1.25px solid black;
547+
accent-color: black;
548+
}
549+
}
550+
}

wiki/public/scss/wiki.scss

+4
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ body.dark {
651651
h2 {
652652
margin-top: 2.5rem;
653653
}
654+
655+
ul[data-type="taskList"] input {
656+
margin-top: 0;
657+
}
654658
}
655659
@include media-breakpoint-down(md) {
656660
width: auto;

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@
181181
resolved "https://registry.yarnpkg.com/@tiptap/extension-table/-/extension-table-2.0.2.tgz#b6cf7c78643e18a38f01cf1e9beded76470da7d0"
182182
integrity sha512-0HUpCQ+roTZqgMDtKQfgq8Yjo5SSxUJc+lMVHqcdeW2UwPkwXfAPCZ0ojle8SyQgQjv6GTcVTssvzq7+HGpd0Q==
183183

184+
"@tiptap/extension-task-item@^2.0.2":
185+
version "2.1.8"
186+
resolved "https://registry.yarnpkg.com/@tiptap/extension-task-item/-/extension-task-item-2.1.8.tgz#2036360be6702ab753cbc77b60ab24fb33ff20a6"
187+
integrity sha512-PoY2PDiYEQC44qDQLubzDuhZ3f6OL7sui89960M1HUQR2URnPvToOBaa5veNY8VyACdAolm+LwTpseBKKkcpmw==
188+
189+
"@tiptap/extension-task-list@^2.0.2":
190+
version "2.1.8"
191+
resolved "https://registry.yarnpkg.com/@tiptap/extension-task-list/-/extension-task-list-2.1.8.tgz#993c415d85d414039baf7379df7c3b19b1d342d9"
192+
integrity sha512-PmEPJHTOgy0AveE6YoxY6w09+bh5OqkrMI/sluY88291cnSPPEf9sFWmBHOrONNj54Ti6ua37arudUY5mqxOCA==
193+
184194
"@tiptap/extension-text-align@^2.0.2":
185195
version "2.0.2"
186196
resolved "https://registry.yarnpkg.com/@tiptap/extension-text-align/-/extension-text-align-2.0.2.tgz#1e688d9aa555e3d51b946a1e8e01d290b07c281a"

0 commit comments

Comments
 (0)