-
-
Notifications
You must be signed in to change notification settings - Fork 555
feat: Block quote #1563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Block quote #1563
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
createBlockSpecFromStronglyTypedTiptapNode, | ||
createStronglyTypedTiptapNode, | ||
} from "../../schema/index.js"; | ||
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js"; | ||
import { defaultProps } from "../defaultProps.js"; | ||
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js"; | ||
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js"; | ||
|
||
export const quotePropSchema = { | ||
...defaultProps, | ||
}; | ||
|
||
export const QuoteBlockContent = createStronglyTypedTiptapNode({ | ||
name: "quote", | ||
content: "inline*", | ||
group: "blockContent", | ||
|
||
addKeyboardShortcuts() { | ||
return { | ||
"Mod-Alt-q": () => { | ||
const blockInfo = getBlockInfoFromSelection(this.editor.state); | ||
if ( | ||
!blockInfo.isBlockContainer || | ||
blockInfo.blockContent.node.type.spec.content !== "inline*" | ||
) { | ||
return true; | ||
} | ||
|
||
return this.editor.commands.command( | ||
updateBlockCommand(this.options.editor, blockInfo.bnBlock.beforePos, { | ||
type: "quote", | ||
}) | ||
); | ||
}, | ||
}; | ||
}, | ||
|
||
parseHTML() { | ||
return [ | ||
{ tag: "div[data-content-type=" + this.name + "]" }, | ||
{ | ||
tag: "blockquote", | ||
node: "quote", | ||
}, | ||
]; | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
return createDefaultBlockDOMOutputSpec( | ||
this.name, | ||
"blockquote", | ||
{ | ||
...(this.options.domAttributes?.blockContent || {}), | ||
...HTMLAttributes, | ||
}, | ||
this.options.domAttributes?.inlineContent || {} | ||
); | ||
}, | ||
}); | ||
|
||
export const Quote = createBlockSpecFromStronglyTypedTiptapNode( | ||
QuoteBlockContent, | ||
quotePropSchema | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,11 @@ export type BlockNoteEditorOptions< | |
*/ | ||
setIdAttribute?: boolean; | ||
|
||
/** | ||
* A flag indicating whether to show the grey left border on nested blocks. | ||
*/ | ||
showNestingIndicator: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I'm not sure I like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this was a suggestion from @YousefED, but I may have misunderstood. You're right though, you can just do the same thing with CSS: .bn-block-group
.bn-block-group
.bn-block-outer:not([data-prev-depth-changed])::before {
border-left: none !important;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea was:
Don't feel to strong about this I'll let @nperez0111 decide. We could also defer the border-left change to a later moment (it might make sense to also indent the draghandle when we do this) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll revert the |
||
|
||
/** | ||
* The detection mode for showing the side menu - "viewport" always shows the | ||
* side menu for the block next to the mouse cursor, while "editor" only shows | ||
|
@@ -494,6 +499,7 @@ export class BlockNoteEditor< | |
// apply defaults | ||
const newOptions = { | ||
defaultStyles: true, | ||
showNestingIndicator: options.showNestingIndicator || true, | ||
schema: options.schema || BlockNoteSchema.create(), | ||
_headless: false, | ||
...options, | ||
|
@@ -651,7 +657,8 @@ export class BlockNoteEditor< | |
class: mergeCSSClasses( | ||
"bn-editor", | ||
newOptions.defaultStyles ? "bn-default-styles" : "", | ||
newOptions.domAttributes?.editor?.class || "" | ||
newOptions.domAttributes?.editor?.class || "", | ||
newOptions.showNestingIndicator ? "bn-show-nesting-indicator" : "" | ||
), | ||
}, | ||
transformPasted, | ||
|
Uh oh!
There was an error while loading. Please reload this page.