You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@tiptap/extension-text-align

Package Overview
Dependencies
Maintainers
5
Versions
189
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/extension-text-align - npm Package Compare versions

Comparing version

to
3.0.0-beta.0

dist/index.d.cts

50

dist/index.d.ts

@@ -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 };

123

dist/index.js

@@ -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
[![Version](https://img.shields.io/npm/v/@tiptap/extension-text-align.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-text-align)

@@ -8,8 +9,11 @@ [![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-text-align.svg)](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