Skip to content

Commit 3baffd8

Browse files
authored
Merge pull request #2282 from pie-framework/develop
fix: PIE-674, PIE-442, PIE-575
2 parents 1747b14 + 92be605 commit 3baffd8

5 files changed

Lines changed: 55 additions & 2 deletions

File tree

packages/editable-html-tip-tap/src/components/TiptapContainer.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,25 @@ function TiptapContainer(props) {
171171
el.style.whiteSpace = 'nowrap';
172172
el.textContent = 'W'.repeat(props.charactersLimit);
173173

174-
rootRef.current.appendChild(el);
174+
// Copy font styles from the editor container so the width measurement reflects the actual font
175+
const computedStyles = window.getComputedStyle(rootRef.current);
176+
const fontStyleProps = [
177+
'fontFamily',
178+
'fontSize',
179+
'fontWeight',
180+
'fontStyle',
181+
'letterSpacing',
182+
'wordSpacing',
183+
'textTransform',
184+
'lineHeight',
185+
];
186+
187+
fontStyleProps.forEach((prop) => {
188+
el.style[prop] = computedStyles[prop];
189+
});
175190

191+
document.body.appendChild(el);
176192
setAdjustedWidth(`${el.offsetWidth + 27}px`);
177-
178193
el.remove();
179194
}
180195
}, [props.adjustWidthForLimit, props.charactersLimit]);

packages/editable-html-tip-tap/src/components/__tests__/InlineDropdown.test.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,20 @@ describe('InlineDropdown', () => {
464464
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
465465
});
466466

467+
it('does not close toolbar when clicking the page scrollbar (documentElement)', async () => {
468+
const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
469+
470+
await waitFor(() => {
471+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
472+
});
473+
474+
fireEvent.mouseDown(document.documentElement);
475+
476+
await waitFor(() => {
477+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
478+
});
479+
});
480+
467481
it('renders delete control on portaled custom toolbar when container el is set', async () => {
468482
const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
469483
expect(await findByLabelText('Delete')).toBeInTheDocument();

packages/editable-html-tip-tap/src/components/respArea/InlineDropdown.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ const InlineDropdown = (props) => {
9393
}
9494
}, [editor, node, selected]);
9595

96+
97+
98+
const isScrollbarClicked = (event) =>
99+
event.clientX > document.documentElement.clientWidth ||
100+
event.clientY > document.documentElement.clientHeight ||
101+
event.target === document.documentElement;
102+
103+
96104
useEffect(() => {
97105
// Calculate position relative to selection
98106
const bodyRect = document.body.getBoundingClientRect();
@@ -105,6 +113,10 @@ const InlineDropdown = (props) => {
105113
});
106114

107115
const handleClickOutside = (event) => {
116+
117+
if( isScrollbarClicked(event) ) {
118+
return;
119+
}
108120
const insideSomeEditor = event.target.closest('[data-toolbar-for]');
109121

110122
if (

packages/math-rendering/src/__tests__/render-math.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
3+
import { TeX } from 'mathjax-full/js/input/tex';
34
import renderMath, { fixMathElement } from '../render-math';
45
import { times } from 'lodash-es';
56

@@ -140,6 +141,16 @@ describe('render-math', () => {
140141
});
141142
});
142143

144+
it('registers the abs macro in the TeX config', () => {
145+
const div = document.createElement('div');
146+
147+
renderMath(div);
148+
149+
const texConfig = TeX.mock.calls[0][0];
150+
151+
expect(texConfig.macros.abs).toEqual(['\\left|#1\\right|', 1]);
152+
});
153+
143154
it('wraps the math containing element the right way', () => {
144155
const { container } = render(
145156
<div>

packages/math-rendering/src/render-math.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const createMathMLInstance = (opts, docProvided = document) => {
132132
overarc: '\\overparen',
133133
napprox: '\\not\\approx',
134134
longdiv: '\\enclose{longdiv}',
135+
abs: ['\\left|#1\\right|', 1],
135136
};
136137

137138
const texConfig = opts.useSingleDollar

0 commit comments

Comments
 (0)