@cntrl-site/sdk-nextjs 1.11.0 → 1.11.1

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.
@@ -68,7 +68,8 @@ class RichTextConverter {
68
68
  const content = text.slice(block.start, block.end + 1);
69
69
  const entities = [...((_a = block.entities) !== null && _a !== void 0 ? _a : [])].sort((a, b) => a.start - b.start);
70
70
  const typeClass = hasLists ? ` ${(_b = LIST_ITEM_CLASSES[block.type]) !== null && _b !== void 0 ? _b : 'rt-paragraph'}` : '';
71
- if (content.length === 1) {
71
+ // an empty line keeps its height, as in the editor; a text never typed into comes without even its line break
72
+ if (content === '' || content === '\n') {
72
73
  const id = `rt_${richText.id}_br_${blockIndex}`;
73
74
  root.push((0, jsx_runtime_1.jsx)("div", { className: `${id}${typeClass}`, children: (0, jsx_runtime_1.jsx)("br", {}) }, id));
74
75
  layouts.forEach(l => {
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.1",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -60,6 +60,26 @@ describe('RichTextConverter', () => {
60
60
  expect(styles).toContain('background-color: rgba(255, 255, 0, 1)');
61
61
  });
62
62
 
63
+ it('keeps an empty line a line tall, in a text never typed into as well, and a one-letter last line its letter', () => {
64
+ const untyped: RichTextSource = {
65
+ id: 'text',
66
+ commonParams: { text: '', blocks: [{ start: 0, end: 0, type: 'unstyled', entities: [] }] },
67
+ layoutParams: { desktop: { rangeStyles: [], textAlign: TextAlign.Left } }
68
+ };
69
+ const emptied = text([{ text: '' }], []);
70
+ for (const source of [untyped, emptied]) {
71
+ const { container } = render(<>{converter.toHtml(source, layouts)[0]}</>);
72
+ expect(container.innerHTML).toBe('<div class="rt_text_br_0"><br></div>');
73
+ }
74
+ const unterminated: RichTextSource = {
75
+ id: 'text',
76
+ commonParams: { text: 'a', blocks: [{ start: 0, end: 1, type: 'unstyled', entities: [] }] },
77
+ layoutParams: { desktop: { rangeStyles: [], textAlign: TextAlign.Left } }
78
+ };
79
+ const { container } = render(<>{converter.toHtml(unterminated, layouts)[0]}</>);
80
+ expect(container.textContent).toBe('a');
81
+ });
82
+
63
83
  it('leaves text without lists as it was', () => {
64
84
  const [content, styles] = converter.toHtml(text([{ text: 'Plain' }]), layouts);
65
85
  const { container } = render(<>{content}</>);
@@ -125,7 +125,8 @@ export class RichTextConverter {
125
125
  const content = text.slice(block.start, block.end + 1);
126
126
  const entities = [...(block.entities ?? [])].sort((a, b) => a.start - b.start);
127
127
  const typeClass = hasLists ? ` ${LIST_ITEM_CLASSES[block.type] ?? 'rt-paragraph'}` : '';
128
- if (content.length === 1) {
128
+ // an empty line keeps its height, as in the editor; a text never typed into comes without even its line break
129
+ if (content === '' || content === '\n') {
129
130
  const id = `rt_${richText.id}_br_${blockIndex}`;
130
131
  root.push(<div key={id} className={`${id}${typeClass}`}><br /></div>);
131
132
  layouts.forEach(l => {