Skip to content

Commit b33a4c0

Browse files
authored
Add Bard field object to meta data (#20)
* Add Bard field object to meta data * Tweak
1 parent 6ea9e83 commit b33a4c0

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/Mutator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public function __construct($extensions)
3030
$this->extensions = $extensions;
3131

3232
Augmentor::addExtensions([
33-
'bmuRoot' => new Nodes\Root(),
33+
'bmuRoot' => function ($bard) {
34+
return new Nodes\Root(['bard' => $bard->field()]);
35+
},
3436
'bmuHtml' => new Nodes\Html(),
3537
]);
3638
}
@@ -45,16 +47,16 @@ public function injectRoot($value)
4547
return $value;
4648
}
4749

48-
public function processRoot($data)
50+
public function processRoot($data, array $extra)
4951
{
5052
if (in_array($data, $this->roots, true)) {
5153
return;
5254
}
5355

5456
$this->roots[] = $data;
5557

56-
Data::walk($data, function ($data, $meta) {
57-
$this->storeMeta($data, $meta);
58+
Data::walk($data, function ($data, $meta) use ($extra) {
59+
$this->storeMeta($data, array_merge($meta, $extra));
5860
$this->mutateData($data->type, $data);
5961
});
6062
}

src/Nodes/Root.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ class Root extends \Tiptap\Core\Node
88
{
99
public static $name = 'bmuRoot';
1010

11+
public function addOptions()
12+
{
13+
return [
14+
'bard' => null,
15+
];
16+
}
17+
1118
public function renderHTML($node, $HTMLAttributes = [])
1219
{
13-
Mutator::processRoot($node);
20+
Mutator::processRoot($node, [
21+
'bard' => $this->options['bard'],
22+
]);
1423

1524
return null;
1625
}

0 commit comments

Comments
 (0)