awcodes / scribble

MIT License
43 stars 7 forks source link

[Bug]: Faker utilities generate extra content key #58

Closed agentphoenix closed 3 weeks ago

agentphoenix commented 3 months ago

What happened?

When using the Faker utilities to generate a block, there is an extra content key with the JSON values that duplicates all of the data as a JSON string.

How to reproduce the bug

Faker::make()->block(values: ['foo' => 'bar'])->asJson()

This will produce the following content:

[
  "type" => "doc"
  "content" => [
    0 => [
      "type" => "scribbleBlock"
      "attrs" => [
        "type" => "scribbleBlock"
        "identifier" => "scribble-block"
        "values" => [
          "foo" => "bar"
        ]
      ]
      "content" => [
        0 => [
          "type" => "text"
          "text" => "{"type":"scribbleBlock","identifier":"scribble-block","values":{"foo":"bar"}}"
        ]
      ]
    ]
  ]
]

My expectation is that the extra content key isn't there since it isn't present when using the package in the web app.

Package Version

0.3.11-alpha

PHP Version

8.3.8

Laravel Version

10.48.14

Which operating systems does with happen with?

macOS

Notes

No response

awcodes commented 3 months ago

The content is necessary to convert between html and json. It's not implemented yet, but would be necessary for allowing for Source Code editing.

agentphoenix commented 3 months ago

@awcodes so are the custom blocks supposed to be adding that content array as well when editing directly through the editor?

awcodes commented 3 months ago

Would have to double check, but it's most likely coming from the conversion from html to json since the faker doesn't create json directly. It has to be parsed. And using the content as a json string for the blocks data is safer than trying to store them as attributes on the html element, due to escaping.