@cntrl-site/sdk-nextjs 1.11.0-0 → 1.11.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/StructuredBlockItem/StructuredHeaderImage/StructuredHeaderImage.js +2 -1
- package/lib/components/StructuredBlockItem/StructuredImage/StructuredImage.js +2 -1
- package/lib/components/StructuredBlockItem/StructuredRichText/StructuredRichText.js +11 -1
- package/lib/components/StructuredBlockItem/textStylesRule.js +13 -1
- package/lib/utils/getHeadingTag.js +3 -2
- package/package.json +5 -5
- package/src/components/StructuredBlockItem/StructuredHeaderImage/StructuredHeaderImage.tsx +3 -2
- package/src/components/StructuredBlockItem/StructuredImage/StructuredImage.tsx +3 -2
- package/src/components/StructuredBlockItem/StructuredRichText/StructuredRichText.tsx +13 -3
- package/src/components/StructuredBlockItem/textStylesRule.ts +15 -1
- package/src/components/StructuredContent/StructuredContent.test.tsx +30 -0
- package/src/utils/getHeadingTag.ts +3 -4
|
@@ -20,7 +20,8 @@ const StructuredHeaderImage = ({ block, readingWidth }) => {
|
|
|
20
20
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
21
21
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
22
22
|
(0, useItemGeometry_1.useItemGeometry)(block.id, ref);
|
|
23
|
-
const { url, altText
|
|
23
|
+
const { url, altText } = block.commonParams;
|
|
24
|
+
const caption = (0, sdk_1.getShownCaption)(block.commonParams);
|
|
24
25
|
if (!url)
|
|
25
26
|
return null;
|
|
26
27
|
const layoutValues = [block.layoutParams];
|
|
@@ -22,7 +22,8 @@ const StructuredImage = ({ block, readingWidth }) => {
|
|
|
22
22
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
23
23
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
24
24
|
(0, useItemGeometry_1.useItemGeometry)(block.id, ref);
|
|
25
|
-
const { urls, altText
|
|
25
|
+
const { urls, altText } = block.commonParams;
|
|
26
|
+
const caption = (0, sdk_1.getShownCaption)(block.commonParams);
|
|
26
27
|
const [ratios, setRatios] = (0, react_1.useState)({});
|
|
27
28
|
// an image already loaded when the page hydrates fires no load event of its own
|
|
28
29
|
const measure = (0, react_1.useCallback)((url, image) => {
|
|
@@ -12,6 +12,7 @@ const useCntrlContext_1 = require("../../../provider/useCntrlContext");
|
|
|
12
12
|
const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
|
|
13
13
|
const RichTextConverter_1 = require("../../../utils/RichTextConverter/RichTextConverter");
|
|
14
14
|
const detectLang_1 = require("../../../utils/detectLang");
|
|
15
|
+
const getHeadingTag_1 = require("../../../utils/getHeadingTag");
|
|
15
16
|
const textStylesRule_1 = require("../textStylesRule");
|
|
16
17
|
const richTextConverter = new RichTextConverter_1.RichTextConverter();
|
|
17
18
|
/**
|
|
@@ -19,6 +20,7 @@ const richTextConverter = new RichTextConverter_1.RichTextConverter();
|
|
|
19
20
|
* the text it reads as. Its text is set in the styles it was drawn with, its ranges styled over them.
|
|
20
21
|
*/
|
|
21
22
|
const StructuredRichText = ({ block }) => {
|
|
23
|
+
var _a;
|
|
22
24
|
const reactId = (0, react_1.useId)();
|
|
23
25
|
const id = `${reactId}-structured-text-${block.id}`;
|
|
24
26
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
@@ -27,11 +29,19 @@ const StructuredRichText = ({ block }) => {
|
|
|
27
29
|
const [content, rangeStyles] = (0, react_1.useMemo)(() => richTextConverter.toHtml(block, layouts, { isScaledToViewport: false }), [block, layouts]);
|
|
28
30
|
const lang = (0, react_1.useMemo)(() => (0, detectLang_1.detectLang)(block.commonParams.text), [block.commonParams.text]);
|
|
29
31
|
const isQuote = block.type === sdk_1.StructuredBlockType.Quote;
|
|
32
|
+
// only a text block of the stack flows in columns: a quote keeps to its box, a date to its line
|
|
33
|
+
const isText = block.type === sdk_1.StructuredBlockType.RichText;
|
|
34
|
+
const Wrapper = ((_a = (0, getHeadingTag_1.getHeadingTag)(block)) !== null && _a !== void 0 ? _a : 'div');
|
|
30
35
|
const layoutValues = [block.layoutParams];
|
|
31
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(
|
|
36
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Wrapper, { ref: setRef, lang: lang, className: `structured-text-${block.id}`, children: isQuote ? (0, jsx_runtime_1.jsx)("div", { className: `structured-quote-box-${block.id}`, children: content }) : content }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: id, children: [rangeStyles, `
|
|
37
|
+
.structured-text-${block.id} {
|
|
38
|
+
margin: 0;
|
|
39
|
+
}
|
|
40
|
+
`, `${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([layoutParams]) => {
|
|
32
41
|
var _a, _b;
|
|
33
42
|
return (`
|
|
34
43
|
${(0, textStylesRule_1.textStylesRule)(`.structured-text-${block.id}`, layoutParams)}
|
|
44
|
+
${isText ? (0, textStylesRule_1.textColumnsRule)(`.structured-text-${block.id}`, layoutParams) : ''}
|
|
35
45
|
${isQuote ? `
|
|
36
46
|
.structured-quote-box-${block.id} {
|
|
37
47
|
padding: ${((_a = layoutParams.boxPadding) !== null && _a !== void 0 ? _a : 0) * 100}vw;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.colorRule = exports.textStylesRule = void 0;
|
|
3
|
+
exports.colorRule = exports.textColumnsRule = exports.textStylesRule = void 0;
|
|
4
4
|
const color_1 = require("@cntrl-site/color");
|
|
5
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
6
|
const getFontFamilyValue_1 = require("../../utils/getFontFamilyValue");
|
|
6
7
|
/** A block's text styles as a CSS rule for `selector`, its lengths in viewport units as the block's own. */
|
|
7
8
|
function textStylesRule(selector, styles) {
|
|
@@ -29,6 +30,17 @@ function textStylesRule(selector, styles) {
|
|
|
29
30
|
`;
|
|
30
31
|
}
|
|
31
32
|
exports.textStylesRule = textStylesRule;
|
|
33
|
+
/** The columns a text block flows in, the gap between them in viewport units, and whether its lines hyphenate. */
|
|
34
|
+
function textColumnsRule(selector, { columns = 1, columnGap = 0, hyphens = sdk_1.Hyphens.None }) {
|
|
35
|
+
return `
|
|
36
|
+
${selector} {
|
|
37
|
+
hyphens: ${hyphens};
|
|
38
|
+
-webkit-hyphens: ${hyphens};
|
|
39
|
+
${columns > 1 ? `column-count: ${columns}; column-gap: ${columnGap * 100}vw; column-fill: balance;` : ''}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
exports.textColumnsRule = textColumnsRule;
|
|
32
44
|
/** A colour of the palette as CSS for `property`, with a fallback where oklch is not supported. */
|
|
33
45
|
function colorRule(selector, property, value) {
|
|
34
46
|
const color = color_1.CntrlColor.parse(value);
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getHeadingTag = void 0;
|
|
4
4
|
const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/** The heading tag a text is drawn in, where its params name one: a rich text item's, or a text block's. */
|
|
6
|
+
function getHeadingTag(element) {
|
|
7
|
+
const heading = element.commonParams.heading;
|
|
7
8
|
if (typeof heading !== 'string' || !HEADING_TAGS.has(heading))
|
|
8
9
|
return;
|
|
9
10
|
return heading;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.11.0-
|
|
3
|
+
"version": "1.11.0-2",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"author": "arsen@momdesign.nyc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,16 +24,15 @@
|
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@types/lodash.isequal": "^4.5.6",
|
|
26
26
|
"lodash.isequal": "^4.5.0",
|
|
27
|
-
"next": "^14.2.3",
|
|
27
|
+
"next": "^14.2.3 || ^15.0.0",
|
|
28
28
|
"react": "^18.3.1",
|
|
29
29
|
"react-dom": "^18.3.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@antfu/eslint-config": "^3.8.0",
|
|
33
32
|
"@cntrl-site/color": "^1.0.0",
|
|
34
|
-
"@cntrl-site/components": "^1.0.
|
|
33
|
+
"@cntrl-site/components": "^1.0.97-8",
|
|
35
34
|
"@cntrl-site/effects": "^1.4.2",
|
|
36
|
-
"@cntrl-site/sdk": "^1.29.0-
|
|
35
|
+
"@cntrl-site/sdk": "^1.29.0-2",
|
|
37
36
|
"@types/vimeo__player": "^2.18.0",
|
|
38
37
|
"@vimeo/player": "^2.25.0",
|
|
39
38
|
"franc-min": "^5.0.0",
|
|
@@ -42,6 +41,7 @@
|
|
|
42
41
|
"styled-jsx": "^5.0.2"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
44
|
+
"@antfu/eslint-config": "^3.8.0",
|
|
45
45
|
"@testing-library/jest-dom": "^6.4.8",
|
|
46
46
|
"@testing-library/react": "^16.0.0",
|
|
47
47
|
"@tsconfig/node16": "^1.0.3",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getLayoutStyles, HeaderImageStructuredBlock } from '@cntrl-site/sdk';
|
|
1
|
+
import { getLayoutStyles, getShownCaption, HeaderImageStructuredBlock } from '@cntrl-site/sdk';
|
|
2
2
|
import { FC, useId, useState } from 'react';
|
|
3
3
|
import JSXStyle from 'styled-jsx/style';
|
|
4
4
|
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
@@ -15,7 +15,8 @@ export const StructuredHeaderImage: FC<StructuredBlockItemProps<HeaderImageStruc
|
|
|
15
15
|
const { layouts } = useCntrlContext();
|
|
16
16
|
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
17
17
|
useItemGeometry(block.id, ref);
|
|
18
|
-
const { url, altText
|
|
18
|
+
const { url, altText } = block.commonParams;
|
|
19
|
+
const caption = getShownCaption(block.commonParams);
|
|
19
20
|
if (!url) return null;
|
|
20
21
|
const layoutValues: Record<string, any>[] = [block.layoutParams];
|
|
21
22
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getLayoutStyles, ImageStructuredBlock } from '@cntrl-site/sdk';
|
|
1
|
+
import { getLayoutStyles, getShownCaption, ImageStructuredBlock } from '@cntrl-site/sdk';
|
|
2
2
|
import { FC, useCallback, useId, useState } from 'react';
|
|
3
3
|
import JSXStyle from 'styled-jsx/style';
|
|
4
4
|
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
@@ -18,7 +18,8 @@ export const StructuredImage: FC<StructuredBlockItemProps<ImageStructuredBlock>>
|
|
|
18
18
|
const { layouts } = useCntrlContext();
|
|
19
19
|
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
20
20
|
useItemGeometry(block.id, ref);
|
|
21
|
-
const { urls, altText
|
|
21
|
+
const { urls, altText } = block.commonParams;
|
|
22
|
+
const caption = getShownCaption(block.commonParams);
|
|
22
23
|
const [ratios, setRatios] = useState<Record<string, number>>({});
|
|
23
24
|
// an image already loaded when the page hydrates fires no load event of its own
|
|
24
25
|
const measure = useCallback((url: string, image: HTMLImageElement | null) => {
|
|
@@ -5,8 +5,9 @@ import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
|
5
5
|
import { useItemGeometry } from '../../../ItemGeometry/useItemGeometry';
|
|
6
6
|
import { RichTextConverter } from '../../../utils/RichTextConverter/RichTextConverter';
|
|
7
7
|
import { detectLang } from '../../../utils/detectLang';
|
|
8
|
+
import { getHeadingTag } from '../../../utils/getHeadingTag';
|
|
8
9
|
import { StructuredBlockItemProps } from '../StructuredBlockItem';
|
|
9
|
-
import { colorRule, textStylesRule } from '../textStylesRule';
|
|
10
|
+
import { colorRule, textColumnsRule, textStylesRule } from '../textStylesRule';
|
|
10
11
|
|
|
11
12
|
type TextBlock = RichTextStructuredBlock | QuoteStructuredBlock | DateStructuredBlock;
|
|
12
13
|
|
|
@@ -28,16 +29,25 @@ export const StructuredRichText: FC<StructuredBlockItemProps<TextBlock>> = ({ bl
|
|
|
28
29
|
);
|
|
29
30
|
const lang = useMemo(() => detectLang(block.commonParams.text), [block.commonParams.text]);
|
|
30
31
|
const isQuote = block.type === StructuredBlockType.Quote;
|
|
32
|
+
// only a text block of the stack flows in columns: a quote keeps to its box, a date to its line
|
|
33
|
+
const isText = block.type === StructuredBlockType.RichText;
|
|
34
|
+
const Wrapper = (getHeadingTag(block) ?? 'div') as 'div';
|
|
31
35
|
const layoutValues: Record<string, any>[] = [block.layoutParams];
|
|
32
36
|
return (
|
|
33
37
|
<>
|
|
34
|
-
<
|
|
38
|
+
<Wrapper ref={setRef} lang={lang} className={`structured-text-${block.id}`}>
|
|
35
39
|
{isQuote ? <div className={`structured-quote-box-${block.id}`}>{content}</div> : content}
|
|
36
|
-
</
|
|
40
|
+
</Wrapper>
|
|
37
41
|
<JSXStyle id={id}>
|
|
38
42
|
{rangeStyles}
|
|
43
|
+
{`
|
|
44
|
+
.structured-text-${block.id} {
|
|
45
|
+
margin: 0;
|
|
46
|
+
}
|
|
47
|
+
`}
|
|
39
48
|
{`${getLayoutStyles(layouts, layoutValues, ([layoutParams]) => (`
|
|
40
49
|
${textStylesRule(`.structured-text-${block.id}`, layoutParams)}
|
|
50
|
+
${isText ? textColumnsRule(`.structured-text-${block.id}`, layoutParams) : ''}
|
|
41
51
|
${isQuote ? `
|
|
42
52
|
.structured-quote-box-${block.id} {
|
|
43
53
|
padding: ${(layoutParams.boxPadding ?? 0) * 100}vw;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CntrlColor } from '@cntrl-site/color';
|
|
2
|
-
import { StructuredBlockTextStyles } from '@cntrl-site/sdk';
|
|
2
|
+
import { Hyphens, StructuredBlockRichTextLayoutParams, StructuredBlockTextStyles } from '@cntrl-site/sdk';
|
|
3
3
|
import { getFontFamilyValue } from '../../utils/getFontFamilyValue';
|
|
4
4
|
|
|
5
5
|
/** A block's text styles as a CSS rule for `selector`, its lengths in viewport units as the block's own. */
|
|
@@ -28,6 +28,20 @@ export function textStylesRule(selector: string, styles: StructuredBlockTextStyl
|
|
|
28
28
|
`;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** The columns a text block flows in, the gap between them in viewport units, and whether its lines hyphenate. */
|
|
32
|
+
export function textColumnsRule(
|
|
33
|
+
selector: string,
|
|
34
|
+
{ columns = 1, columnGap = 0, hyphens = Hyphens.None }: Pick<StructuredBlockRichTextLayoutParams, 'columns' | 'columnGap' | 'hyphens'>
|
|
35
|
+
): string {
|
|
36
|
+
return `
|
|
37
|
+
${selector} {
|
|
38
|
+
hyphens: ${hyphens};
|
|
39
|
+
-webkit-hyphens: ${hyphens};
|
|
40
|
+
${columns > 1 ? `column-count: ${columns}; column-gap: ${columnGap * 100}vw; column-fill: balance;` : ''}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
/** A colour of the palette as CSS for `property`, with a fallback where oklch is not supported. */
|
|
32
46
|
export function colorRule(selector: string, property: string, value: string): string {
|
|
33
47
|
const color = CntrlColor.parse(value);
|
|
@@ -51,6 +51,9 @@ const title = block(StructuredBlockType.RichText, 'title', paragraph('The title'
|
|
|
51
51
|
const headerImage = block(StructuredBlockType.HeaderImage, 'key-image', { url: 'https://cdn.cntrl.site/key.jpg', altText: 'Key', caption: 'Under the key image' }, { opacity: 1 });
|
|
52
52
|
const text = block(StructuredBlockType.RichText, 'text', paragraph('Read the post'), {
|
|
53
53
|
...textStyles,
|
|
54
|
+
columns: 2,
|
|
55
|
+
columnGap: 0.01,
|
|
56
|
+
hyphens: 'auto',
|
|
54
57
|
rangeStyles: [{ start: 0, end: 4, style: 'FONTSIZE', value: '0.04' }]
|
|
55
58
|
});
|
|
56
59
|
const quote = block(StructuredBlockType.Quote, 'quote', { ...paragraph('A quote'), kind: 'boxed' }, {
|
|
@@ -146,6 +149,14 @@ describe('StructuredContent', () => {
|
|
|
146
149
|
expect(css()).toMatch(/\.structured-block-item-component \{[^}]*align-self: flex-start;/);
|
|
147
150
|
});
|
|
148
151
|
|
|
152
|
+
it('draws a text block served as a heading in its tag, without the tag\'s own margins, and other text plainly', () => {
|
|
153
|
+
const heading = block(StructuredBlockType.RichText, 'heading', { ...paragraph('The page'), heading: 'h1' }, { ...textStyles, rangeStyles: [] });
|
|
154
|
+
const { container } = draw({ ...section(false), structuredContent: [heading, text] } as Section);
|
|
155
|
+
expect(container.querySelector('.structured-text-heading')!.tagName).toBe('H1');
|
|
156
|
+
expect(container.querySelector('.structured-text-text')!.tagName).toBe('DIV');
|
|
157
|
+
expect(css()).toMatch(/\.structured-text-heading \{\s*margin: 0;/);
|
|
158
|
+
});
|
|
159
|
+
|
|
149
160
|
it('sets text in its styles, its ranges in viewport units', () => {
|
|
150
161
|
const { container } = draw(section(false));
|
|
151
162
|
expect(container.querySelector('.structured-text-text')!.textContent!.trim()).toBe('Read the post');
|
|
@@ -153,6 +164,13 @@ describe('StructuredContent', () => {
|
|
|
153
164
|
expect(css()).toContain('font-size: 4vw');
|
|
154
165
|
});
|
|
155
166
|
|
|
167
|
+
it('flows a text block in its columns, the gap between them in viewport units, hyphenating as set; a quote keeps to its box', () => {
|
|
168
|
+
draw(section(false));
|
|
169
|
+
expect(css()).toMatch(/\.structured-text-text \{[^}]*hyphens: auto;[^}]*column-count: 2; column-gap: 1vw; column-fill: balance;/);
|
|
170
|
+
expect(css()).not.toMatch(/\.structured-text-quote \{[^}]*column-count/);
|
|
171
|
+
expect(css()).not.toMatch(/\.structured-text-quote \{[^}]*hyphens/);
|
|
172
|
+
});
|
|
173
|
+
|
|
156
174
|
it('draws a quote in its box and a date as the text it reads as', () => {
|
|
157
175
|
const { container } = draw(section(false));
|
|
158
176
|
expect(container.querySelector('.structured-quote-box-quote')!.textContent!.trim()).toBe('A quote');
|
|
@@ -169,6 +187,18 @@ describe('StructuredContent', () => {
|
|
|
169
187
|
expect(container.querySelector('.structured-caption-gallery')!.textContent).toBe('Seen from the hill');
|
|
170
188
|
});
|
|
171
189
|
|
|
190
|
+
it('draws no caption an image has switched off, nor one that says nothing', () => {
|
|
191
|
+
const switchedOff = block(StructuredBlockType.Image, 'off', { urls: ['https://cdn.cntrl.site/a.jpg'], altText: '', caption: 'Kept for later', showCaption: false }, { opacity: 1 });
|
|
192
|
+
const blank = block(StructuredBlockType.Image, 'blank', { urls: ['https://cdn.cntrl.site/b.jpg'], altText: '', caption: ' ' }, { opacity: 1 });
|
|
193
|
+
const keyImage = { ...headerImage, commonParams: { ...headerImage.commonParams, showCaption: false } };
|
|
194
|
+
const { container } = draw({ ...section(false), structuredContent: [switchedOff, blank, keyImage] } as Section);
|
|
195
|
+
expect(container.querySelector('.structured-caption-off')).toBeNull();
|
|
196
|
+
expect(container.querySelector('.structured-caption-blank')).toBeNull();
|
|
197
|
+
expect(container.querySelector(`.structured-caption-${keyImage.id}`)).toBeNull();
|
|
198
|
+
expect(container.querySelector('.structured-gallery-image-off')).not.toBeNull();
|
|
199
|
+
expect(container.querySelector(`.structured-header-picture-${keyImage.id}`)).not.toBeNull();
|
|
200
|
+
});
|
|
201
|
+
|
|
172
202
|
it('fills a gallery\'s row whatever its images\' proportions, a lone portrait image as wide as the block', () => {
|
|
173
203
|
const portrait = block(StructuredBlockType.Image, 'portrait', { urls: ['https://cdn.cntrl.site/p.jpg'], altText: '', caption: '' }, { opacity: 1 });
|
|
174
204
|
const { container } = draw({ ...section(false), structuredContent: [portrait] } as Section);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { RichTextItem } from '@cntrl-site/sdk';
|
|
2
|
-
|
|
3
1
|
export type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
4
2
|
|
|
5
3
|
const HEADING_TAGS = new Set<string>(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/** The heading tag a text is drawn in, where its params name one: a rich text item's, or a text block's. */
|
|
6
|
+
export function getHeadingTag(element: { commonParams: object }): HeadingTag | undefined {
|
|
7
|
+
const heading = (element.commonParams as { heading?: unknown }).heading;
|
|
9
8
|
if (typeof heading !== 'string' || !HEADING_TAGS.has(heading)) return;
|
|
10
9
|
return heading as HeadingTag;
|
|
11
10
|
}
|