Skip to content

Commit bee18df

Browse files
committed
More fixes for prosemirror integration
1 parent e7e2860 commit bee18df

File tree

2 files changed

+64
-28
lines changed

2 files changed

+64
-28
lines changed

GalleryNode.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use dokuwiki\plugin\prosemirror\parser\Node;
66

7+
/**
8+
* Gallery Node in Prosemirror editor
9+
*/
710
class GalleryNode extends Node
811
{
912
protected $parent;
@@ -30,12 +33,9 @@ public function __construct($data, Node $parent)
3033
*/
3134
public function toSyntax()
3235
{
33-
/** @var syntax_plugin_gallery $syntax */
34-
$syntax = plugin_load('syntax', 'gallery');
35-
$defaults = $syntax->getDataFromParams($syntax->getConf('options'));
36-
/** @var action_plugin_gallery_prosemirror $action */
36+
/** @var \action_plugin_gallery_prosemirror $action */
3737
$action = plugin_load('action', 'gallery_prosemirror');
38-
$defaults = $action->cleanAttributes($defaults);
38+
$defaults = $action->getDefaults();
3939
$query = [];
4040
$attrs = $this->data['attrs'];
4141
if ($attrs['thumbnailsize'] !== $defaults['thumbnailsize']) {

action/prosemirror.php

+59-23
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,7 @@ public function writeDefaultsToJSINFO(Event $event, $param)
4343
{
4444
global $JSINFO;
4545

46-
$options = new Options();
47-
$defaults = [
48-
'thumbnailsize' => $options->thumbnailWidth . 'x' . $options->thumbnailHeight,
49-
'imagesize' => $options->lightboxWidth . 'X' . $options->lightboxHeight,
50-
'cache' => $options->cache,
51-
'filter' => $options->filter,
52-
'showname' => $options->showname,
53-
'showtitle' => $options->showtitle,
54-
'crop' => $options->crop,
55-
'direct' => $options->direct,
56-
'reverse' => $options->reverse,
57-
'recursive' => $options->recursive,
58-
'align' => $options->align,
59-
'cols' => $options->columns,
60-
'limit' => $options->limit,
61-
'offset' => $options->offset,
62-
'paginate' => $options->paginate,
63-
'sort' => $options->sort,
64-
];
46+
$defaults = $this->getDefaults();
6547

6648
if (!isset($JSINFO['plugins'])) {
6749
$JSINFO['plugins'] = [];
@@ -88,22 +70,24 @@ public function writeDefaultsToJSINFO(Event $event, $param)
8870
*/
8971
public function renderFromInstructions(Event $event, $param)
9072
{
91-
if ($event->data['name'] !== 'gallery') {
73+
if ($event->data['name'] !== 'gallery_main') {
9274
return;
9375
}
9476
$event->preventDefault();
9577
$event->stopPropagation();
9678

9779
$node = new Node('dwplugin_gallery');
98-
// FIXME we may have to parse the namespace from the original syntax ?
9980
$data = $event->data['data'];
100-
$ns = $data['ns'];
81+
// FIXME source can be something other than namespace
82+
[$ns, $options] = $data;
10183

10284
if (cleanID($ns) === $ns) {
10385
$ns = ':' . $ns;
10486
}
10587
$node->attr('namespace', $ns);
106-
foreach ($data as $name => $value) {
88+
89+
$attrs = $this->optionsToAttrs($options);
90+
foreach ($attrs as $name => $value) {
10791
$node->attr($name, $value);
10892
}
10993
$event->data['renderer']->nodestack->add($node);
@@ -156,4 +140,56 @@ public function renderAttributesToHTML(Event $event, $param)
156140
$html = p_render('xhtml', p_get_instructions($syntax), $info);
157141
echo $html;
158142
}
143+
144+
/**
145+
* Get default node attributes from gallery Options object
146+
*
147+
* @return array
148+
*/
149+
public function getDefaults(): array
150+
{
151+
$options = new Options();
152+
153+
return [
154+
'thumbnailsize' => $options->thumbnailWidth . 'x' . $options->thumbnailHeight,
155+
'imagesize' => $options->lightboxWidth . 'X' . $options->lightboxHeight,
156+
'cache' => $options->cache,
157+
'filter' => $options->filter,
158+
'showname' => $options->showname,
159+
'showtitle' => $options->showtitle,
160+
'crop' => $options->crop,
161+
'direct' => $options->direct,
162+
'reverse' => $options->reverse,
163+
'recursive' => $options->recursive,
164+
'align' => $options->align,
165+
'cols' => $options->columns,
166+
'limit' => $options->limit,
167+
'offset' => $options->offset,
168+
'paginate' => $options->paginate,
169+
'sort' => $options->sort,
170+
];
171+
}
172+
173+
/**
174+
* Convert gallery options to node attributes
175+
*
176+
* @param Options $options
177+
* @return array
178+
*/
179+
protected function optionsToAttrs($options)
180+
{
181+
$attrs = (array)$options;
182+
183+
$attrs['thumbnailsize'] = $options->thumbnailWidth . 'x' . $options->thumbnailHeight;
184+
$attrs['imagesize'] = $options->lightboxWidth . 'X' . $options->lightboxHeight;
185+
$attrs['cols'] = $options->columns;
186+
187+
unset($attrs['thumbnailWidth']);
188+
unset($attrs['thumbnailHeight']);
189+
unset($attrs['lightboxWidth']);
190+
unset($attrs['lightboxHeight']);
191+
unset($attrs['columns']);
192+
193+
return $attrs;
194+
}
159195
}

0 commit comments

Comments
 (0)