Tiptap TextStyle tweaks
This commit is contained in:
committed by
Jacob Overgaard
parent
da26fd1a3c
commit
5037cc321f
@@ -1,4 +1,5 @@
|
||||
import { Extension } from '@tiptap/core';
|
||||
import type { Attributes } from '@tiptap/core';
|
||||
|
||||
/**
|
||||
* Converts camelCase to kebab-case.
|
||||
@@ -45,7 +46,14 @@ export const HtmlGlobalAttributes = Extension.create<HtmlGlobalAttributesOptions
|
||||
},
|
||||
id: {},
|
||||
style: {},
|
||||
},
|
||||
// style: {
|
||||
// parseHTML: (element) => (element.style?.length ? element.style : null),
|
||||
// renderHTML: (attributes) => {
|
||||
// if (!attributes.style?.length) return null;
|
||||
// return { style: attributes.style.cssText };
|
||||
// },
|
||||
// },
|
||||
} as Attributes,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
@@ -37,6 +37,7 @@ export class UmbTiptapToolbarFontFamilyToolbarElement extends UmbTiptapToolbarBu
|
||||
#getElement(fontFamily: string, label: string) {
|
||||
const menuItem = document.createElement('uui-menu-item');
|
||||
menuItem.addEventListener('click', () => {
|
||||
//this.editor?.chain().focus().setMark('textStyle', { fontFamily }).run();
|
||||
this.editor
|
||||
?.chain()
|
||||
.focus()
|
||||
@@ -47,7 +48,7 @@ export class UmbTiptapToolbarFontFamilyToolbarElement extends UmbTiptapToolbarBu
|
||||
const element = document.createElement('span');
|
||||
element.slot = 'label';
|
||||
element.textContent = label;
|
||||
element.style.cssText = `font-family: ${fontFamily};`;
|
||||
element.style.fontFamily = fontFamily;
|
||||
|
||||
menuItem.appendChild(element);
|
||||
|
||||
|
||||
@@ -6,16 +6,17 @@ import '../../components/cascading-menu-popover/cascading-menu-popover.element.j
|
||||
|
||||
@customElement('umb-tiptap-font-size-toolbar-element')
|
||||
export class UmbTiptapToolbarFontSizeToolbarElement extends UmbTiptapToolbarButtonElement {
|
||||
#fontSizes = [8, 10, 12, 14, 16, 18, 24, 36, 48];
|
||||
#fontSizes = [8, 10, 12, 14, 16, 18, 24, 36, 48].map((fontSize) => `${fontSize}pt`);
|
||||
|
||||
#menu: Array<UmbCascadingMenuItem> = this.#fontSizes.map((fontSize) => ({
|
||||
unique: `font-size-${fontSize}pt`,
|
||||
label: `${fontSize}pt`,
|
||||
unique: `font-size-${fontSize}`,
|
||||
label: fontSize,
|
||||
// execute: () => this.editor?.chain().focus().setMark('textStyle', { fontSize }).run(),
|
||||
execute: () =>
|
||||
this.editor
|
||||
?.chain()
|
||||
.focus()
|
||||
.setMark('textStyle', { style: `font-size: ${fontSize}pt;` })
|
||||
.setMark('textStyle', { style: `font-size: ${fontSize};` })
|
||||
.run(),
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user