snapshot of https://github.com/ueberdosis/tiptap.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Verify / Install node dependencies (push) Failing after 2s
Verify / Build packages (push) Has been skipped
Verify / Check linting & formatting (push) Has been skipped
Verify / Run unit tests (push) Has been skipped
Verify / Run e2e tests (shard 1/4) (push) Has been skipped
Verify / Run e2e tests (shard 2/4) (push) Has been skipped
Verify / Run e2e tests (shard 3/4) (push) Has been skipped
Verify / Run e2e tests (shard 4/4) (push) Has been skipped
Publish / Resolve publish config (push) Failing after 2s
Publish / Send notification to Slack (push) Has been skipped
Publish / Send failure notification to Slack (push) Failing after 8s
Verify / Merge e2e reports (push) Has been skipped
Publish / Build (push) Has been skipped
Publish / Bump Versions OR Release to Registry (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 21:11:02 +05:00
commit 083a46e93b
2115 changed files with 245958 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
# @tiptap/extension-blockquote
[![Version](https://img.shields.io/npm/v/@tiptap/extension-blockquote.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-blockquote)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-blockquote.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@tiptap/extension-blockquote.svg)](https://www.npmjs.com/package/@tiptap/extension-blockquote)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
## Introduction
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
## Official Documentation
Documentation can be found on the [Tiptap website](https://tiptap.dev).
## License
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).

View File

@@ -0,0 +1,52 @@
{
"name": "@tiptap/extension-blockquote",
"version": "3.30.3",
"description": "blockquote extension for tiptap",
"keywords": [
"tiptap",
"tiptap extension"
],
"homepage": "https://tiptap.dev",
"bugs": {
"url": "https://github.com/ueberdosis/tiptap/issues"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ueberdosis/tiptap",
"directory": "packages/extension-blockquote"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/ueberdosis"
},
"files": [
"src",
"dist"
],
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": {
"import": "./dist/index.d.ts",
"require": "./dist/index.d.cts"
},
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"scripts": {
"build": "vp pack"
},
"devDependencies": {
"@tiptap/core": "workspace:^",
"@tiptap/pm": "workspace:^"
},
"peerDependencies": {
"@tiptap/core": "workspace:*",
"@tiptap/pm": "workspace:*"
}
}

View File

@@ -0,0 +1,143 @@
/** @jsxImportSource @tiptap/core */
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
import { handleBackspace } from './handleBackspace.js'
export interface BlockquoteOptions {
/**
* HTML attributes to add to the blockquote element
* @default {}
* @example { class: 'foo' }
*/
HTMLAttributes: Record<string, any>
}
declare module '@tiptap/core' {
interface Commands<ReturnType> {
blockQuote: {
/**
* Set a blockquote node
*/
setBlockquote: () => ReturnType
/**
* Toggle a blockquote node
*/
toggleBlockquote: () => ReturnType
/**
* Unset a blockquote node
*/
unsetBlockquote: () => ReturnType
}
}
}
/**
* Matches a blockquote to a `>` as input.
*/
export const inputRegex = /^\s*>\s$/
/**
* This extension allows you to create blockquotes.
* @see https://tiptap.dev/api/nodes/blockquote
*/
export const Blockquote = Node.create<BlockquoteOptions>({
name: 'blockquote',
addOptions() {
return {
HTMLAttributes: {},
}
},
content: 'block+',
group: 'block',
defining: true,
parseHTML() {
return [{ tag: 'blockquote' }]
},
renderHTML({ HTMLAttributes }) {
return (
<blockquote {...mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)}>
<slot />
</blockquote>
)
},
parseMarkdown: (token, helpers) => {
const parseBlockChildren = helpers.parseBlockChildren ?? helpers.parseChildren
return helpers.createNode('blockquote', undefined, parseBlockChildren(token.tokens || []))
},
renderMarkdown: (node, h) => {
if (!node.content) {
return ''
}
// Use a single '>' prefix regardless of nesting level
// Nested blockquotes will add their own '>' prefix recursively
const prefix = '>'
const result: string[] = []
node.content.forEach((child, index) => {
const childContent = h.renderChild?.(child, index) ?? h.renderChildren([child])
const lines = childContent.split('\n')
const linesWithPrefix = lines.map(line => {
// Don't add prefix to empty lines
if (line.trim() === '') {
return prefix
}
// Nested blockquotes will already have their own prefixes
// We just need to add our own prefix at the start
return `${prefix} ${line}`
})
result.push(linesWithPrefix.join('\n'))
})
// Add separator lines between children
return result.join(`\n${prefix}\n`)
},
addCommands() {
return {
setBlockquote:
() =>
({ commands }) => {
return commands.wrapIn(this.name)
},
toggleBlockquote:
() =>
({ commands }) => {
return commands.toggleWrap(this.name)
},
unsetBlockquote:
() =>
({ commands }) => {
return commands.lift(this.name)
},
}
},
addKeyboardShortcuts() {
return {
'Mod-Shift-b': () => this.editor.commands.toggleBlockquote(),
Backspace: () => handleBackspace(this.editor, this.type),
}
},
addInputRules() {
return [
wrappingInputRule({
find: inputRegex,
type: this.type,
}),
]
},
})

View File

@@ -0,0 +1,45 @@
import { Editor } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Image from '@tiptap/extension-image'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { GapCursor } from '@tiptap/pm/gapcursor'
import { afterEach, beforeEach, describe, expect, it } from 'vite-plus/test'
import { handleBackspace } from './handleBackspace.js'
import { Blockquote } from './blockquote.js'
describe('Blockquote handleBackspace', () => {
let editor: Editor
beforeEach(() => {
const element = document.createElement('div')
document.body.appendChild(element)
editor = new Editor({
element,
extensions: [Document, Paragraph, Text, Image, Blockquote],
content: '<img src="https://example.com/image.png">',
})
})
afterEach(() => {
editor.destroy()
})
// Regression test for https://github.com/ueberdosis/tiptap/issues/7973
// With a leading image, pressing backspace at the very start of the document
// resolved the caret to the top (doc) level, where `$from.depth` is 0. The
// handler then dereferenced `$from.node(-1)` (undefined) and crashed with
// `TypeError: can't access property "type", parent is undefined`.
it('does not throw when backspacing at the very start of the document', () => {
const { state, view } = editor
// Before the leading image, the caret resolves to a gap cursor at depth 0.
const selection = new GapCursor(state.doc.resolve(0))
view.dispatch(state.tr.setSelection(selection))
const blockquoteType = editor.schema.nodes.blockquote
expect(() => handleBackspace(editor, blockquoteType)).not.toThrow()
expect(handleBackspace(editor, blockquoteType)).toBe(false)
})
})

View File

@@ -0,0 +1,75 @@
import type { Editor } from '@tiptap/core'
import { Slice, type NodeType } from '@tiptap/pm/model'
import { TextSelection } from '@tiptap/pm/state'
/**
* Restructure the blockquote boundary at the caret.
*
* Two cases are handled in a single backspace:
*
* 1. Caret at the start of a non-first child of a blockquote — lift the
* current child out, splitting the blockquote around it.
* 2. Caret at the start of a top-level textblock whose previous sibling is
* a blockquote with a textblock last child — merge the current
* textblock's inline content into the blockquote's last textblock
* instead of letting joinBackward pull the paragraph back inside.
*
* Returns true when the backspace was consumed.
*/
export const handleBackspace = (editor: Editor, type: NodeType): boolean => {
const { state } = editor
const { selection } = state
if (!selection.empty) return false
const { $from } = selection
if ($from.parentOffset !== 0) return false
const parentDepth = $from.depth - 1
// At the very start of the document the caret can resolve to the top (doc)
// level — for example a gap cursor before a leading image — where there is
// no parent block. Bail out so backspace is a no-op instead of dereferencing
// an undefined parent at a negative depth. (#7973)
if (parentDepth < 0) return false
const parent = $from.node(parentDepth)
const index = $from.index(parentDepth)
if (index === 0) return false
// Non-first child of a blockquote: lift to split the blockquote around it.
if (parent.type === type) {
return editor.commands.lift(type.name)
}
// Previous sibling is a blockquote whose last child is a textblock:
// merge the inline content in instead of letting joinBackward pull the
// paragraph back inside the blockquote.
const previous = parent.child(index - 1)
if (previous.type !== type || !previous.lastChild?.isTextblock) {
return false
}
const blockStart = $from.before()
// `blockStart` sits in the shared parent at the position right after
// the previous blockquote. In ProseMirror coordinates, each closing
// token costs one position: step one back to land inside the blockquote
// right after its last child, then one more to land inside that last
// child at the end of its inline content.
const insideBlockquoteEnd = blockStart - 1
const targetPos = insideBlockquoteEnd - 1
return editor.commands.command(({ tr, dispatch }) => {
if (!dispatch) {
return true
}
const content = $from.parent.content
const slice = new Slice(content, 0, 0)
tr.replace(targetPos, $from.after(), slice)
tr.setSelection(TextSelection.create(tr.doc, targetPos + content.size))
tr.scrollIntoView()
dispatch(tr)
return true
})
}

View File

@@ -0,0 +1,5 @@
import { Blockquote } from './blockquote.jsx'
export * from './blockquote.jsx'
export default Blockquote

View File

@@ -0,0 +1,9 @@
import { defineConfig } from 'vite-plus'
import { basePackConfig } from '../../pack.config.mjs'
export default defineConfig({
pack: {
entry: ['src/index.ts'],
...basePackConfig(),
},
})