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
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:
1868
packages/extension-horizontal-rule/CHANGELOG.md
Normal file
1868
packages/extension-horizontal-rule/CHANGELOG.md
Normal file
File diff suppressed because it is too large
Load Diff
18
packages/extension-horizontal-rule/README.md
Normal file
18
packages/extension-horizontal-rule/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# @tiptap/extension-horizontal-rule
|
||||
|
||||
[](https://www.npmjs.com/package/@tiptap/extension-horizontal-rule)
|
||||
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
||||
[](https://www.npmjs.com/package/@tiptap/extension-horizontal-rule)
|
||||
[](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).
|
||||
52
packages/extension-horizontal-rule/package.json
Normal file
52
packages/extension-horizontal-rule/package.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@tiptap/extension-horizontal-rule",
|
||||
"version": "3.30.3",
|
||||
"description": "horizontal rule 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-horizontal-rule"
|
||||
},
|
||||
"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:*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Editor } from '@tiptap/core'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import { HorizontalRule } from './horizontal-rule.js'
|
||||
import Image from '@tiptap/extension-image'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import { describe, expect, it } from 'vite-plus/test'
|
||||
|
||||
describe('extension-horizontal-rule', () => {
|
||||
const editorElClass = 'tiptap'
|
||||
let editor: Editor | null = null
|
||||
|
||||
const createEditorEl = () => {
|
||||
const editorEl = document.createElement('div')
|
||||
|
||||
editorEl.classList.add(editorElClass)
|
||||
document.body.appendChild(editorEl)
|
||||
|
||||
return editorEl
|
||||
}
|
||||
|
||||
const getEditorEl = () => document.querySelector(`.${editorElClass}`)
|
||||
|
||||
it('should be inserted after block leaf nodes correctly', () => {
|
||||
editor = new Editor({
|
||||
element: createEditorEl(),
|
||||
extensions: [Document, Text, Paragraph, HorizontalRule, Image],
|
||||
content: {
|
||||
type: 'doc',
|
||||
content: [
|
||||
{
|
||||
type: 'image',
|
||||
attrs: {
|
||||
src: 'https://source.unsplash.com/8xznAGy4HcY/800x400',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'paragraph',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Example Text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
editor.commands.setTextSelection(2)
|
||||
editor.commands.setHorizontalRule()
|
||||
|
||||
expect(editor.getHTML()).toMatch(/<img(.*?)><hr><p>Example Text<\/p>/)
|
||||
|
||||
editor?.destroy()
|
||||
getEditorEl()?.remove()
|
||||
})
|
||||
})
|
||||
136
packages/extension-horizontal-rule/src/horizontal-rule.ts
Normal file
136
packages/extension-horizontal-rule/src/horizontal-rule.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import { canInsertNode, isNodeSelection, mergeAttributes, Node, nodeInputRule } from '@tiptap/core'
|
||||
import { NodeSelection, TextSelection } from '@tiptap/pm/state'
|
||||
|
||||
export interface HorizontalRuleOptions {
|
||||
/**
|
||||
* The HTML attributes for a horizontal rule node.
|
||||
* @default {}
|
||||
* @example { class: 'foo' }
|
||||
*/
|
||||
HTMLAttributes: Record<string, any>
|
||||
/**
|
||||
* The default type to insert after the horizontal rule.
|
||||
* @default "paragraph"
|
||||
* @example "heading"
|
||||
*/
|
||||
nextNodeType: string
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands<ReturnType> {
|
||||
horizontalRule: {
|
||||
/**
|
||||
* Add a horizontal rule
|
||||
* @example editor.commands.setHorizontalRule()
|
||||
*/
|
||||
setHorizontalRule: () => ReturnType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This extension allows you to insert horizontal rules.
|
||||
* @see https://www.tiptap.dev/api/nodes/horizontal-rule
|
||||
*/
|
||||
export const HorizontalRule = Node.create<HorizontalRuleOptions>({
|
||||
name: 'horizontalRule',
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {},
|
||||
nextNodeType: 'paragraph',
|
||||
}
|
||||
},
|
||||
|
||||
group: 'block',
|
||||
|
||||
parseHTML() {
|
||||
return [{ tag: 'hr' }]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['hr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]
|
||||
},
|
||||
|
||||
markdownTokenName: 'hr',
|
||||
|
||||
parseMarkdown: (token, helpers) => {
|
||||
return helpers.createNode('horizontalRule')
|
||||
},
|
||||
|
||||
renderMarkdown: () => {
|
||||
return '---'
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setHorizontalRule:
|
||||
() =>
|
||||
({ chain, state }) => {
|
||||
// Check if we can insert the node at the current selection
|
||||
if (!canInsertNode(state, state.schema.nodes[this.name])) {
|
||||
return false
|
||||
}
|
||||
|
||||
const { selection } = state
|
||||
const { $to: $originTo } = selection
|
||||
|
||||
const currentChain = chain()
|
||||
|
||||
if (isNodeSelection(selection)) {
|
||||
currentChain.insertContentAt($originTo.pos, {
|
||||
type: this.name,
|
||||
})
|
||||
} else {
|
||||
currentChain.insertContent({ type: this.name })
|
||||
}
|
||||
|
||||
return (
|
||||
currentChain
|
||||
// set cursor after horizontal rule
|
||||
.command(({ state: chainState, tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
const { $to } = tr.selection
|
||||
const posAfter = $to.end()
|
||||
|
||||
if ($to.nodeAfter) {
|
||||
if ($to.nodeAfter.isTextblock) {
|
||||
tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1))
|
||||
} else if ($to.nodeAfter.isBlock) {
|
||||
tr.setSelection(NodeSelection.create(tr.doc, $to.pos))
|
||||
} else {
|
||||
tr.setSelection(TextSelection.create(tr.doc, $to.pos))
|
||||
}
|
||||
} else {
|
||||
// add node after horizontal rule if it’s the end of the document
|
||||
const nodeType =
|
||||
chainState.schema.nodes[this.options.nextNodeType] ||
|
||||
$to.parent.type.contentMatch.defaultType
|
||||
const node = nodeType?.create()
|
||||
|
||||
if (node) {
|
||||
tr.insert(posAfter, node)
|
||||
tr.setSelection(TextSelection.create(tr.doc, posAfter + 1))
|
||||
}
|
||||
}
|
||||
|
||||
tr.scrollIntoView()
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
.run()
|
||||
)
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addInputRules() {
|
||||
return [
|
||||
nodeInputRule({
|
||||
find: /^(?:---|—-|___\s|\*\*\*\s)$/,
|
||||
type: this.type,
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
5
packages/extension-horizontal-rule/src/index.ts
Normal file
5
packages/extension-horizontal-rule/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { HorizontalRule } from './horizontal-rule.js'
|
||||
|
||||
export * from './horizontal-rule.js'
|
||||
|
||||
export default HorizontalRule
|
||||
9
packages/extension-horizontal-rule/vite.config.ts
Normal file
9
packages/extension-horizontal-rule/vite.config.ts
Normal 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(),
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user