Skip to content

Commit 185cf43

Browse files
authored
INT-3291: Support for TinyMCE Version 7 release (#506)
* INT-3291: Add tinymce 7 as a dep * INT-3291: Added licenseKey prop * INT-3291: Test against version 7 as well * INT-3291: Add technical reference to Editor's JSDoc * INT-3291: Remove @storybook/addon-onboarding dev dep * INT-3291: Updated stories to use newer StoryObj API * INT-3291: Change default `cloudChannel` to '7' * INT-3291: Upgrade dependencies * INT-3291: Disable storybook actions * INT-3291: Fix version 7 discrepency that's carried over from 6 * INT-3291: Upgrade storybook to use react-vite instead of webpack * INT-3291: Use an `as` assertion for `cloudChannel` * INT-3291: Added input and composition related event handlers * INT-3291: Turn off no-unsafe-arguments eslint rule as certain internal testing libraries return generics containing `any` * INT-3291: Updated codesandbox link * INT-3291: Added changelog entries
1 parent dbdf516 commit 185cf43

File tree

15 files changed

+4655
-4204
lines changed

15 files changed

+4655
-4204
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"sourceType": "module"
1212
},
1313
"rules": {
14-
"@tinymce/prefer-fun": "off"
14+
"@tinymce/prefer-fun": "off",
15+
"@typescript-eslint/no-unsafe-argument": "off"
1516
}
1617
}
1718
]

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assignees: ''
99

1010
**What is the current behavior?**
1111

12-
**Please provide the steps to reproduce and if possible a minimal demo of the problem via [codesandbox.io](https://codesandbox.io/s/tinymce-tinymce-react-p6bqty?file=/src/index.js) or similar.**
12+
**Please provide the steps to reproduce and if possible a minimal demo of the problem via [codesandbox.io](https://codesandbox.io/p/sandbox/tinymce-react-yny726?file=src/index.tsx) or similar.**
1313

1414
**What is the expected behavior?**
1515

.storybook/main.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import type { StorybookConfig } from "@storybook/react-webpack5";
2-
3-
const config: StorybookConfig = {
1+
export default {
42
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
53
addons: [
64
"@storybook/addon-links",
75
"@storybook/addon-essentials",
8-
"@storybook/addon-onboarding",
96
"@storybook/addon-interactions",
107
],
11-
framework: {
12-
name: "@storybook/react-webpack5",
13-
options: {},
8+
core: {
9+
disableTelemetry: true
1410
},
1511
docs: {
1612
autodocs: "tag",
1713
},
18-
};
19-
export default config;
14+
framework: {
15+
name: "@storybook/react-vite",
16+
options: {}
17+
}
18+
};

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
## 5.0.0 - 2024-03-25
10+
11+
### Added
12+
- Added `licenseKey` property that overrides the TinyMCE `license_key` init property. #INT-3291
13+
- Added events `onInput`, `onCompositionEnd`, `onCompositionStart` & `onCompositionUpdate`. #INT-3291
14+
- Added a JSDoc link to the TinyMCE 7 React Technical Reference docs page. #INT-3291
15+
16+
### Fixed
17+
- `readonly` init property is now properly typed as undefined, as it's overriden by the integration. #INT-3287
18+
19+
### Changed
20+
- Updated dependencies. #INT-3291
21+
- Changed default cloudChannel to `'7'`. #INT-3291
22+
23+
### Improved
24+
- Improved `cloudChannel` type. #INT-3291
25+
- Updated to Storybook v8 and it now uses react-vite as a bundler/builder instead of webpack. #INT-3291
26+
- Storybook examples now use CSFv3 components. #INT-3291
27+
- Tests now run against TinyMCE version 7 as well. #INT-3291
28+
929
## 4.3.2 - 2023-11-20
1030

1131
### Fixed

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"license": "MIT",
2828
"dependencies": {
2929
"prop-types": "^15.6.2",
30-
"tinymce": "^6.0.0 || ^5.5.1"
30+
"tinymce": "^7.0.0 || ^6.0.0 || ^5.5.1"
3131
},
3232
"peerDependencies": {
3333
"react": "^18.0.0 || ^17.0.1 || ^16.7.0",
@@ -39,23 +39,21 @@
3939
"@babel/preset-react": "^7.23.3",
4040
"@babel/preset-typescript": "^7.23.3",
4141
"@ephox/agar": "^8.0.0-alpha.0",
42-
"@ephox/bedrock-client": "^13.0.0",
43-
"@ephox/bedrock-server": "^13.6.0",
42+
"@ephox/bedrock-client": "^14.1.1",
43+
"@ephox/bedrock-server": "^14.1.3",
4444
"@ephox/katamari": "^9.1.5",
4545
"@ephox/mcagar": "^9.0.0-alpha.0",
4646
"@ephox/sand": "^6.0.9",
4747
"@ephox/sugar": "^9.2.1",
48-
"@storybook/addon-essentials": "^7.5.3",
49-
"@storybook/addon-interactions": "^7.5.3",
50-
"@storybook/addon-links": "^7.5.3",
51-
"@storybook/addon-onboarding": "^1.0.8",
52-
"@storybook/blocks": "^7.5.3",
53-
"@storybook/react": "^7.5.3",
54-
"@storybook/react-webpack5": "^7.5.3",
55-
"@storybook/testing-library": "^0.2.2",
48+
"@storybook/addon-essentials": "^8.0.2",
49+
"@storybook/addon-interactions": "^8.0.2",
50+
"@storybook/addon-links": "^8.0.2",
51+
"@storybook/blocks": "^8.0.2",
52+
"@storybook/react": "^8.0.2",
53+
"@storybook/react-vite": "^8.0.2",
5654
"@tinymce/beehive-flow": "^0.19.0",
5755
"@tinymce/eslint-plugin": "^2.3.1",
58-
"@tinymce/miniature": "^5.0.1",
56+
"@tinymce/miniature": "^6.0.0",
5957
"@types/node": "^20.9.0",
6058
"@types/prop-types": "^15.7.10",
6159
"@types/react": "^18.2.37",
@@ -64,11 +62,13 @@
6462
"react": "^18.2.0",
6563
"react-dom": "^18.2.0",
6664
"rimraf": "^5.0.5",
67-
"storybook": "^7.5.3",
65+
"storybook": "^8.0.2",
6866
"tinymce-4": "npm:tinymce@^4",
6967
"tinymce-5": "npm:tinymce@^5",
7068
"tinymce-6": "npm:tinymce@^6",
71-
"typescript": "~5.2.2"
69+
"tinymce-7": "npm:tinymce@^7",
70+
"typescript": "~5.4.3",
71+
"vite": "^5.2.2"
7272
},
7373
"version": "4.3.3-rc",
7474
"name": "@tinymce/tinymce-react"

src/main/ts/Events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export interface INativeEvents {
88
onBeforePaste: EEventHandler<'beforepaste'>;
99
onBlur: EEventHandler<'blur'>;
1010
onClick: EEventHandler<'click'>;
11+
onCompositionEnd: EEventHandler<'compositionend'>;
12+
onCompositionStart: EEventHandler<'compositionstart'>;
13+
onCompositionUpdate: EEventHandler<'compositionupdate'>;
1114
onContextMenu: EEventHandler<'contextmenu'>;
1215
onCopy: EEventHandler<'copy'>;
1316
onCut: EEventHandler<'cut'>;
@@ -21,6 +24,7 @@ export interface INativeEvents {
2124
onFocus: EEventHandler<'focus'>;
2225
onFocusIn: EEventHandler<'focusin'>;
2326
onFocusOut: EEventHandler<'focusout'>;
27+
onInput: EEventHandler<'input'>;
2428
onKeyDown: EEventHandler<'keydown'>;
2529
onKeyPress: EEventHandler<'keypress'>;
2630
onKeyUp: EEventHandler<'keyup'>;

src/main/ts/components/Editor.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import { Bookmark, Editor as TinyMCEEditor, EditorEvent, TinyMCE } from 'tinymce
88

99
type EditorOptions = Parameters<TinyMCE['init']>[0];
1010

11+
export type Version = `${'4' | '5' | '6' | '7'}${'' | '-dev' | '-testing' | `.${number}` | `.${number}.${number}`}`;
12+
1113
export interface IProps {
1214
apiKey: string;
1315
id: string;
1416
inline: boolean;
1517
initialValue: string;
1618
onEditorChange: (a: string, editor: TinyMCEEditor) => void;
1719
value: string;
18-
init: EditorOptions & Partial<Record<'selector' | 'target' | 'readonly', undefined>>;
20+
init: EditorOptions & Partial<Record<'selector' | 'target' | 'readonly' | 'license_key', undefined>>;
1921
tagName: string;
20-
cloudChannel: string;
22+
cloudChannel: Version;
2123
plugins: NonNullable<EditorOptions['plugins']>;
2224
toolbar: NonNullable<EditorOptions['toolbar']>;
2325
disabled: boolean;
@@ -29,15 +31,19 @@ export interface IProps {
2931
defer?: boolean;
3032
delay?: number;
3133
};
34+
licenseKey: string;
3235
}
3336

3437
export interface IAllProps extends Partial<IProps>, Partial<IEvents> { }
3538

39+
/**
40+
* @see {@link https://www.tiny.cloud/docs/tinymce/7/react-ref/} for the TinyMCE React Technical Reference
41+
*/
3642
export class Editor extends React.Component<IAllProps> {
3743
public static propTypes: IEditorPropTypes = EditorPropTypes;
3844

3945
public static defaultProps: Partial<IAllProps> = {
40-
cloudChannel: '6'
46+
cloudChannel: '7',
4147
};
4248

4349
public editor?: TinyMCEEditor;
@@ -206,7 +212,7 @@ export class Editor extends React.Component<IAllProps> {
206212
});
207213
}
208214
// fallback to the cloud when the tinymceScriptSrc is not specified
209-
const channel = this.props.cloudChannel;
215+
const channel = this.props.cloudChannel as Version; // `cloudChannel` is in `defaultProps`, so it's always defined.
210216
const apiKey = this.props.apiKey ? this.props.apiKey : 'no-api-key';
211217
const cloudTinyJs = `https://cdn.tiny.cloud/1/${apiKey}/tinymce/${channel}/tinymce.min.js`;
212218
return [{ src: cloudTinyJs, async, defer }];
@@ -346,6 +352,7 @@ export class Editor extends React.Component<IAllProps> {
346352
inline: this.inline,
347353
plugins: mergePlugins(this.props.init?.plugins, this.props.plugins),
348354
toolbar: this.props.toolbar ?? this.props.init?.toolbar,
355+
...(this.props.licenseKey ? { license_key: this.props.licenseKey } : {}),
349356
setup: (editor) => {
350357
this.editor = editor;
351358
this.bindHandlers({});

src/main/ts/components/EditorPropTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export const eventPropTypes: IEventPropTypes = {
2323
onClick: PropTypes.func,
2424
onContextMenu: PropTypes.func,
2525
onCommentChange: PropTypes.func,
26+
onCompositionEnd: PropTypes.func,
27+
onCompositionStart: PropTypes.func,
28+
onCompositionUpdate: PropTypes.func,
2629
onCopy: PropTypes.func,
2730
onCut: PropTypes.func,
2831
onDblclick: PropTypes.func,
@@ -41,6 +44,7 @@ export const eventPropTypes: IEventPropTypes = {
4144
onGetContent: PropTypes.func,
4245
onHide: PropTypes.func,
4346
onInit: PropTypes.func,
47+
onInput: PropTypes.func,
4448
onKeyDown: PropTypes.func,
4549
onKeyPress: PropTypes.func,
4650
onKeyUp: PropTypes.func,
@@ -84,6 +88,7 @@ export const eventPropTypes: IEventPropTypes = {
8488

8589
export const EditorPropTypes: IEditorPropTypes = {
8690
apiKey: PropTypes.string,
91+
licenseKey: PropTypes.string,
8792
id: PropTypes.string,
8893
inline: PropTypes.bool,
8994
init: PropTypes.object,

0 commit comments

Comments
 (0)