Skip to content

Commit ae034a5

Browse files
committed
Fixed: Move createSummernoteButton to ReactSummernote
1 parent 2cc0ec0 commit ae034a5

File tree

10 files changed

+67
-157
lines changed

10 files changed

+67
-157
lines changed

.changeset/pretty-jars-scream.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@easylogic/react-summernote-lite': patch
3+
'@easylogic/react-summernote-bs4': patch
4+
'@easylogic/react-summernote': patch
5+
---
6+
7+
Fixed: Move createSummernoteButton to ReactSummernote

apps/dev-storybook/src/stories/basic-api/createRange.stories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const CreateRangeComponent: React.FC = () => {
2828
<ReactSummernoteLite
2929
id="sample"
3030
onInit={({ note }) => {
31-
nodeRef.current = note;
31+
const range = note.summernote('createRange');
32+
console.log(range);
3233
}}
3334
/>
3435
`}</pre>

apps/dev-storybook/src/stories/basic-api/focus.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const FocusTemplate: Story = {
1616
let $note: any = null;
1717
function doFocus() {
1818
if ($note) {
19-
$note.summernote('Focus');
19+
$note.summernote('focus');
2020
}
2121
}
2222

apps/dev-storybook/src/stories/basic-api/fullscreen.toggle.stories.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import React from 'react';
3-
import { ReactSummernoteLite, SummernoteCallbackInitProps } from '@easylogic/react-summernote-lite';
3+
import {
4+
ReactSummernoteLite,
5+
SummernoteCallbackInitProps,
6+
SummernoteJQueryInstance,
7+
} from '@easylogic/react-summernote-lite';
48

59
const meta = {
610
title: 'Basic API/FullScreenToggle',
@@ -11,7 +15,7 @@ export default meta;
1115
type Story = StoryObj<typeof meta>;
1216

1317
const FullScreenToggleComponent: React.FC = () => {
14-
const noteRef = React.useRef<any>(null);
18+
const noteRef = React.useRef<SummernoteJQueryInstance | null>(null);
1519

1620
const doFullScreen = React.useCallback(() => {
1721
if (noteRef.current) {

apps/dev-storybook/src/stories/basic-api/undo.redo.stories.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { Meta, StoryObj } from '@storybook/react';
3-
import { action } from '@storybook/addon-actions';
43
import { ReactSummernoteLite } from '@easylogic/react-summernote-lite';
54

65
const meta: Meta<typeof ReactSummernoteLite> = {
@@ -18,14 +17,12 @@ export const UndoAndRedo: Story = {
1817
const doUndo = () => {
1918
if ($note.current) {
2019
$note.current.summernote('undo');
21-
action('undo')();
2220
}
2321
};
2422

2523
const doRedo = () => {
2624
if ($note.current) {
2725
$note.current.summernote('redo');
28-
action('redo')();
2926
}
3027
};
3128

@@ -39,7 +36,6 @@ export const UndoAndRedo: Story = {
3936
{...args}
4037
onInit={({ note }) => {
4138
$note.current = note;
42-
action('onInit')(note);
4339
}}
4440
/>
4541
</div>

json

-58
This file was deleted.

packages/react-summernote-bs4/src/summernote/ReactSummernoteBS4.tsx

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,9 @@
1-
import React from 'react';
2-
import * as ReactDOM from 'react-dom/client';
31
import 'jquery';
42
import 'popper.js';
53
import 'bootstrap';
64
import 'summernote/dist/summernote-bs4';
75
import 'summernote/dist/summernote-bs4.css';
8-
import {
9-
Summernote,
10-
SummernoteProps,
11-
SummernoteContext,
12-
SummernoteCustomButtonProps,
13-
} from '@easylogic/react-summernote';
14-
15-
interface ButtonProps {
16-
container?: string;
17-
tooltip?: string;
18-
contents?: string;
19-
click?: () => void;
20-
}
21-
22-
export function createSummernoteButton(opt: SummernoteCustomButtonProps): any {
23-
return (context: SummernoteContext) => {
24-
let buttonProps: ButtonProps = {
25-
container: opt.container || 'body',
26-
tooltip: opt.tooltip || 'sample',
27-
};
28-
29-
if (opt.title && !opt.element) {
30-
buttonProps.contents = opt.title;
31-
buttonProps.click = () => {
32-
opt?.onClick?.(context);
33-
};
34-
return context.ui.button(buttonProps).render();
35-
} else {
36-
const button = context.ui.button(buttonProps);
37-
const el = button.render(); // return button as jquery object
38-
39-
if (opt?.element) {
40-
const props = { context, ...opt.props };
41-
ReactDOM.createRoot(el[0]).render(React.createElement(opt.element, props));
42-
}
43-
44-
return el;
45-
}
46-
};
47-
}
6+
import { Summernote, SummernoteProps } from '@easylogic/react-summernote';
487

498
export function ReactSummernoteBS4({ children, ...props }: SummernoteProps) {
509
return <Summernote {...props}>{children}</Summernote>;

packages/react-summernote-lite/src/summernote/ReactSummernoteLite.tsx

+1-46
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,6 @@
1-
import React from 'react';
2-
import * as ReactDOM from 'react-dom/client';
31
import 'summernote/dist/summernote-lite';
42
import 'summernote/dist/summernote-lite.css';
5-
import {
6-
Summernote,
7-
SummernoteContext,
8-
SummernoteCustomButtonProps,
9-
SummernoteProps,
10-
} from '@easylogic/react-summernote';
11-
12-
interface ButtonProps {
13-
container?: string;
14-
tooltip?: string;
15-
contents?: string;
16-
click?: () => void;
17-
}
18-
19-
export function createSummernoteButton(opt: SummernoteCustomButtonProps): any {
20-
return (context: SummernoteContext) => {
21-
let buttonProps: ButtonProps = {
22-
container: opt.container || 'body',
23-
tooltip: opt.tooltip || 'sample',
24-
};
25-
26-
if (opt.title && !opt.element && !opt.render) {
27-
buttonProps.contents = opt.title;
28-
buttonProps.click = () => {
29-
opt?.onClick?.(context);
30-
};
31-
return context.ui.button(buttonProps).render();
32-
} else {
33-
const button = context.ui.button(buttonProps);
34-
const el = button.render(); // return button as jquery object
35-
const props = { context, ...opt.props };
36-
37-
if (opt?.render) {
38-
ReactDOM.createRoot(el[0]).render(opt.render(props));
39-
}
40-
41-
if (opt?.element && React.isValidElement(React.createElement(opt.element, props))) {
42-
ReactDOM.createRoot(el[0]).render(React.createElement(opt.element, props));
43-
}
44-
45-
return el;
46-
}
47-
};
48-
}
3+
import { Summernote, SummernoteProps } from '@easylogic/react-summernote';
494

505
export function ReactSummernoteLite({ children, ...props }: SummernoteProps) {
516
return <Summernote {...props}>{children}</Summernote>;

packages/react-summernote/src/component/Summernote.tsx

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import { useEffect, useId, useState } from 'react';
1+
import React, { useEffect, useId, useState } from 'react';
2+
import * as ReactDOM from 'react-dom/client';
23
import $ from 'jquery';
3-
import { SummernoteProps, SummernoteContext, SummernotePluginInterface, SummernoteCallbackInitProps } from '../types';
4+
import {
5+
SummernoteProps,
6+
SummernoteContext,
7+
SummernotePluginInterface,
8+
SummernoteCallbackInitProps,
9+
SummernoteCustomButtonProps,
10+
} from '../types';
411

512
export type SummernoteEventNames =
613
| 'init'
@@ -56,6 +63,44 @@ export function createSummernotePlugin(name: string, PluginClass: SummernotePlug
5663
});
5764
}
5865

66+
interface ButtonProps {
67+
container?: string;
68+
tooltip?: string;
69+
contents?: string;
70+
click?: () => void;
71+
}
72+
73+
export function createSummernoteButton(opt: SummernoteCustomButtonProps): any {
74+
return (context: SummernoteContext) => {
75+
let buttonProps: ButtonProps = {
76+
container: opt.container || 'body',
77+
tooltip: opt.tooltip || 'sample',
78+
};
79+
80+
if (opt.title && !opt.element && !opt.render) {
81+
buttonProps.contents = opt.title;
82+
buttonProps.click = () => {
83+
opt?.onClick?.(context);
84+
};
85+
return context.ui.button(buttonProps).render();
86+
} else {
87+
const button = context.ui.button(buttonProps);
88+
const el = button.render(); // return button as jquery object
89+
const props = { context, ...opt.props };
90+
91+
if (opt?.render) {
92+
ReactDOM.createRoot(el[0]).render(opt.render(props));
93+
}
94+
95+
if (opt?.element && React.isValidElement(React.createElement(opt.element, props))) {
96+
ReactDOM.createRoot(el[0]).render(React.createElement(opt.element, props));
97+
}
98+
99+
return el;
100+
}
101+
};
102+
}
103+
59104
export function setSummernoteLang(langInfo: any) {
60105
const jQuery = $ as any;
61106

packages/react-summernote/src/types/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export type SummernoteCommand =
9191
| 'formatH5'
9292
| 'formatH6'
9393
| 'isEmpty'
94-
| string;
94+
| 'fullscreen.toggle'
95+
| (string & {});
9596

9697
export interface SummernoteCommandCallback {
9798
(command: 'justify' | 'justifyLeft' | 'justifyCenter' | 'justifyRight' | 'justifyFull'): void;

0 commit comments

Comments
 (0)