@tiptap/extension-bullet-list
Advanced tools
Comparing version 3.0.0-next.0 to 3.0.0-next.1
@@ -1,149 +0,73 @@ | ||
import { Node, mergeAttributes, Mark, getMarkAttributes, wrappingInputRule } from '@tiptap/core'; | ||
/** | ||
* This extension allows you to create list items. | ||
* @see https://www.tiptap.dev/api/nodes/list-item | ||
*/ | ||
const ListItem = Node.create({ | ||
name: 'listItem', | ||
addOptions() { | ||
return { | ||
HTMLAttributes: {}, | ||
bulletListTypeName: 'bulletList', | ||
orderedListTypeName: 'orderedList', | ||
}; | ||
}, | ||
content: 'paragraph block*', | ||
defining: true, | ||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'li', | ||
}, | ||
]; | ||
}, | ||
renderHTML({ HTMLAttributes }) { | ||
return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; | ||
}, | ||
addKeyboardShortcuts() { | ||
return { | ||
Enter: () => this.editor.commands.splitListItem(this.name), | ||
Tab: () => this.editor.commands.sinkListItem(this.name), | ||
'Shift-Tab': () => this.editor.commands.liftListItem(this.name), | ||
}; | ||
}, | ||
}); | ||
/** | ||
* This extension allows you to create text styles. It is required by default | ||
* for the `textColor` and `backgroundColor` extensions. | ||
* @see https://www.tiptap.dev/api/marks/text-style | ||
*/ | ||
const TextStyle = Mark.create({ | ||
name: 'textStyle', | ||
addOptions() { | ||
return { | ||
HTMLAttributes: {}, | ||
}; | ||
}, | ||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'span', | ||
getAttrs: element => { | ||
const hasStyles = element.hasAttribute('style'); | ||
if (!hasStyles) { | ||
return false; | ||
} | ||
return {}; | ||
}, | ||
}, | ||
]; | ||
}, | ||
renderHTML({ HTMLAttributes }) { | ||
return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; | ||
}, | ||
addCommands() { | ||
return { | ||
removeEmptyTextStyle: () => ({ state, commands }) => { | ||
const attributes = getMarkAttributes(state, this.type); | ||
const hasStyles = Object.entries(attributes).some(([, value]) => !!value); | ||
if (hasStyles) { | ||
return true; | ||
} | ||
return commands.unsetMark(this.name); | ||
}, | ||
}; | ||
}, | ||
}); | ||
/** | ||
* Matches a bullet list to a dash or asterisk. | ||
*/ | ||
const inputRegex = /^\s*([-+*])\s$/; | ||
/** | ||
* This extension allows you to create bullet lists. | ||
* This requires the ListItem extension | ||
* @see https://tiptap.dev/api/nodes/bullet-list | ||
* @see https://tiptap.dev/api/nodes/list-item. | ||
*/ | ||
const BulletList = Node.create({ | ||
name: 'bulletList', | ||
addOptions() { | ||
return { | ||
itemTypeName: 'listItem', | ||
HTMLAttributes: {}, | ||
keepMarks: false, | ||
keepAttributes: false, | ||
}; | ||
}, | ||
group: 'block list', | ||
content() { | ||
return `${this.options.itemTypeName}+`; | ||
}, | ||
parseHTML() { | ||
return [ | ||
{ tag: 'ul' }, | ||
]; | ||
}, | ||
renderHTML({ HTMLAttributes }) { | ||
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; | ||
}, | ||
addCommands() { | ||
return { | ||
toggleBulletList: () => ({ commands, chain }) => { | ||
if (this.options.keepAttributes) { | ||
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run(); | ||
} | ||
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks); | ||
}, | ||
}; | ||
}, | ||
addKeyboardShortcuts() { | ||
return { | ||
'Mod-Shift-8': () => this.editor.commands.toggleBulletList(), | ||
}; | ||
}, | ||
addInputRules() { | ||
let inputRule = wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type, | ||
}); | ||
if (this.options.keepMarks || this.options.keepAttributes) { | ||
inputRule = wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type, | ||
keepMarks: this.options.keepMarks, | ||
keepAttributes: this.options.keepAttributes, | ||
getAttributes: () => { return this.editor.getAttributes(TextStyle.name); }, | ||
editor: this.editor, | ||
}); | ||
// src/bullet-list.ts | ||
import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core"; | ||
var ListItemName = "listItem"; | ||
var TextStyleName = "textStyle"; | ||
var inputRegex = /^\s*([-+*])\s$/; | ||
var BulletList = Node.create({ | ||
name: "bulletList", | ||
addOptions() { | ||
return { | ||
itemTypeName: "listItem", | ||
HTMLAttributes: {}, | ||
keepMarks: false, | ||
keepAttributes: false | ||
}; | ||
}, | ||
group: "block list", | ||
content() { | ||
return `${this.options.itemTypeName}+`; | ||
}, | ||
parseHTML() { | ||
return [ | ||
{ tag: "ul" } | ||
]; | ||
}, | ||
renderHTML({ HTMLAttributes }) { | ||
return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; | ||
}, | ||
addCommands() { | ||
return { | ||
toggleBulletList: () => ({ commands, chain }) => { | ||
if (this.options.keepAttributes) { | ||
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run(); | ||
} | ||
return [ | ||
inputRule, | ||
]; | ||
}, | ||
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks); | ||
} | ||
}; | ||
}, | ||
addKeyboardShortcuts() { | ||
return { | ||
"Mod-Shift-8": () => this.editor.commands.toggleBulletList() | ||
}; | ||
}, | ||
addInputRules() { | ||
let inputRule = wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type | ||
}); | ||
if (this.options.keepMarks || this.options.keepAttributes) { | ||
inputRule = wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type, | ||
keepMarks: this.options.keepMarks, | ||
keepAttributes: this.options.keepAttributes, | ||
getAttributes: () => { | ||
return this.editor.getAttributes(TextStyleName); | ||
}, | ||
editor: this.editor | ||
}); | ||
} | ||
return [ | ||
inputRule | ||
]; | ||
} | ||
}); | ||
export { BulletList, BulletList as default, inputRegex }; | ||
//# sourceMappingURL=index.js.map | ||
// src/index.ts | ||
var src_default = BulletList; | ||
export { | ||
BulletList, | ||
src_default as default, | ||
inputRegex | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@tiptap/extension-bullet-list", | ||
"description": "bullet list extension for tiptap", | ||
"version": "3.0.0-next.0", | ||
"version": "3.0.0-next.1", | ||
"homepage": "https://tiptap.dev", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
".": { | ||
"types": "./dist/packages/extension-bullet-list/src/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
@@ -26,4 +26,3 @@ "require": "./dist/index.cjs" | ||
"module": "dist/index.js", | ||
"umd": "dist/index.umd.js", | ||
"types": "dist/packages/extension-bullet-list/src/index.d.ts", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -34,6 +33,6 @@ "src", | ||
"devDependencies": { | ||
"@tiptap/core": "^3.0.0-next.0" | ||
"@tiptap/core": "^3.0.0-next.1" | ||
}, | ||
"peerDependencies": { | ||
"@tiptap/core": "^3.0.0-next.0" | ||
"@tiptap/core": "^3.0.0-next.1" | ||
}, | ||
@@ -46,5 +45,4 @@ "repository": { | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"build": "npm run clean && rollup -c" | ||
"build": "tsup" | ||
} | ||
} |
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' | ||
import ListItem from '../../extension-list-item/src/index.js' | ||
import TextStyle from '../../extension-text-style/src/index.js' | ||
const ListItemName = 'listItem' | ||
const TextStyleName = 'textStyle' | ||
@@ -90,3 +90,3 @@ export interface BulletListOptions { | ||
if (this.options.keepAttributes) { | ||
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() | ||
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run() | ||
} | ||
@@ -116,3 +116,3 @@ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks) | ||
keepAttributes: this.options.keepAttributes, | ||
getAttributes: () => { return this.editor.getAttributes(TextStyle.name) }, | ||
getAttributes: () => { return this.editor.getAttributes(TextStyleName) }, | ||
editor: this.editor, | ||
@@ -119,0 +119,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21395
10
326
1