@pie-lib/math-toolbar 3.0.3-next.38 → 3.0.3-next.83

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/package.json CHANGED
@@ -1,45 +1,39 @@
1
1
  {
2
2
  "name": "@pie-lib/math-toolbar",
3
- "version": "3.0.3-next.38",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "3.0.3-next.83+92c2acb72",
4
7
  "description": "Math toolbar for editing math equations",
8
+ "keywords": [
9
+ "math",
10
+ "toolbar",
11
+ "equations",
12
+ "expressions"
13
+ ],
14
+ "main": "lib/index.js",
15
+ "module": "src/index.jsx",
16
+ "author": "",
17
+ "license": "ISC",
18
+ "repository": "pie-framework/pie-lib",
5
19
  "dependencies": {
6
20
  "@emotion/react": "^11.14.0",
7
- "@emotion/style": "^0.8.0",
21
+ "@emotion/styled": "^11.14.1",
8
22
  "@mui/icons-material": "^7.3.4",
9
23
  "@mui/material": "^7.3.4",
10
- "@pie-lib/math-input": "8.1.1-next.3",
11
- "@pie-lib/render-ui": "6.1.1-next.38",
24
+ "@pie-lib/math-input": "^8.1.0",
25
+ "@pie-lib/render-ui": "^6.1.0",
12
26
  "debug": "^4.1.1",
13
- "prop-types": "^15.7.2",
14
- "@pie-element/shared-lodash": "0.1.1-next.1"
15
- },
16
- "type": "module",
17
- "main": "./dist/index.js",
18
- "types": "./dist/index.d.ts",
19
- "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
23
- }
27
+ "lodash-es": "^4.17.23",
28
+ "prop-types": "^15.7.2"
24
29
  },
25
- "files": [
26
- "dist"
27
- ],
28
- "sideEffects": false,
29
- "scripts": {
30
- "build": "bun x vite build && bun x tsc --emitDeclarationOnly",
31
- "dev": "bun x vite",
32
- "test": "bun x vitest run"
30
+ "peerDependencies": {
31
+ "react": "^18.2.0",
32
+ "react-dom": "^18.2.0"
33
33
  },
34
34
  "devDependencies": {
35
- "vite": "^8.0.1",
36
- "typescript": "^5.9.3",
37
- "@vitejs/plugin-react": "^6.0.1",
38
- "@types/react": "^18.2.0",
39
- "@types/react-dom": "^18.2.0"
35
+ "@pie-lib/test-utils": "^2.0.2"
40
36
  },
41
- "peerDependencies": {
42
- "react": "^18.0.0",
43
- "react-dom": "^18.0.0"
44
- }
37
+ "scripts": {},
38
+ "gitHead": "92c2acb72564003dfda36a652f46cf0257cd1093"
45
39
  }
@@ -0,0 +1,74 @@
1
+ import { EditorAndPad } from '../editor-and-pad';
2
+ import { render } from '@testing-library/react';
3
+ import React from 'react';
4
+
5
+ describe('EditorAndPad', () => {
6
+ const defaultProps = {
7
+ classes: {},
8
+ classNames: {},
9
+ onBlur: jest.fn(),
10
+ };
11
+
12
+ beforeEach(() => {
13
+ jest.useFakeTimers();
14
+ });
15
+
16
+ afterEach(() => {
17
+ jest.useRealTimers();
18
+ });
19
+
20
+ it('renders with default props', () => {
21
+ const { container } = render(<EditorAndPad {...defaultProps} />);
22
+ expect(container.firstChild).toBeInTheDocument();
23
+ });
24
+
25
+ describe('autoFocus', () => {
26
+ it('focuses input immediately via setTimeout when autoFocus is true', () => {
27
+ const mockFocus = jest.fn();
28
+ const component = new EditorAndPad({ ...defaultProps, autoFocus: true });
29
+ component.input = { focus: mockFocus };
30
+
31
+ component.componentDidMount();
32
+
33
+ expect(mockFocus).not.toHaveBeenCalled();
34
+
35
+ jest.runAllTimers();
36
+
37
+ expect(mockFocus).toHaveBeenCalledTimes(1);
38
+ });
39
+
40
+ it('does not focus input when autoFocus is false', () => {
41
+ const mockFocus = jest.fn();
42
+ const component = new EditorAndPad({ ...defaultProps, autoFocus: false });
43
+ component.input = { focus: mockFocus };
44
+
45
+ component.componentDidMount();
46
+ jest.runAllTimers();
47
+
48
+ expect(mockFocus).not.toHaveBeenCalled();
49
+ });
50
+
51
+ it('does not focus when input ref is not set', () => {
52
+ const component = new EditorAndPad({ ...defaultProps, autoFocus: true });
53
+ component.input = null;
54
+
55
+ expect(() => {
56
+ component.componentDidMount();
57
+ jest.runAllTimers();
58
+ }).not.toThrow();
59
+ });
60
+
61
+ it('uses setTimeout with 0ms delay to defer focus', () => {
62
+ const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
63
+ const mockFocus = jest.fn();
64
+ const component = new EditorAndPad({ ...defaultProps, autoFocus: true });
65
+ component.input = { focus: mockFocus };
66
+
67
+ component.componentDidMount();
68
+
69
+ expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 0);
70
+
71
+ setTimeoutSpy.mockRestore();
72
+ });
73
+ });
74
+ });
@@ -0,0 +1,21 @@
1
+ import { RawPureToolbar } from '../index';
2
+ import { render } from '@testing-library/react';
3
+ import React from 'react';
4
+
5
+ describe('RawPureToolbar', () => {
6
+ const defaultProps = {
7
+ classes: {},
8
+ controlledKeypad: true,
9
+ showKeypad: true,
10
+ };
11
+
12
+ it('renders with DONE button if hideDoneButton is not defined', () => {
13
+ const { container } = render(<RawPureToolbar {...defaultProps} />);
14
+ expect(container.firstChild).toBeInTheDocument();
15
+ });
16
+
17
+ it('renders without DONE button if hideDoneButton value is true', () => {
18
+ const { container } = render(<RawPureToolbar {...defaultProps} hideDoneButton={true} />);
19
+ expect(container.firstChild).toBeInTheDocument();
20
+ });
21
+ });
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import MathPreview from '../math-preview';
4
+
5
+ describe('MathPreview', () => {
6
+ const defaultProps = {
7
+ latex: 'sqrt(5)',
8
+ classes: {},
9
+ isSelected: false,
10
+ onFocus: jest.fn(),
11
+ onBlur: jest.fn(),
12
+ };
13
+
14
+ it('renders with default props', () => {
15
+ const { container } = render(<MathPreview {...defaultProps} />);
16
+ expect(container.firstChild).toBeInTheDocument();
17
+ });
18
+ });
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+
3
+ import IconButton from '@mui/material/IconButton';
4
+ import Check from '@mui/icons-material/Check';
5
+ import { styled } from '@mui/material/styles';
6
+ import PropTypes from 'prop-types';
7
+
8
+ const StyledIconButton = styled(IconButton)(({ theme, hideBackground }) => ({
9
+ verticalAlign: 'top',
10
+ width: '28px',
11
+ height: '28px',
12
+ color: '#00bb00',
13
+ ...(hideBackground && {
14
+ backgroundColor: theme.palette.common.white,
15
+ '&:hover': {
16
+ backgroundColor: theme.palette.grey[200],
17
+ },
18
+ }),
19
+ '& .MuiIconButton-label': {
20
+ position: 'absolute',
21
+ top: '2px',
22
+ },
23
+ }));
24
+
25
+ export const RawDoneButton = ({ onClick, hideBackground }) => (
26
+ <StyledIconButton aria-label="Done" onClick={onClick} hideBackground={hideBackground} size="large">
27
+ <Check />
28
+ </StyledIconButton>
29
+ );
30
+
31
+ RawDoneButton.propTypes = {
32
+ onClick: PropTypes.func,
33
+ hideBackground: PropTypes.bool,
34
+ };
35
+
36
+ export const DoneButton = RawDoneButton;