Skip to content

Commit

Permalink
Merge pull request #18 from lmottasin/checklist
Browse files Browse the repository at this point in the history
[2.x] Add checklist render option
  • Loading branch information
alaminfirdows authored Oct 2, 2024
2 parents c9ab70e + 5fd6199 commit 97a423c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
17 changes: 17 additions & 0 deletions config/laravel_editorjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@
'allowedTags' => '*',
],
],
'checklist' => [
'items' => [
'type' => 'array',
'data' => [
'-' => [
'type' => 'array',
'data' => [
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
'checked' => 'boolean',
],
],
],
],
],
// 'attaches' => [
// 'file' => [
// 'type' => 'array',
Expand Down
9 changes: 9 additions & 0 deletions resources/views/blocks/checklist.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul>
@foreach($data['items'] as $item)
<li>
<input type="checkbox" {{ $item['checked'] ? 'checked' : '' }} disabled>
<span>{!! $item['text'] !!}</span>
</li>
@endforeach
</ul>

53 changes: 53 additions & 0 deletions tests/Feature/Blocks/ChecklistTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace AlAminFirdows\LaravelEditorJs\Tests\Feature\Blocks;

use AlAminFirdows\LaravelEditorJs\Tests\TestCase;

class ChecklistTest extends TestCase
{
protected function getBlockData()
{
return [
"type" => "checklist",
"data" => [
"items" => [
[
"text" => "<a href=\"https://githuh.com/lmottasin\">LINK</a>",
"checked" => true
],
[
"text" => "<b>BOLD</b>",
"checked" => false
],
[
"text" => "<i>ITALIC</i>",
"checked" => false
],
[
"text" => "PLAIN TEXT",
"checked" => false
]
]
]
];

}

protected function getBlockHtml()
{
return '<ul> <li> <input type="checkbox" checked disabled> <span><a href="https://githuh.com/lmottasin" target="_blank" rel="noreferrer noopener">LINK</a></span> </li> <li> <input type="checkbox" disabled> <span><b>BOLD</b></span> </li> <li> <input type="checkbox" disabled> <span><i>ITALIC</i></span> </li> <li> <input type="checkbox" disabled> <span>PLAIN TEXT</span> </li> </ul>';
}

/** @test */
public function render_checklist_block_test(): void
{
//This replaces any sequence of whitespace (including tabs and newlines) with a single space,
// normalizing the formatting in both the expected and actual HTML strings.

$expectedHtml = preg_replace('/\s+/', ' ', $this->getBlockHtml());
$actualHtml = preg_replace('/\s+/', ' ', $this->renderBlocks($this->getEditorData([$this->getBlockData()])));

$this->assertEquals($expectedHtml, $actualHtml);
}
}

0 comments on commit 97a423c

Please sign in to comment.