Skip to content

Commit ba8e1ae

Browse files
authored
Tiptap RTE: Fixes embedded media spacing (#19878)
* Tiptap RTE: Makes embedded-media truly inline by using a `<span>` instead of a `<div>`. * Cosmetically aligns the selection styles * Adds `UmbEmbeddedMediaOptions` to strongly-type the `inline` option
1 parent e7da631 commit ba8e1ae

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/Umbraco.Web.UI.Client/src/external/tiptap/extensions/tiptap-span.extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ function serializeStyles(items: Record<string, string>): string {
3737
export const Span = Mark.create<SpanOptions>({
3838
name: 'span',
3939

40+
priority: 50,
41+
4042
addOptions() {
4143
return { HTMLAttributes: {} };
4244
},

src/Umbraco.Web.UI.Client/src/external/tiptap/extensions/tiptap-umb-embedded-media.extension.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { mergeAttributes, Node } from '@tiptap/core';
22

3-
export const umbEmbeddedMedia = Node.create({
3+
export interface UmbEmbeddedMediaOptions {
4+
inline: boolean;
5+
}
6+
7+
export const umbEmbeddedMedia = Node.create<UmbEmbeddedMediaOptions>({
48
name: 'umbEmbeddedMedia',
59
group() {
610
return this.options.inline ? 'inline' : 'block';
@@ -25,19 +29,13 @@ export const umbEmbeddedMedia = Node.create({
2529
},
2630

2731
parseHTML() {
28-
return [
29-
{
30-
tag: 'div',
31-
priority: 100,
32-
getAttrs: (dom) => dom.classList.contains('umb-embed-holder') && null,
33-
},
34-
];
32+
return [{ tag: '.umb-embed-holder', priority: 100 }];
3533
},
3634

3735
renderHTML({ HTMLAttributes }) {
3836
const { markup, ...attrs } = HTMLAttributes;
3937
const embed = document.createRange().createContextualFragment(markup);
40-
return ['div', mergeAttributes({ class: 'umb-embed-holder' }, attrs), embed];
38+
return [this.options.inline ? 'span' : 'div', mergeAttributes({ class: 'umb-embed-holder' }, attrs), embed];
4139
},
4240

4341
addCommands() {

src/Umbraco.Web.UI.Client/src/packages/tiptap/extensions/core/embedded-media.tiptap-api.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ export default class UmbTiptapEmbeddedMediaExtensionApi extends UmbTiptapExtensi
99
.umb-embed-holder {
1010
display: inline-block;
1111
position: relative;
12-
}
1312
14-
.umb-embed-holder > * {
15-
user-select: none;
16-
pointer-events: none;
17-
}
13+
&::before {
14+
z-index: 1000;
15+
width: 100%;
16+
height: 100%;
17+
position: absolute;
18+
content: ' ';
19+
}
1820
19-
.umb-embed-holder.ProseMirror-selectednode {
20-
outline: 2px solid var(--uui-palette-spanish-pink-light);
21-
}
21+
&.ProseMirror-selectednode {
22+
outline: 3px solid var(--uui-color-focus);
2223
23-
.umb-embed-holder::before {
24-
z-index: 1000;
25-
width: 100%;
26-
height: 100%;
27-
position: absolute;
28-
content: ' ';
29-
}
24+
&::before {
25+
background: rgba(0, 0, 0, 0.1);
26+
}
3027
31-
.umb-embed-holder.ProseMirror-selectednode::before {
32-
background: rgba(0, 0, 0, 0.025);
28+
> * {
29+
user-select: none;
30+
pointer-events: none;
31+
}
32+
}
3333
}
3434
`;
3535
}

0 commit comments

Comments
 (0)