1. Go to this page and download the library: Download vipertecpro/wysiwyg-editor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Native\Mobile\Attributes\On;
use Native\Mobile\Edge\NativeComponent;
use Vipertecpro\WysiwygEditor\Events\ContentSaved;
use Vipertecpro\WysiwygEditor\Events\EditCancelled;
use Vipertecpro\WysiwygEditor\Facades\WysiwygEditor;
class EditNote extends NativeComponent
{
public string $body = '';
public function edit(): void
{
WysiwygEditor::open($this->body, [
'title' => 'Edit note',
'placeholder' => 'Write something…',
]);
}
#[On(ContentSaved::class)]
public function onSaved(string $html, string $text): void
{
$this->body = $html; // clean, normalised HTML
}
#[On(EditCancelled::class)]
public function onCancelled(): void
{
// user backed out — content unchanged
}
}
WysiwygEditor::open($html); // full — everything
WysiwygEditor::open($html, ['preset' => 'basic']); // bold italic underline strike lists link
WysiwygEditor::open($html, ['preset' => 'comment', 'maxLength' => 500]); // bold italic link
WysiwygEditor::open($html, ['preset' => 'note']); // bold italic underline h1 h2 lists checklist
WysiwygEditor::open($html, ['toolbar' => ['bold', 'link']]); // exactly these, in this order
WysiwygEditor::open($html, [
'theme' => [
'background' => '#121417',
'text' => '#FFFFFF',
'accent' => '#F97316', // Save button
'highlight' => '#22C55E', // toggled toolbar buttons / active states
],
]);
#[On(ContentSaved::class)]
public function onSaved(string $html, string $text, string $json): void
{
$post = Http::withToken($token)
->post('https://api.example.com/posts', [
'html' => $html, // to render
'text' => $text, // to search
'json' => $json, // to re-open for editing
])->json();
foreach (WysiwygEditor::attachments($json) as $file) {
if ($file['path'] === '') {
continue; // already on your server; $file['url'] says where
}
Http::withToken($token)
->attach('file', file_get_contents($file['path']), basename($file['path']))
->post("https://api.example.com/posts/{$post['id']}/media", [
'kind' => $file['kind'], // image | video | file
'alt' => $file['alt'],
'caption' => $file['caption'],
'uploadId' => $file['uploadId'],
]);
}
}
WysiwygEditor::open($note->body, ['changeDebounce' => 1500]);
#[On(ContentChanged::class)]
public function onChanged(string $html, string $json): void
{
$this->note->update(['body_html' => $html, 'body_json' => $json]);
}
#[On(MediaRequested::class)]
public function onMediaRequested(string $kind): void
{
Camera::pickImages('images', false); // or your own picker
}
#[On(MediaSelected::class)]
public function onMediaSelected(bool $success, array $files, int $count): void
{
ImageCropper::open($files[0]['path'], ['preset' => 'landscape']);
}
#[On(ImageCropped::class)]
public function onImageCropped(string $path): void
{
WysiwygEditor::insertMedia('image', [
'localPath' => $path,
'uploadId' => $id = uniqid('up-'),
]);
// Upload with your own stack (or nativephp/mobile-background-tasks),
// then tell the editor how it went:
WysiwygEditor::uploadProgress($id, 0.5);
WysiwygEditor::uploadCompleted($id, $cdnUrl);
WysiwygEditor::uploadFailed($id, 'Network unavailable');
}
WysiwygEditor::preview('image', $post->photo); // or 'video'
WysiwygEditor::open($html, [
'toolbar' => ['image', 'camera', 'video', 'poll'],
'customTools' => [
['id' => 'gif', 'icon' => 'embed', 'label' => 'GIF'],
['id' => 'schedule', 'icon' => 'orderedList', 'label' => 'Schedule'],
],
'avatar' => $user->avatarUrl,
]);
#[On(ToolTapped::class)]
public function onToolTapped(string $tool): void
{
// Your picker, your sheet, your data.
}
WysiwygEditor::open($html, [
'accessories' => [
['id' => 'tag', 'label' => 'Tag people', 'icon' => 'image'],
['id' => 'audience', 'label' => 'Everyone can reply', 'value' => 'Everyone'],
],
]);
#[On(AccessoryTapped::class)]
public function onAccessoryTapped(string $accessory): void
{
// Your picker, your data. The editor stays open throughout.
WysiwygEditor::setAccessory('audience', 'Everyone can reply', 'People you follow');
}
use Vipertecpro\WysiwygEditor\Events\SuggestionRequested;
WysiwygEditor::open($html, [
'triggers' => ['@' => 'mention', '#' => 'hashtag'], // the default
]);
#[On(SuggestionRequested::class)]
public function onSuggestionRequested(string $kind, string $trigger, string $query = ''): void
{
// Fires on every keystroke, so debounce or cap it before hitting an API.
$matches = User::query()
->whereLike('name', "%{$query}%")
->limit(5)
->get()
->map(fn (User $u) => [
'id' => (string) $u->id, //
#[On(ToolTapped::class)]
public function onToolTapped(string $tool): void
{
if ($tool === 'date') {
WysiwygEditor::insertText(now()->format('j F Y'));
}
}
use Native\Mobile\Testing\Native;
it('opens the editor when a new page is started', function () {
$bridge = Native::fakeBridge();
Native::test(Pages::class)->call('newPage');
$bridge->assertEditorOpened();
});
it('answers a slash command with the matching rows', function () {
$bridge = Native::fakeBridge();
Native::test(Pages::class)->call('onSuggestionRequested', 'command', 'to-do');
$bridge->assertSuggestionsOffered(['To-do list']);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.