Skip to content

Commit 867a2e1

Browse files
committed
Another go at React docs
1 parent 367992d commit 867a2e1

File tree

7 files changed

+110
-81
lines changed

7 files changed

+110
-81
lines changed

modules/ROOT/pages/react-cloud.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
:productSource: cloud
66

77

8-
This guide shows how to integrate TinyMCE from Tiny Cloud into a React project using link:https://github.com/tinymce/tinymce-react[{productname} React component]
8+
This guide shows how to integrate TinyMCE from Tiny Cloud into a React application using link:https://github.com/tinymce/tinymce-react[{productname} React component].
99

1010
include::partial$integrations/react-quick-start.adoc[]

modules/ROOT/pages/react-pm-bundle.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
:productSource: package-manager
66
:productUse: bundle
77

8-
This guide shows how to bundle TinyMCE in a React project with link:https://github.com/tinymce/tinymce-react[{productname} React component]
8+
This guide shows how to integrate TinyMCE in a React application with link:https://github.com/tinymce/tinymce-react[{productname} React component].
99

1010
include::partial$integrations/react-quick-start.adoc[]

modules/ROOT/pages/react-pm-host.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
:productSource: package-manager
77
:productUse: host
88

9-
This guide shows how to self-host TinyMCE in a React project using link:https://github.com/tinymce/tinymce-react[{productname} React component]
9+
This guide shows how to self-host TinyMCE in a React application using link:https://github.com/tinymce/tinymce-react[{productname} React component].
1010

1111
include::partial$integrations/react-quick-start.adoc[]
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
= Bundling TinyMCE from .zip package in React
22
:navtitle: Using a .zip package with a module bundler
3-
:description: A guide on integrating a .zip version of TinyMCE in a React project by bundling it.
3+
:description: A guide on bundling a .zip version of TinyMCE in a React project.
44
:keywords: integration, integrate, react, reactjs, vite, tinymce-react, bundle
55
:productSource: zip
66
:productUse: bundle
77

8+
This shows how to self-host and bundle {productname} from a `.zip` package into a React application.
9+
810
include::partial$integrations/react-quick-start.adoc[]
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
= Self-host TinyMCE from .zip package in React
1+
= Lazy-loading TinyMCE from .zip package in React
22
:page-aliases: react-zip.adoc
33
:navtitle: Using a TinyMCE .zip package in React
4-
:description: A guide on self-hosting a .zip version of TinyMCE into React.
4+
:description: A guide on lazy-loading a .zip version of TinyMCE in a React application.
55
:keywords: integration, integrate, react, reactjs, vite, tinymce-react, host
66
:productSource: zip
77
:productUse: host
88

9+
This guide shows how to self-host and lazy-load {productname} from a `.zip` package into a React application.
10+
911
include::partial$integrations/react-quick-start.adoc[]

modules/ROOT/partials/integrations/import-tinymce-statements.adoc

Lines changed: 0 additions & 36 deletions
This file was deleted.

modules/ROOT/partials/integrations/react-quick-start.adoc

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
:packageName: tinymce-react
22

3-
For more live examples of {productname} React component, visit https://tinymce.github.io/tinymce-react/[the tinymce-react storybook].
4-
53
== Prerequisites
64

75
This procedure requires https://nodejs.org/[Node.js (and NPM)].
@@ -85,21 +83,21 @@ npm install -D fs-extra
8583
----
8684
+
8785

88-
. Setup a `postinstall` script to copy {productname} to `public` directory which makes {productname} available as static assets
86+
. Setup a `postinstall` script to copy {productname} to `public` directory, which automatically makes {productname} and other components available as static assets after each installation.
8987
+
90-
.Add `postinstall.js` script with the following:
88+
.Add `postinstall.js` file.
9189
[source,js]
9290
----
9391
import fse from 'fs-extra';
9492
import path from 'path';
93+
9594
const topDir = import.meta.dirname;
9695
fse.emptyDirSync(path.join(topDir, 'public', 'tinymce'));
9796
fse.copySync(path.join(topDir, 'node_modules', 'tinymce'), path.join(topDir, 'public', 'tinymce'), { overwrite: true });
9897
----
99-
+
10098

10199
+
102-
.Update `postinstall` target in `package.json` to run the `postinstall.js` script
100+
.Update `postinstall` target in `package.json` to run the `postinstall.js` script.
103101
[source,json]
104102
----
105103
{
@@ -110,26 +108,23 @@ fse.copySync(path.join(topDir, 'node_modules', 'tinymce'), path.join(topDir, 'pu
110108
}
111109
}
112110
----
113-
+
114111

115-
. Exclude `public/tinymce` from Git tracking
112+
. Exclude `+public/tinymce+` from Git tracking
116113
+
117114
[source,.gitignore]
118115
----
119116
# ... other rules omitted for brevity ...
120117
/public/tinymce/
121118
----
122-
+
123119

124-
. In this instance, run the `postinstall` to copy {productname} to the `public` directory. Note: This script will run automatically after every package installation.
120+
. In this instance, run the `postinstall` to copy {productname} to the `public` directory.
125121
+
126122
[source,sh]
127123
----
128124
npm run postinstall
129125
----
130-
+
131126

132-
. Add `Editor` component to `+./src/App.jsx+` and point `tinymceScriptSrc` the `tinymce` location.
127+
. Add `Editor` component to `+./src/App.jsx+` and point `tinymceScriptSrc` to the `tinymce` location.
133128
+
134129
[source,jsx]
135130
----
@@ -171,15 +166,15 @@ export default function App() {
171166
);
172167
}
173168
----
174-
+
175169

176170
endif::[]
171+
177172
ifeval::["{productUse}" == "bundle"]
178-
. Install the `+tinymce+` and `+@tinymce/tinymce-react+` packages
173+
. Install the `+tinymce+` package.
179174
+
180175
[source,sh]
181176
----
182-
npm install tinymce @tinymce/tinymce-react
177+
npm install tinymce
183178
----
184179
+
185180

@@ -188,7 +183,41 @@ npm install tinymce @tinymce/tinymce-react
188183
[source,jsx]
189184
----
190185
import { Editor } from '@tinymce/tinymce-react';
191-
include::partial$integrations/import-tinymce-statements.adoc[]
186+
// Ensure to import tinymce first as other components expect
187+
// a global variable `tinymce` to exist
188+
import 'tinymce/tinymce';
189+
// DOM model
190+
import 'tinymce/models/dom/model'
191+
// Theme
192+
import 'tinymce/themes/silver';
193+
// Toolbar icons
194+
import 'tinymce/icons/default';
195+
// Editor styles
196+
import 'tinymce/skins/ui/oxide/skin';
197+
// Content styles, including inline UI like fake cursors
198+
import 'tinymce/skins/content/default/content';
199+
import 'tinymce/skins/ui/oxide/content';
200+
201+
// Import plugins
202+
import 'tinymce/plugins/anchor';
203+
import 'tinymce/plugins/advlist';
204+
import 'tinymce/plugins/autolink';
205+
import 'tinymce/plugins/charmap';
206+
import 'tinymce/plugins/code';
207+
import 'tinymce/plugins/media';
208+
import 'tinymce/plugins/visualblocks';
209+
import 'tinymce/plugins/fullscreen';
210+
import 'tinymce/plugins/insertdatetime';
211+
import 'tinymce/plugins/preview';
212+
import 'tinymce/plugins/help';
213+
// Include resources that a plugin lazy-loads at the run-time
214+
import 'tinymce/plugins/help/js/i18n/keynav/en';
215+
import 'tinymce/plugins/image';
216+
import 'tinymce/plugins/link';
217+
import 'tinymce/plugins/lists';
218+
import 'tinymce/plugins/searchreplace';
219+
import 'tinymce/plugins/table';
220+
import 'tinymce/plugins/wordcount';
192221
193222
export default function BundledEditor(props) {
194223
return (
@@ -199,9 +228,8 @@ export default function BundledEditor(props) {
199228
);
200229
}
201230
----
202-
+
203231

204-
. Use `BundleEditor` component in `+./src/App.jsx+` as the following:
232+
. Add `BundledEditor` component into `+./src/App.jsx+` with necessary configurations.
205233
+
206234
[source,jsx]
207235
----
@@ -242,16 +270,16 @@ export default function App() {
242270
);
243271
}
244272
----
245-
+
246273
endif::[]
274+
247275
endif::[]
276+
248277
ifeval::["{productSource}" == "zip"]
249278
ifeval::["{productUse}" == "host"]
250279

251280
. Unzip the content of the `+tinymce/js+` folder from the link:{download-enterprise}[{productname} zip] into the `+public+` folder
252-
+
253281

254-
. Add `+'public/tinymce'+` to the `+ignores+` array to `+./eslint.config.js` file.
282+
. Add `+'public/tinymce'+` to the `+ignores+` array to `+./eslint.config.js+` file.
255283
+
256284
.Diff of `.eslint.config.js`
257285
[source,patch]
@@ -263,7 +291,6 @@ export default tseslint.config(
263291
extends: [js.configs.recommended, ...tseslint.configs.recommended],
264292
files: ['**/*.{ts,tsx}'],
265293
----
266-
+
267294

268295
. Update `+./src/App.jsx+` as below. *Note*: Remember to point `tinymceScriptSrc` the `tinymce` location.
269296
+
@@ -307,9 +334,6 @@ export default function App() {
307334
);
308335
}
309336
----
310-
+
311-
312-
. Update the `+licenseKey+` option in the editor element and include your xref:license-key.adoc[License Key].
313337
endif::[]
314338
ifeval::["{productUse}" == "bundle"]
315339

@@ -319,7 +343,7 @@ ifeval::["{productUse}" == "bundle"]
319343
----
320344
npm install script-loader
321345
----
322-
+
346+
323347
. Unzip the content of the `+tinymce/js+` folder from the link:{download-enterprise}[{productname} zip] into the `+src+` folder.
324348

325349
. Add `+'src/tinymce'+` to the `+ignores+` array to `+./eslint.config.js` file.
@@ -341,14 +365,60 @@ index 092408a..1ab8db4 100644
341365
extends: [js.configs.recommended, ...tseslint.configs.recommended],
342366
files: ['**/*.{ts,tsx}'],
343367
----
368+
369+
. Install `+vite-plugin-commonjs+` and update `vite.config.ts` file to enable support for `+CommonJS+` modules.
344370
+
371+
[source,typescript]
372+
----
373+
import { defineConfig } from 'vite';
374+
import react from '@vitejs/plugin-react';
375+
import commonjs from 'vite-plugin-commonjs';
376+
377+
// https://vite.dev/config/
378+
export default defineConfig({
379+
plugins: [react(), commonjs()],
380+
});
381+
----
345382

346383
. Create `+./src/BundledEditor.jsx+` and set the contents to:
347384
+
348385
[source,jsx]
349386
----
350387
import { Editor } from '@tinymce/tinymce-react';
351-
include::partial$integrations/import-tinymce-statements.adoc[]
388+
// Ensure to import `tinymce` first as other components expect
389+
// a global variable `tinymce` to exist
390+
import './tinymce/tinymce';
391+
// DOM model
392+
import './tinymce/models/dom/model'
393+
// Theme
394+
import './tinymce/themes/silver';
395+
// Toolbar icons
396+
import './tinymce/icons/default';
397+
// Editor styles
398+
import './tinymce/skins/ui/oxide/skin';
399+
// Content styles, including inline UI like fake cursors
400+
import './tinymce/skins/content/default/content';
401+
import './tinymce/skins/ui/oxide/content';
402+
// Import plugins
403+
import './tinymce/plugins/anchor';
404+
import './tinymce/plugins/advlist';
405+
import './tinymce/plugins/autolink';
406+
import './tinymce/plugins/charmap';
407+
import './tinymce/plugins/code';
408+
import './tinymce/plugins/media';
409+
import './tinymce/plugins/visualblocks';
410+
import './tinymce/plugins/fullscreen';
411+
import './tinymce/plugins/insertdatetime';
412+
import './tinymce/plugins/preview';
413+
import './tinymce/plugins/help';
414+
// Include resources that a plugin lazy-loads at the run-time
415+
import './tinymce/plugins/help/js/i18n/keynav/en';
416+
import './tinymce/plugins/image';
417+
import './tinymce/plugins/link';
418+
import './tinymce/plugins/lists';
419+
import './tinymce/plugins/searchreplace';
420+
import './tinymce/plugins/table';
421+
import './tinymce/plugins/wordcount';
352422
353423
export default function BundledEditor(props) {
354424
return (
@@ -359,8 +429,6 @@ export default function BundledEditor(props) {
359429
);
360430
}
361431
----
362-
+
363-
. Update the `+licenseKey+` option to include your xref:license-key.adoc[License Key].
364432

365433
. Add `BundleEditor` component into `+./src/App.jsx+` as the following:
366434
+
@@ -406,27 +474,20 @@ endif::[]
406474
endif::[]
407475

408476
. Test the application.
409-
+
410477
* To start the development server run:
411478
+
412479
[source,sh]
413480
----
414481
npm run dev
415482
----
416483

417-
* To stop the development server, select on the command line or command prompt and press _Ctrl+C_.
418-
419-
420-
== Deploying the application
421-
422-
The application will require further configuration before it can be deployed to a production environment. For information on configuring the application for deployment, see: https://vitejs.dev/guide/build[Building for Production] or https://vitejs.dev/guide/static-deploy.html[Deploying a Static Site].
423-
424-
== Next Steps
484+
== Other resources
425485

426486
ifeval::["{productUse}" == "bundle"]
427487
* For information on bundling, see: xref:introduction-to-bundling-tinymce.adoc[]
428488
endif::[]
429-
* For examples of the {productname} integration, see: https://tinymce.github.io/tinymce-react/[the tinymce-react storybook].
489+
* For examples of the {productname} React integration, see: https://tinymce.github.io/tinymce-react/[the tinymce-react storybook].
490+
* For guides on integrating {productname} premium plugins, see: xref:bundling-plugins.adoc#using-premium-plugins[Using premium plugins].
430491
* For information on customizing:
431492
** {productname} integration, see: xref:react-ref.adoc[].
432493
** {productname}, see: xref:basic-setup.adoc[].

0 commit comments

Comments
 (0)