@tiptap/extension-text-align
Advanced tools
Comparing version 3.0.0-next.0 to 3.0.0-next.1
@@ -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: 'left', | ||
}; | ||
}, | ||
addGlobalAttributes() { | ||
return [ | ||
{ | ||
types: this.options.types, | ||
attributes: { | ||
textAlign: { | ||
default: this.options.defaultAlignment, | ||
parseHTML: element => { | ||
const alignment = element.style.textAlign || this.options.defaultAlignment; | ||
return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment; | ||
}, | ||
renderHTML: attributes => { | ||
if (attributes.textAlign === this.options.defaultAlignment) { | ||
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: "left" | ||
}; | ||
}, | ||
addGlobalAttributes() { | ||
return [ | ||
{ | ||
types: this.options.types, | ||
attributes: { | ||
textAlign: { | ||
default: this.options.defaultAlignment, | ||
parseHTML: (element) => { | ||
const alignment = element.style.textAlign || this.options.defaultAlignment; | ||
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 === this.options.defaultAlignment) { | ||
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 src_default = TextAlign; | ||
export { | ||
TextAlign, | ||
src_default as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@tiptap/extension-text-align", | ||
"description": "text align 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-text-align/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-text-align/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" | ||
} | ||
} |
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
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
21770
10
293
1