Svelte integration
TinyMCE Svelte integration quick start guide
The Official TinyMCE Svelte component integrates TinyMCE into Svelte applications.
This procedure creates a basic Svelte application using the sveltejs/template project adds a TinyMCE editor based using the TinyMCE Svelte integration.
For examples of the TinyMCE integration, visit the tinymce-svelte storybook.
Procedure
-
Create a Svelte application using the Svelte template project, for example:
npx degit sveltejs/template my-tiny-app cd my-tiny-app -
Install the
tinymce-svelteeditor component, such as:npm install @tinymce/tinymce-svelte -
Open
src/App.svelteand add:-
An
importstatement for the TinyMCE component. -
The
<Editor />as a placeholder for the editor.For example:
File:
src/App.svelte<script lang="ts"> import Editor from '@tinymce/tinymce-svelte'; </script> <main> <h1>Hello Tiny</h1> <Editor></Editor> </main>
-
-
Test the application using the Node.js development server.
-
To start the development server, in the project’s root directory, run:
npm run devThis will start a local development server, accessible at http://localhost:5000.
-
To stop the development server, select on the command line or command prompt and press Ctrl+C.
-
Next Steps
-
For examples of the TinyMCE integration, see: the tinymce-svelte storybook.
-
For information on customizing, see:
TinyMCE Svelte integration technical reference
Covered in this section:
Configuring the TinyMCE Svelte integration
The tinymce-svelte Editor component accepts the following properties:
<Editor
apiKey="api-key"
channel="5"
id="uuid"
inline=false
disabled=false
scriptSrc=undefined
conf={}
modelEvents="input change undo redo"
value="value"
text="readonly-text-output"
/>
apiKey
Tiny Cloud API key. Required for deployments using the Tiny Cloud to provide the TinyMCE editor.
- Default value
-
"no-api-key" - Type
-
String
channel
Specifies the Tiny Cloud channel to use. For information on Tiny Cloud deployment channels, see: Specifying the TinyMCE editor version deployed from Cloud.
- Default value
-
"5" - Type
-
String
id
Specified an Id for the editor. Used for retrieving the editor instance using the tinymce.get('ID') method.
- Default value
-
Automatically generated UUID
- Type
-
String
Component binding
Input binding
The editor component allows developers to bind the contents of editor to a variable. By specifying the bind:value, developers can create a two-way binding on a selected variable.
Example of input binding
<script>
let value = 'some content';
</script>
<main>
<Editor bind:value={value} />
<div>{@html value}</div>
<textarea bind:value={value}></textarea>
</main>
Event binding
Functions can be bound to editor events, such as:
<Editor on:resizeeditor={this.handlerFunction} />
When the handler is called (handlerFunction in this example), it is called with two arguments:
event-
The TinyMCE event object.
editor-
A reference to the editor.
Ensure event names are specified in lower-case (event names are case-sensitive).
The following events are available:
-
activate -
addundo -
beforeaddundo -
beforeexeccommand -
beforegetcontent -
beforerenderui -
beforesetcontent -
beforepaste -
blur -
change -
clearundos -
click -
contextmenu -
copy -
cut -
dblclick -
deactivate -
dirty -
drag -
dragdrop -
dragend -
draggesture -
dragover -
drop -
execcommand -
focus -
focusin -
focusout -
getcontent -
hide -
init -
keydown -
keypress -
keyup -
loadcontent -
mousedown -
mouseenter -
mouseleave -
mousemove -
mouseout -
mouseover -
mouseup -
nodechange -
objectresizestart -
objectresized -
objectselected -
paste -
postprocess -
postrender -
preprocess -
progressstate -
redo -
remove -
reset -
resizeeditor -
savecontent -
selectionchange -
setattrib -
setcontent -
show -
submit -
undo -
visualaid