Skip to content

Commit

Permalink
fix(editor): allow users to turn list items into task list items (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Jul 4, 2021
1 parent a72ab5d commit 26efc12
Show file tree
Hide file tree
Showing 3 changed files with 458 additions and 456 deletions.
42 changes: 21 additions & 21 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
"@emotion/react": "^11.4.0",
"@material-ui/core": "^4.11.4",
"@material-ui/icons": "^4.11.2",
"@remirror/core": "0.0.0-pr706.35",
"@remirror/core-utils": "0.0.0-pr706.35",
"@remirror/dev": "0.0.0-pr706.35",
"@remirror/extension-blockquote": "0.0.0-pr706.35",
"@remirror/extension-codemirror5": "0.0.0-pr706.35",
"@remirror/extension-doc": "0.0.0-pr706.35",
"@remirror/extension-hard-break": "0.0.0-pr706.35",
"@remirror/extension-heading": "0.0.0-pr706.35",
"@remirror/extension-horizontal-rule": "0.0.0-pr706.35",
"@remirror/extension-list": "0.0.0-pr706.35",
"@remirror/extension-paragraph": "0.0.0-pr706.35",
"@remirror/extension-placeholder": "0.0.0-pr706.35",
"@remirror/extension-react-component": "0.0.0-pr706.35",
"@remirror/extension-tables": "0.0.0-pr706.35",
"@remirror/extension-text": "0.0.0-pr706.35",
"@remirror/pm": "0.0.0-pr706.35",
"@remirror/preset-core": "0.0.0-pr706.35",
"@remirror/react": "0.0.0-pr706.35",
"@remirror/react-core": "0.0.0-pr706.35",
"@remirror/styles": "0.0.0-pr706.35",
"@remirror/core": "0.0.0-pr993.1",
"@remirror/core-utils": "0.0.0-pr993.1",
"@remirror/dev": "0.0.0-pr993.1",
"@remirror/extension-blockquote": "0.0.0-pr993.1",
"@remirror/extension-codemirror5": "0.0.0-pr993.1",
"@remirror/extension-doc": "0.0.0-pr993.1",
"@remirror/extension-hard-break": "0.0.0-pr993.1",
"@remirror/extension-heading": "0.0.0-pr993.1",
"@remirror/extension-horizontal-rule": "0.0.0-pr993.1",
"@remirror/extension-list": "0.0.0-pr993.1",
"@remirror/extension-paragraph": "0.0.0-pr993.1",
"@remirror/extension-placeholder": "0.0.0-pr993.1",
"@remirror/extension-react-component": "0.0.0-pr993.1",
"@remirror/extension-tables": "0.0.0-pr993.1",
"@remirror/extension-text": "0.0.0-pr993.1",
"@remirror/pm": "0.0.0-pr993.1",
"@remirror/preset-core": "0.0.0-pr993.1",
"@remirror/react": "0.0.0-pr993.1",
"@remirror/react-core": "0.0.0-pr993.1",
"@remirror/styles": "0.0.0-pr993.1",
"@rino.app/common": "workspace:0.0.0",
"clsx": "^1.1.1",
"codemirror": "^5.62.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"commonmark-spec": "^0.30.0",
"jest": "^27.0.6",
"jest-extended": "^0.11.5",
"jest-remirror": "0.0.0-pr706.35",
"jest-remirror": "0.0.0-pr993.1",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
70 changes: 36 additions & 34 deletions packages/editor/src/extensions/list/__test__/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const setup = () => {
new RinoListItemSharedExtension(),
new RinoTaskListExtension(),
]
const result = renderEditor(extensions, {
const editor = renderEditor(extensions, {
core: {
// Remove `gapCursor` from `CorePreset` since it will cache the click event and cause some error.
excludeExtensions: ["gapCursor", "paragraph", "text"],
Expand All @@ -34,7 +34,7 @@ const setup = () => {
attributeNodes: { taskListItem, bulletList },
manager,
schema,
} = result
} = editor

const checked = taskListItem({ checked: true })
const unchecked = taskListItem({ checked: false })
Expand All @@ -52,6 +52,7 @@ const setup = () => {
taskList,
checked,
unchecked,
taskListItem,
hardBreak,
}
}
Expand Down Expand Up @@ -290,7 +291,7 @@ describe("toMarkdown", () => {
})

describe("inputRules", () => {
const { add, doc, p, bulletList, orderedList, listItem } = setup()
const { add, doc, p, bulletList, orderedList, listItem, taskListItem, taskList } = setup()

test("ol", () => {
add(doc(p("1.<cursor>")))
Expand Down Expand Up @@ -322,38 +323,39 @@ describe("inputRules", () => {
})
})

// const testCheckbox = (checked: boolean) =>
// test(`checkbox ${checked}`, () => {
// add(doc(p("-<cursor>")))
// .callback((content) => {
// expect(content.state.doc).toEqualRemirrorDocument(doc(p("-")))
// })
// .insertText(" ")
// .callback((content) => {
// expect(content.state.doc).toEqualRemirrorDocument(doc(bulletList({ bullet: "-" })(listItem(p("")))))
// })
// .insertText(checked ? "[x]" : "[ ]")
// .callback((content) => {
// expect(content.state.doc).toEqualRemirrorDocument(
// doc(bulletList({ bullet: "-" })(listItem(p(checked ? "[x]" : "[ ]")))),
// )
// })
// .insertText(" ")
// .callback((content) => {
// expect(content.state.doc).toEqualRemirrorDocument(
// doc(bulletList({ bullet: "-" })(listItem(rinoCheckbox({ checked: checked })(), p("")))),
// )
// })
// .insertText("INSERT")
// .callback((content) => {
// expect(content.state.doc).toEqualRemirrorDocument(
// doc(bulletList({ bullet: "-" })(listItem(rinoCheckbox({ checked: checked })(), p("INSERT")))),
// )
// })
// })
const testCheckbox = (checked: boolean) =>
test(`checkbox ${checked}`, () => {
add(doc(p("-<cursor>")))
.callback((content) => {
expect(content.state.doc).toEqualRemirrorDocument(doc(p("-")))
})
.insertText(" ")
.callback((content) => {
expect(content.state.doc).toEqualRemirrorDocument(doc(bulletList({ bullet: "-" })(listItem(p("")))))
})
.insertText(checked ? "[x]" : "[ ]")
.callback((content) => {
expect(content.state.doc).toEqualRemirrorDocument(
doc(bulletList({ bullet: "-" })(listItem(p(checked ? "[x]" : "[ ]")))),
)
})
.insertText(" ")
.callback((content) => {
expect(content.state.doc).toEqualRemirrorDocument(doc(taskList(taskListItem({ checked })(p("")))))
})
.insertText("- ")
.callback((content) => {
// make sure it won't turn to a bullet list item
expect(content.state.doc).toEqualRemirrorDocument(doc(taskList(taskListItem({ checked })(p("- ")))))
})
.insertText("INSERT")
.callback((content) => {
expect(content.state.doc).toEqualRemirrorDocument(doc(taskList(taskListItem({ checked })(p("- INSERT")))))
})
})

// testCheckbox(true)
// testCheckbox(false)
testCheckbox(true)
testCheckbox(false)
})

describe("shortcuts", () => {
Expand Down
Loading

0 comments on commit 26efc12

Please sign in to comment.