@tiptap/extension-text-align
Advanced tools
Comparing version
@@ -1,4 +0,46 @@ | ||
import { TextAlign } from './text-align.js'; | ||
export * from './text-align.js'; | ||
export default TextAlign; | ||
//# sourceMappingURL=index.d.ts.map | ||
import { Extension } from '@tiptap/core'; | ||
interface TextAlignOptions { | ||
/** | ||
* The types where the text align attribute can be applied. | ||
* @default [] | ||
* @example ['heading', 'paragraph'] | ||
*/ | ||
types: string[]; | ||
/** | ||
* The alignments which are allowed. | ||
* @default ['left', 'center', 'right', 'justify'] | ||
* @example ['left', 'right'] | ||
*/ | ||
alignments: string[]; | ||
/** | ||
* The default alignment. | ||
* @default null | ||
* @example 'center' | ||
*/ | ||
defaultAlignment: string | null; | ||
} | ||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
textAlign: { | ||
/** | ||
* Set the text align attribute | ||
* @param alignment The alignment | ||
* @example editor.commands.setTextAlign('left') | ||
*/ | ||
setTextAlign: (alignment: string) => ReturnType; | ||
/** | ||
* Unset the text align attribute | ||
* @example editor.commands.unsetTextAlign() | ||
*/ | ||
unsetTextAlign: () => ReturnType; | ||
}; | ||
} | ||
} | ||
/** | ||
* This extension allows you to align text. | ||
* @see https://www.tiptap.dev/api/extensions/text-align | ||
*/ | ||
declare const TextAlign: Extension<TextAlignOptions, any>; | ||
export { TextAlign, type TextAlignOptions, TextAlign as default }; |
@@ -1,66 +0,63 @@ | ||
import { Extension } from '@tiptap/core'; | ||
/** | ||
* This extension allows you to align text. | ||
* @see https://www.tiptap.dev/api/extensions/text-align | ||
*/ | ||
const TextAlign = Extension.create({ | ||
name: 'textAlign', | ||
addOptions() { | ||
return { | ||
types: [], | ||
alignments: ['left', 'center', 'right', 'justify'], | ||
defaultAlignment: null, | ||
}; | ||
}, | ||
addGlobalAttributes() { | ||
return [ | ||
{ | ||
types: this.options.types, | ||
attributes: { | ||
textAlign: { | ||
default: this.options.defaultAlignment, | ||
parseHTML: element => { | ||
const alignment = element.style.textAlign; | ||
return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment; | ||
}, | ||
renderHTML: attributes => { | ||
if (!attributes.textAlign) { | ||
return {}; | ||
} | ||
return { style: `text-align: ${attributes.textAlign}` }; | ||
}, | ||
}, | ||
}, | ||
// src/text-align.ts | ||
import { Extension } from "@tiptap/core"; | ||
var TextAlign = Extension.create({ | ||
name: "textAlign", | ||
addOptions() { | ||
return { | ||
types: [], | ||
alignments: ["left", "center", "right", "justify"], | ||
defaultAlignment: null | ||
}; | ||
}, | ||
addGlobalAttributes() { | ||
return [ | ||
{ | ||
types: this.options.types, | ||
attributes: { | ||
textAlign: { | ||
default: this.options.defaultAlignment, | ||
parseHTML: (element) => { | ||
const alignment = element.style.textAlign; | ||
return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment; | ||
}, | ||
]; | ||
}, | ||
addCommands() { | ||
return { | ||
setTextAlign: (alignment) => ({ commands }) => { | ||
if (!this.options.alignments.includes(alignment)) { | ||
return false; | ||
} | ||
return this.options.types | ||
.map(type => commands.updateAttributes(type, { textAlign: alignment })) | ||
.every(response => response); | ||
}, | ||
unsetTextAlign: () => ({ commands }) => { | ||
return this.options.types | ||
.map(type => commands.resetAttributes(type, 'textAlign')) | ||
.every(response => response); | ||
}, | ||
}; | ||
}, | ||
addKeyboardShortcuts() { | ||
return { | ||
'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'), | ||
'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'), | ||
'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'), | ||
'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'), | ||
}; | ||
}, | ||
renderHTML: (attributes) => { | ||
if (!attributes.textAlign) { | ||
return {}; | ||
} | ||
return { style: `text-align: ${attributes.textAlign}` }; | ||
} | ||
} | ||
} | ||
} | ||
]; | ||
}, | ||
addCommands() { | ||
return { | ||
setTextAlign: (alignment) => ({ commands }) => { | ||
if (!this.options.alignments.includes(alignment)) { | ||
return false; | ||
} | ||
return this.options.types.map((type) => commands.updateAttributes(type, { textAlign: alignment })).every((response) => response); | ||
}, | ||
unsetTextAlign: () => ({ commands }) => { | ||
return this.options.types.map((type) => commands.resetAttributes(type, "textAlign")).every((response) => response); | ||
} | ||
}; | ||
}, | ||
addKeyboardShortcuts() { | ||
return { | ||
"Mod-Shift-l": () => this.editor.commands.setTextAlign("left"), | ||
"Mod-Shift-e": () => this.editor.commands.setTextAlign("center"), | ||
"Mod-Shift-r": () => this.editor.commands.setTextAlign("right"), | ||
"Mod-Shift-j": () => this.editor.commands.setTextAlign("justify") | ||
}; | ||
} | ||
}); | ||
export { TextAlign, TextAlign as default }; | ||
//# sourceMappingURL=index.js.map | ||
// src/index.ts | ||
var index_default = TextAlign; | ||
export { | ||
TextAlign, | ||
index_default as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@tiptap/extension-text-align", | ||
"description": "text align extension for tiptap", | ||
"version": "2.11.7", | ||
"version": "3.0.0-beta.0", | ||
"homepage": "https://tiptap.dev", | ||
@@ -18,3 +18,6 @@ "keywords": [ | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"types": { | ||
"import": "./dist/index.d.ts", | ||
"require": "./dist/index.d.cts" | ||
}, | ||
"import": "./dist/index.js", | ||
@@ -26,3 +29,2 @@ "require": "./dist/index.cjs" | ||
"module": "dist/index.js", | ||
"umd": "dist/index.umd.js", | ||
"types": "dist/index.d.ts", | ||
@@ -34,6 +36,6 @@ "files": [ | ||
"devDependencies": { | ||
"@tiptap/core": "^2.11.7" | ||
"@tiptap/core": "^3.0.0-beta.0" | ||
}, | ||
"peerDependencies": { | ||
"@tiptap/core": "^2.7.0" | ||
"@tiptap/core": "^3.0.0-beta.0" | ||
}, | ||
@@ -46,5 +48,5 @@ "repository": { | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"build": "npm run clean && rollup -c" | ||
"build": "tsup", | ||
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/" | ||
} | ||
} | ||
} |
# @tiptap/extension-text-align | ||
[](https://www.npmjs.com/package/@tiptap/extension-text-align) | ||
@@ -8,8 +9,11 @@ [](https://npmcharts.com/compare/tiptap?minimal=true) | ||
## 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*. | ||
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). |
@@ -9,3 +9,3 @@ import { Extension } from '@tiptap/core' | ||
*/ | ||
types: string[], | ||
types: string[] | ||
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
alignments: string[], | ||
alignments: string[] | ||
@@ -25,3 +25,3 @@ /** | ||
*/ | ||
defaultAlignment: string | null, | ||
defaultAlignment: string | null | ||
} | ||
@@ -37,3 +37,3 @@ | ||
*/ | ||
setTextAlign: (alignment: string) => ReturnType, | ||
setTextAlign: (alignment: string) => ReturnType | ||
/** | ||
@@ -43,3 +43,3 @@ * Unset the text align attribute | ||
*/ | ||
unsetTextAlign: () => ReturnType, | ||
unsetTextAlign: () => ReturnType | ||
} | ||
@@ -91,17 +91,19 @@ } | ||
return { | ||
setTextAlign: (alignment: string) => ({ commands }) => { | ||
if (!this.options.alignments.includes(alignment)) { | ||
return false | ||
} | ||
setTextAlign: | ||
(alignment: string) => | ||
({ commands }) => { | ||
if (!this.options.alignments.includes(alignment)) { | ||
return false | ||
} | ||
return this.options.types | ||
.map(type => commands.updateAttributes(type, { textAlign: alignment })) | ||
.every(response => response) | ||
}, | ||
return this.options.types | ||
.map(type => commands.updateAttributes(type, { textAlign: alignment })) | ||
.every(response => response) | ||
}, | ||
unsetTextAlign: () => ({ commands }) => { | ||
return this.options.types | ||
.map(type => commands.resetAttributes(type, 'textAlign')) | ||
.every(response => response) | ||
}, | ||
unsetTextAlign: | ||
() => | ||
({ commands }) => { | ||
return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).every(response => response) | ||
}, | ||
} | ||
@@ -108,0 +110,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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19
26.67%22727
-23.17%11
-21.43%295
-15.71%1
Infinity%