Skip to content

Commit 3207367

Browse files
committed
refactor: broken image glyph css var
1 parent cfc85ba commit 3207367

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/web/EnrichedText.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,3 @@
328328
-webkit-mask: var(--et-broken-image-glyph) no-repeat center / contain;
329329
mask: var(--et-broken-image-glyph) no-repeat center / contain;
330330
}
331-
332-
.et-view {
333-
--et-broken-image-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 960'%3E%3Cpath d='M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM240,503L400,343L560,503L720,343L760,383L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,463L240,503ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,496L720,456L560,616L400,456L240,616L200,576L200,760Q200,760 200,760Q200,760 200,760ZM200,760L200,760Q200,760 200,760Q200,760 200,760L200,496L200,576L200,463L200,383L200,200Q200,200 200,200Q200,200 200,200L200,200Q200,200 200,200Q200,200 200,200L200,463L200,463L200,576L200,576L200,760Q200,760 200,760Q200,760 200,760Z'/%3E%3C/svg%3E");
334-
}

src/web/EnrichedText.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { enrichedInputThemingToCSSProperties } from './styleConversion/enrichedI
88
import { buildMentionRulesCSS } from './styleConversion/buildMentionRulesCSS';
99
import { sanitizeHtml } from './sanitization/htmlSanitizer';
1010
import { prepareHtmlForWeb } from './normalization/prepareHtmlForWeb';
11+
import { BROKEN_IMAGE_GLYPH_MASK } from './constants/brokenImageGlyph';
1112

1213
export const EnrichedText = memo(
1314
({ children, htmlStyle, style, selectionColor }: EnrichedTextProps) => {
@@ -26,7 +27,10 @@ export const EnrichedText = memo(
2627
);
2728

2829
const cssVars = useMemo(
29-
() => htmlStyleToCSSVariables(htmlStyle),
30+
() => ({
31+
...htmlStyleToCSSVariables(htmlStyle),
32+
'--et-broken-image-glyph': BROKEN_IMAGE_GLYPH_MASK,
33+
}),
3034
[htmlStyle]
3135
);
3236

@@ -41,7 +45,12 @@ export const EnrichedText = memo(
4145
);
4246

4347
const finalStyle = useMemo(
44-
() => ({ ...textStyle, ...themingStyle, ...cssVars }),
48+
() =>
49+
({
50+
...textStyle,
51+
...themingStyle,
52+
...cssVars,
53+
}) as CSSProperties,
4554
[textStyle, themingStyle, cssVars]
4655
);
4756

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SVG path of the broken-image glyph, shared between the editor's image
2+
// node view (rendered as an inline <svg>).
3+
export const BROKEN_IMAGE_PATH_D =
4+
'M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM240,503L400,343L560,503L720,343L760,383L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,463L240,503ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,496L720,456L560,616L400,456L240,616L200,576L200,760Q200,760 200,760Q200,760 200,760ZM200,760L200,760Q200,760 200,760Q200,760 200,760L200,496L200,576L200,463L200,383L200,200Q200,200 200,200Q200,200 200,200L200,200Q200,200 200,200Q200,200 200,200L200,463L200,463L200,576L200,576L200,760Q200,760 200,760Q200,760 200,760Z';
5+
6+
// Glyph as a `mask`-ready data URI, consumed via the
7+
// `--et-broken-image-glyph` custom property in EnrichedText.css.
8+
export const BROKEN_IMAGE_GLYPH_MASK = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 960'%3E%3Cpath d='${BROKEN_IMAGE_PATH_D}'/%3E%3C/svg%3E")`;

src/web/formats/EnrichedImageNodeView.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { NodeViewWrapper, type ReactNodeViewProps } from '@tiptap/react';
22
import type { CSSProperties } from 'react';
33
import { useState } from 'react';
4+
import { BROKEN_IMAGE_PATH_D } from '../constants/brokenImageGlyph';
45

56
const IMAGE_FALLBACK_SIZE = 80;
67

7-
const BROKEN_IMAGE_PATH_D =
8-
'M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM240,503L400,343L560,503L720,343L760,383L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,463L240,503ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,496L720,456L560,616L400,456L240,616L200,576L200,760Q200,760 200,760Q200,760 200,760ZM200,760L200,760Q200,760 200,760Q200,760 200,760L200,496L200,576L200,463L200,383L200,200Q200,200 200,200Q200,200 200,200L200,200Q200,200 200,200Q200,200 200,200L200,463L200,463L200,576L200,576L200,760Q200,760 200,760Q200,760 200,760Z';
9-
108
function BrokenImageGlyph() {
119
return (
1210
<svg

0 commit comments

Comments
 (0)