Step 1: Organize Files
First, you need to place the necessary files in the public folder.
Directory Structure:
project-root/
├── public/
│ └── assets/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
Step 2: Include Files in index.html
In your React project's public/index.html file, add the following and <script> tags to include the SPK-Editor assets:
<link rel="stylesheet" href="/assets/spk-editor/spk-editor.css">
<script src="/assets/spk-editor/spk-editor.js"></script>
Step 3: SPKEditor Component
Create a new React component for SPKEditor in your project:
import React, { useEffect } from 'react';
// Define interfaces for structured options
interface SpkDropdownType {
name: string;
value: string;
buttonclass: string;
}
interface SpkTextType {
type?: string;
icon: string;
}
interface SpkEditorOptions {
apikey?: string;
exclude?: {
texttype?: string[];
textstyle?: string[];
fontfamily?: boolean;
fontsize?: boolean;
headings?: boolean;
lineheight?: string[];
alignment?: string[];
list?: string[];
link?: boolean;
hr?: boolean;
table?: boolean;
inc_indent?: boolean;
dec_indent?: boolean;
images?: boolean;
videos?: boolean;
reset?: boolean;
undo?: boolean;
redo?: boolean;
fullscreen?: boolean;
copyToClipboard?: boolean;
print?: boolean;
export?: boolean;
pre?: boolean;
};
icons?: {
texttype?: SpkTextType[];
fontfamily?: SpkTextType;
fontsize?: SpkTextType;
headings?: SpkTextType;
lineheight?: SpkTextType;
images?: SpkTextType;
table?: SpkTextType;
inc_indent?: SpkTextType;
dec_indent?: SpkTextType;
link?: SpkTextType;
videos?: SpkTextType;
hr?: SpkTextType;
alignment?: SpkTextType;
list?: SpkTextType[];
undo?: SpkTextType;
redo?: SpkTextType;
reset?: SpkTextType;
fullscreen?: SpkTextType;
copyToClipboard?: SpkTextType;
print?: SpkTextType;
export?: SpkTextType;
pre?: SpkTextType;
};
dropdown?: {
headings?: string[];
lineheight?: SpkDropdownType[];
fontfamily?: SpkDropdownType[];
fontsize?: number[];
alignment?: string[];
list?: string[];
};
placeholderText?: string;
customClass?: string;
dark?: boolean;
rtl?: string;
showwords?: boolean;
showchar?: boolean;
}
// Define default options
const defaultEditorOptions: SpkEditorOptions = {
apikey: 'secret',
placeholderText: 'Enter your text here...',
customClass: 'spk-editor',
dark: false,
rtl: 'ltr',
showwords: true,
showchar: true
};
interface SpkEditorProps {
id: string;
options?: SpkEditorOptions;
}
declare var Spk: any;
const SpkEditor: React.FC<SpkEditorProps> = ({ id, options }) => {
useEffect(() => {
const editorElement = document.querySelector(`#${id}`);
if (editorElement) {
new Spk(editorElement, {
...defaultEditorOptions,
...options,
});
}
}, [id, options]);
return (
<div>
<textarea id={id} className={options?.customClass || defaultEditorOptions.customClass}></textarea>
</div>
);
};
export default SpkEditor;
Step 4: Use the SPKEditor Component
In your React component, import and use SPKEditor like this:
import SpkEditor from 'path_to_SPKEditor';
const MyComponent = () => {
return (
<div>
{/* Basic Usage */}
<SpkEditor id="editor1" />
{/* Custom Options */}
<SpkEditor id="editor2" options={{ apikey: "custom-secret" }} />
</div>
);
};
export default MyComponent;
1. Organize Project Structure
Ensure your project has the following directory structure. This is where you will place the SPK Editor files:
project-root/
├── assets/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
2. Import CSS in _app.js
In your Next.js project, open the pages/_app.js file and import the SPK Editor CSS file:
import '../public/assets/plugins/spk-editor/spk-editor.css';
3. Create the SPK Editor Component
Create a new file for the SPK Editor component (e.g., SpkEditor.tsx). This component will initialize the editor and handle its configuration.
import { useEffect } from 'react';
// Declare the external SPK variable
declare var Spk: any;
// Define interfaces for options
interface SpkDropdownType {
name: string;
value: string;
buttonclass: string;
}
interface SpkTextType {
type?: string;
icon: string;
}
interface SpkEditorOptions {
apikey?: string;
exclude?: {
texttype?: string[];
textstyle?: string[];
fontfamily?: boolean;
fontsize?: boolean;
headings?: boolean;
lineheight?: string[];
alignment?: string[];
list?: string[];
link?: boolean;
hr?: boolean;
table?: boolean;
inc_indent?: boolean;
dec_indent?: boolean;
images?: boolean;
videos?: boolean;
reset?: boolean;
undo?: boolean;
redo?: boolean;
fullscreen?: boolean;
copyToClipboard?: boolean;
print?: boolean;
export?: boolean;
pre?: boolean;
};
icons?: {
texttype?: SpkTextType[];
fontfamily?: SpkTextType;
fontsize?: SpkTextType;
headings?: SpkTextType;
lineheight?: SpkTextType;
images?: SpkTextType;
table?: SpkTextType;
inc_indent?: SpkTextType;
dec_indent?: SpkTextType;
link?: SpkTextType;
videos?: SpkTextType;
hr?: SpkTextType;
alignment?: SpkTextType;
list?: SpkTextType[];
undo?: SpkTextType;
redo?: SpkTextType;
reset?: SpkTextType;
fullscreen?: SpkTextType;
copyToClipboard?: SpkTextType;
print?: SpkTextType;
export?: SpkTextType;
pre?: SpkTextType;
};
dropdown?: {
headings?: string[];
lineheight?: SpkDropdownType[];
fontfamily?: SpkDropdownType[];
fontsize?: number[];
alignment?: string[];
list?: string[];
};
placeholderText?: string;
customClass?: string;
dark?: boolean;
rtl?: string;
showwords?: boolean;
showchar?: boolean;
}
// Define default options for the editor
const defaultEditorOptions: SpkEditorOptions = {
apikey: 'secret',
placeholderText: 'Enter your text here...',
customClass: 'spk-editor',
dark: false,
rtl: 'ltr',
showwords: true,
showchar: true,
};
// Define props for the SPK Editor component
interface SpkEditorProps {
id: string; // 'id' must always be a string
options?: SpkEditorOptions; // 'options' is optional and will fall back to default
}
// Create the SPK Editor component
const SpkEditor: React.FC<SpkEditorProps> = ({ id, options }) => {
useEffect(() => {
// Load the external SPK Editor script when the component mounts
const script = document.createElement('script');
script.src = '/assets/plugins/spk-editor/spk-editor.js';
script.async = true;
document.body.appendChild(script);
script.onload = () => {
// Initialize the editor after the script loads
const editor = new Spk(document.querySelector(`#${id}`), {
...defaultEditorOptions, // Use default options
...options, // Override with passed options
});
};
// Cleanup the script when component unmounts
return () => {
document.body.removeChild(script);
};
}, []);
return (
<textarea id={id} className={options?.customClass || defaultEditorOptions.customClass}></textarea>
);
};
export default SpkEditor;
4. Using the SPK Editor Component
To use the SPK Editor in your Next.js pages or components, import it and provide the necessary props:
import SpkEditor from 'path_to_the_component';
const MyPage = () => {
return (
<div>
<h1>My SPK Editor
<SpkEditor id="spk-editor-one" options={{ placeholderText: 'Hello' }} />
</div>
);
};
export default MyPage;
5. Final Steps
Make sure that the spk-editor.js file is correctly loaded in the browser, and the SPK Editor should initialize without any issues.
You can customize the options prop when using the SpkEditor component to adjust the editor's behavior according to your needs.
Angular Integration of SPK Editor
1. Place the spk-editor Plugin in Assets
You need to place the plugin files (spk-editor.js and spk-editor.css) in your Angular project's assets folder.
Folder Structure:
project-root/
├── src/
│ └── assets/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
2. Add Styles and Scripts in angular.json
You need to register the spk-editor plugin's CSS and JS files in your Angular build configuration by editing the angular.json file.
Steps:
Please, write text here!
Welcome to SPK text editor.
1. Place Files in the Assets Folder
Ensure your project structure includes the npecessary files for the SPK-Editor plugin. Organize your project as follows:
project-root/
└── src/
└── assets/
└── plugins/
└── spk-editor/
├── spk-editor.js
└── spk-editor.css
2. Create the SPK-Editor Component
Add the following code to create the SPK-Editor component:
<template>
<textarea :id="id" :class="computedClass"></textarea>
<script>
export default {
props: {
id: {
type: String,
required: true,
},
options: {
type: Object,
default: () => ({}),
},
},
data() {
return {
defaultEditorOptions: {
apikey: 'secret',
placeholderText: 'Enter your text here...',
customClass: 'spk-editor',
dark: false,
rtl: 'ltr',
showwords: true,
showchar: true,
},
};
},
computed: {
computedClass() {
return this.options.customClass || this.defaultEditorOptions.customClass;
},
},
mounted() {
// Load the external script when the component is mounted
const link = document.createElement('link');
link.href = 'src/assets/plugins/spk-editor/spk-editor.css';
link.rel = 'stylesheet';
document.head.appendChild(link);
const script = document.createElement('script');
script.src = 'src/assets/plugins/spk-editor/spk-editor.js';
script.async = true;
document.body.appendChild(script);
script.onload = () => {
// Initialize the editor after the script loads
this.initializeEditor();
};
},
methods: {
initializeEditor() {
if (typeof Spk !== 'undefined') {
new Spk(document.querySelector(`#${this.id}`), {
...this.defaultEditorOptions,
...this.options,
});
} else {
console.error('Spk is not defined');
}
},
},
beforeUnmount() {
// Cleanup the script when the component is unmounted
const link = document.querySelector(`link[href="src/assets/plugins/spk-editor/spk-editor.css"]`);
const script = document.querySelector(`script[src="src/assets/plugins/spk-editor/spk-editor.js"]`);
if (link) {
document.head.removeChild(link);
}
if (script) {
document.body.removeChild(script);
}
},
};
</script>
<style scoped>
/* Optional: You can add any relevant styling here */
</style>
3. Using the SPK-Editor Component
To use the SPK-Editor component in your Vue application, follow these steps:
Import the Component: Import the SpkEditor component in your desired Vue component file.
import SpkEditor from 'Path_to_the_component'; // Update this path accordingly
Register the Component: Add SpkEditor to your component's components option.
components: {
...
SpkEditor,
},
Add the Component in Your Template: Use the SpkEditor component in your template, passing the required id and optional options.
<SpkEditor id="editor1" :options="{ placeholderText: 'Enter your text here...' }" />
1. Place Files in the Assets Folder
Ensure the required JavaScript and CSS files for the SPK-Editor are in the correct directory structure within your project. The structure should look like this:
project-root/
├── public/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
2. Create the SPK-Editor Component
Create a new component file for the SPK-Editor. Below is the code that should be placed in your component file (e.g., SpkEditor.vue).
<template>
<textarea :id="id" :class="computedClass"></textarea>
</template>
<script>
export default {
props: {
id: {
type: String,
required: true,
},
options: {
type: Object,
default: () => ({}),
},
},
data() {
return {
defaultEditorOptions: {
apikey: 'secret',
placeholderText: 'Enter your text here...',
customClass: 'spk-editor',
dark: false,
rtl: 'ltr',
showwords: true,
showchar: true,
},
};
},
computed: {
computedClass() {
return this.options.customClass || this.defaultEditorOptions.customClass;
},
},
mounted() {
// Load the external script when the component is mounted
const link = document.createElement('link');
link.href = '/plugins/spk-editor/spk-editor.css';
link.rel = 'stylesheet';
document.head.appendChild(link);
const script = document.createElement('script');
script.src = '/plugins/spk-editor/spk-editor.js';
script.async = true;
document.body.appendChild(script);
script.onload = () => {
// Initialize the editor after the script loads
this.initializeEditor();
};
},
methods: {
initializeEditor() {
if (typeof Spk !== 'undefined') {
new Spk(document.querySelector(`#${this.id}`), {
...this.defaultEditorOptions, // Use default options
...this.options, // Override only the passed options
});
} else {
console.error('Spk is not defined');
}
},
},
beforeUnmount() {
// Cleanup the script when the component is unmounted
const link = document.querySelector(`link[href="/plugins/spk-editor/spk-editor.css"]`);
const script = document.querySelector(`script[src="/plugins/spk-editor/spk-editor.js"]`);
if (link) {
document.head.removeChild(link);
}
if (script) {
document.body.removeChild(script);
}
},
};
</script>
<style scoped>
/* Optional: You can add any relevant styling here */
</style>
3. Usage of the SPK-Editor Component
To use the SPK-Editor component in your application, you need to import it into the desired page or component. Here’s how to do that:
Import the Component: Replace Path_to_the_component with the actual path to your SpkEditor.vue file.
import SpkEditor from 'Path_to_the_component';
//Register the Component: Add SpkEditor to the components section of your Vue component.
components: {
// other components
SpkEditor,
},
Use the Component in the Template: Use the <SpkEditor> component with the required props in your template.
<template>
<div>
<SpkEditor id="editor1" :options="{ placeholderText: 'placeholderText' }" />
</div>
</template>
4. Complete Example
Here's how everything fits together in a typical component structure:
<template>
<div>
<SpkEditor id="editor1" :options="{ placeholderText: 'placeholderText' }" />
</div>
</template>
<script>
import SpkEditor from 'Path_to_the_component';
export default {
components: {
SpkEditor,
},
};
1. Project Structure Overview:
project-root/
├── static/
│ └── assets/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
spk-editor.js and spk-editor.css: These files are located in the static/assets/plugins/spk-editor/ directory. They contain the JavaScript and CSS for the editor plugin.
2. Django Template Setup:
In your Django template (e.g., editor_template.html), you will load the necessary static files for the editor plugin and configure the editor initialization. Here's the step-by-step breakdown:
Step 1: Load Static Files
At the top of your template, you need to load the Django static template tag.
{% load static %}
Step 2: Link the Editor's CSS
In the {% block styles %}, include the editor's CSS file.
{% block styles %}
<link rel="stylesheet" href="{% static 'assets/plugins/spk-editor/spk-editor.css' %}">
{% endblock %}
Step 3: Create the Editor Area
In the {% block content %}, add the textarea element with the class that will be used to initialize the editor.
{% block content %}
<textarea class="spk-editor-one"></textarea>
{% endblock %}
Step 4: Include the JavaScript for the Editor
In the {% block scripts %}, load the editor’s JavaScript file and initialize it using a script that runs once the DOM is ready.
{% block scripts %}
<script src="{% static 'assets/plugins/spk-editor/spk-editor.js' %}"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
let editor2 = new Spk(document.querySelector('.spk-editor-one'), {
placeholderText: " Hi,
Welcome to SPK text editor.
please, write text here!
super simple Editor",
});
});
</script>
{% endblock %}
1. Project Structure
Ensure your project directory is structured as follows:
project-root/
├── webroot/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
Step 1: Create an Initialization Script
Create a JavaScript File
Create a file named editor-init.js in the wwwroot folder.
// wwwroot/editor-init.js
window.initializeEditor = function(id, options) {
let editor2 = new Spk(document.querySelector(id), {
...options
});
};
Step 2: Include JS and CSS Files in Your View
In your CakePHP view file, include the necessary JavaScript and CSS files for the SPK Editor:
// In your view file
<?= $this->Html->css('/plugins/spk-editor/spk-editor.css') ?>
<?= $this->Html->script('/plugins/spk-editor/spk-editor.js') ?>
Step 3: Add Textarea to Your Component
In the same view file, add a textarea element that will be transformed into the SPK Editor:
<textarea id="editor" class="spk-editor-one"></textarea>
Step 4: Initialize the Plugin
To initialize the editor, add the following script to your view. This should be placed within the script block to ensure it runs after the DOM content has loaded:
<?php $this->start('script'); ?>
<script>
document.addEventListener("DOMContentLoaded", function() {
let editor2 = new Spk(document.querySelector('.spk-editor-one'), {
placeholderText: "<div class='check'> Hi, <blockquote><br> Welcome to SPK text editor.<br></blockquote> please, write text here!<br> super simple Editor</div>",
});
});
</script>
<?php $this->end(); ?>
1. Project Structure
Your project should have the following structure, particularly under the public directory for the SPK Editor assets:
project-root/
├── resources/
│ └── assets/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
Note: Ensure you run the build command npm run build. This will generate the assets in public/build, which you can then utilize within the project.
2. Include Styles in Blade Template
In your Blade template, you need to include the CSS file for the SPK Editor. This can be done in the @section('styles') section of your Blade file:
@section('styles')
<link rel="stylesheet" href="{{ asset('build/assets/plugins/spk-editor/spk-editor.css') }}">
@endsection
3. Create the Textarea for the Editor
Add the textarea element in your Blade template where you want the SPK Editor to be initialized:
<textarea class="spk-editor-one"></textarea>
4. Include Scripts in Blade Template
Next, you need to include the JavaScript file for the SPK Editor in the @section('scripts') section. Additionally, initialize the editor using a script:
@section('scripts')
<script src="{{ asset('build/assets/plugins/spk-editor/spk-editor.js') }}"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
let editor2 = new Spk(document.querySelector('.spk-editor-one'), {
apikey: 'secret',
placeholderText: " Hi,
Welcome to SPK text editor.
please, write text here!
super simple Editor",
});
});
</script>
@endsection
5. Resulting Blade File Example
Here's how your complete Blade file might look after integrating the SPK Editor:
@extends('layouts.app')
@section('styles')
<link rel="stylesheet" href="{{ asset('build/assets/plugins/spk-editor/spk-editor.css') }}">
@endsection
@section('content')
<textarea class="spk-editor-one"></textarea>
@endsection
@section('scripts')
<script src="{{ asset('build/assets/plugins/spk-editor/spk-editor.js') }}"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
let editor2 = new Spk(document.querySelector('.spk-editor-one'), {
apikey: 'secret',
placeholderText: "<div class='check'> Hi, <blockquote><br> Welcome to SPK text editor.<br></blockquote> please, write text here!<br> super simple Editor</div>",
});
});
</script>
@endsection
Project Structure
Your project should have the following structure to properly integrate the SPK Editor:
project-root/
├── wwwroot/
│ └── assets/
│ └── plugins/
│ └── spk-editor/
│ ├── spk-editor.js
│ └── spk-editor.css
│ └── js/
│ └── editor-init.js
1. Create JavaScript Initialization File
Create the editor-init.js file inside the wwwroot/js/ directory.
Add the following code to initialize the SPK Editor:
// editor-init.js
window.initializeEditor = function(id, options) {
let editor2 = new Spk(document.querySelector(id), {
...options
});
};
2. Include JS and CSS Files
For Server-Side Blazor:
Open the _Host.cshtml file located in the Pages directory.
Add the following lines within the
section to include the CSS and JavaScript files:
<link rel="stylesheet" href="assets/plugins/spk-editor/spk-editor.css" />
<script src="assets/plugins/spk-editor/spk-editor.js"></script>
<script src="js/editor-init.js"></script>
For Blazor WebAssembly:
Open the index.html file located in the wwwroot directory.
Add the same lines as above within the <head> section.
3. Add Textarea in Blazor Component
In your Blazor component file (e.g., MyComponent.razor), add the following <textarea> element:
<textarea id="editor" class="spk-editor-one"></textarea>
4. Initialize the Editor
In the same Blazor component, inject the IJSRuntime service at the top:
@inject IJSRuntime JSRuntime
Override the OnAfterRenderAsync method to initialize the editor when the component is rendered for the first time:
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var editorOptions = new
{
apikey = "secret",
PlaceholderText = "Enter your text here...",
CustomClass = "spk-editor",
Dark = true,
Rtl = "ltr",
showwords = true,
showchar = true
};
// Call the JavaScript function to initialize the editor
await JSRuntime.InvokeVoidAsync("initializeEditor", ".spk-editor-one", editorOptions);
}
}
}
Provides RTL (Right-to-Left) language support, making it ideal for international use.
Designed to be easily customizable, allowing you to tailor it to your specific requirements.
Comes with comprehensive documentation, making it easy to understand and implement.
Fully responsive, ensuring it looks great on any device.
Supports seamless integration of images for a richer user experience.
Includes video support, allowing you to embed and play videos effortlessly.
Offers dark mode support, enhancing accessibility and user comfort.
Built with pure JavaScript, so there's no need for jQuery.
Supports integration across multiple frameworks for seamless functionality.
code tag allows you to easily format and display code snippets with proper syntax highlighting, ensuring that your code stands out and remains readable. The editor is initialized using the Spk constructor, linking it to the HTML element via new Spk(), establishing a robust foundation for all editing features while offering flexible options for single or multiple editing views in this text editor.
Ensure the security of your API keys with our advanced protection view in the WYSIWYG text editor, allowing you to manage and safeguard sensitive information seamlessly.
Enhance your editing experience with our WYSIWYG text editor's tollbar configuration settings protection, ensuring a secure and customizable interface that safeguards your preferences while you create.
Experience seamless content creation with our WYSIWYG text editor's advanced Editor Methods and Event Handling protection view, ensuring your editing process is secure, intuitive, and free from interruptions.
Enjoy a refined and clean user interface with SPKEditor that blends seamlessly into any project. The elegant design ensures that your content looks polished and professional, making it perfect for visually appealing websites.
SPKEditor adapts to any content creation scenario, from simple text editing to complex data manipulation. Its modular architecture makes it suitable for a diverse range of applications, from blogs to enterprise-level systems.
Enhance your content with images, videos, and other media elements using SPKEditor’s intuitive media manager. adjust settings, and preview changes in real time without leaving the editor interface.
Leverage smart formatting options like automatic bullet points, smart indenting, and markdown support. SPKEditor intelligently formats content as you type, saving you time and reducing the need for manual adjustments.