PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.2.0
Tableberg – Simple Gutenberg Table Block v1.2.0
1.2.0 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 All 43 releases
← All changes | renderer/Table/TableAttrs.php +111 -60 1.1.2 → 1.2.0 View file →
@@ -107,24 +107,8 @@
107 107
108 108 return ['cells' => []];
109 109 }
110 110
111 - /** @return array<int, array{array{int, int}, array<int, mixed>}> */
112 - public static function get_data_defaults() {
113 - $defaults = Defaults::get_defaults();
114 -
115 - if (
116 - isset($defaults['data']) &&
117 - is_array($defaults['data']) &&
118 - isset($defaults['data']['cells']) &&
119 - is_array($defaults['data']['cells'])
120 - ) {
121 - return $defaults['data']['cells'];
122 - }
123 -
124 - return [];
125 - }
126 -
127 111 /** @return array<int, RowConfig> */
128 112 private static function parse_row_configs($data) {
129 113 if (!is_array($data)) {
130 114 return [];
@@ -192,52 +176,8 @@
192 176 return $bindings;
193 177 }
194 178 }
195 179
196 -class Data {
197 - /** @var array<int, array{array{int, int}, array<int, CellElement>}> */
198 - public $cells;
199 -
200 - /** @return self */
201 - public static function from_array($data) {
202 - $data = is_array($data) ? $data : [];
203 - $default_cells = TableAttrs::get_data_defaults();
204 -
205 - $instance = new self();
206 - $instance->cells = self::parse_cells(getOrNull($data['cells']), $default_cells);
207 -
208 - return $instance;
209 - }
210 -
211 - /** @return array<int, array{array{int, int}, array<int, CellElement>}> */
212 - private static function parse_cells($data, $default) {
213 - if (!is_array($data)) {
214 - return $default;
215 - }
216 -
217 - $cells = [];
218 -
219 - foreach ($data as $cell) {
220 - if (!is_array($cell[0])) {
221 - continue;
222 - }
223 -
224 - $coords = [(int) $cell[0][0], (int) $cell[0][1]];
225 - $elements = [];
226 -
227 - if (is_array($cell[1])) {
228 - foreach ($cell[1] as $element) {
229 - $elements[] = CellElement::from_array($element);
230 - }
231 - }
232 -
233 - $cells[] = [$coords, $elements];
234 - }
235 -
236 - return $cells;
237 - }
238 -}
239 -
240 180 class PaginationConfig {
241 181 /** @var BoolAttr */
242 182 public $enabled;
243 183
@@ -487,8 +427,11 @@
487 427
488 428 /** @var Sides */
489 429 public $tableBorder;
490 430
431 + /** @var TypographyConfig */
432 + public $typography;
433 +
491 434 /** @var Sides */
492 435 public $margin;
493 436
494 437 /** @var Sides */
@@ -528,8 +471,11 @@
528 471 $instance->tableBorder = Sides::from_array(
529 472 getOrNull($data['tableBorder']),
530 473 $d['tableBorder']
531 474 );
475 + $instance->typography = TypographyConfig::from_array(
476 + getOrNull($data['typography'])
477 + );
532 478 $emptySides = ['top' => '', 'right' => '', 'bottom' => '', 'left' => ''];
533 479 $instance->margin = Sides::from_array(
534 480 getOrNull($data['margin']),
535 481 isset($d['margin']) && is_array($d['margin']) ? $d['margin'] : $emptySides
@@ -548,8 +494,97 @@
548 494 return $instance;
549 495 }
550 496 }
551 497
498 +/**
499 + * Table-wide typography: the same options the core Table block offers, set on
500 + * the table element so the cells inherit them.
501 + */
502 +class TypographyConfig {
503 + /** @var StringAttr */
504 + public $fontFamily;
505 +
506 + /** @var StringAttr */
507 + public $fontSize;
508 +
509 + /** @var StringAttr */
510 + public $fontStyle;
511 +
512 + /** @var StringAttr */
513 + public $fontWeight;
514 +
515 + /** @var StringAttr */
516 + public $lineHeight;
517 +
518 + /** @var StringAttr */
519 + public $letterSpacing;
520 +
521 + /** @var StringAttr */
522 + public $textDecoration;
523 +
524 + /** @var StringAttr */
525 + public $textTransform;
526 +
527 + /** @return self */
528 + public static function from_array($data) {
529 + $data = is_array($data) ? $data : [];
530 + $tableDefaults = TableAttrs::get_table_defaults();
531 + $d = isset($tableDefaults['typography']) && is_array($tableDefaults['typography'])
532 + ? $tableDefaults['typography']
533 + : [];
534 +
535 + $instance = new self();
536 + foreach (
537 + [
538 + 'fontFamily',
539 + 'fontSize',
540 + 'fontStyle',
541 + 'fontWeight',
542 + 'lineHeight',
543 + 'letterSpacing',
544 + 'textDecoration',
545 + 'textTransform',
546 + ] as $property
547 + ) {
548 + $instance->{$property} = new StringAttr(
549 + getOrNull($data[$property]),
550 + isset($d[$property]) ? $d[$property] : ''
551 + );
552 + }
553 +
554 + return $instance;
555 + }
556 +
557 + /**
558 + * The typography as `property: value` declarations, skipping everything
559 + * the user has not set so the theme keeps deciding.
560 + *
561 + * @return array<int, string>
562 + */
563 + public function asStyles() {
564 + $properties = [
565 + 'font-family' => $this->fontFamily,
566 + 'font-size' => $this->fontSize,
567 + 'font-style' => $this->fontStyle,
568 + 'font-weight' => $this->fontWeight,
569 + 'line-height' => $this->lineHeight,
570 + 'letter-spacing' => $this->letterSpacing,
571 + 'text-decoration' => $this->textDecoration,
572 + 'text-transform' => $this->textTransform,
573 + ];
574 +
575 + $styles = [];
576 +
577 + foreach ($properties as $property => $attr) {
578 + if ($attr->isNotEmpty()) {
579 + $styles[] = $property . ': ' . $attr->asAttr();
580 + }
581 + }
582 +
583 + return $styles;
584 + }
585 +}
586 +
552 587 class CellStyles {
553 588 /** @var Sides */
554 589 public $padding;
555 590
@@ -561,8 +596,20 @@
561 596
562 597 /** @var StringAttr */
563 598 public $backgroundColor;
564 599
600 + /** @var StringAttr */
601 + public $headerBackgroundColor;
602 +
603 + /** @var StringAttr */
604 + public $footerBackgroundColor;
605 +
606 + /** @var StringAttr */
607 + public $evenRowBackgroundColor;
608 +
609 + /** @var StringAttr */
610 + public $oddRowBackgroundColor;
611 +
565 612 /** @var Sides */
566 613 public $border;
567 614
568 615 /** @var Corners */
@@ -587,8 +634,12 @@
587 634 $d['verticalAlign'],
588 635 ['top', 'middle', 'bottom']
589 636 );
590 637 $instance->backgroundColor = new StringAttr(getOrNull($data['backgroundColor']), $d['backgroundColor']);
638 + $instance->headerBackgroundColor = new StringAttr(getOrNull($data['headerBackgroundColor']), $d['headerBackgroundColor']);
639 + $instance->footerBackgroundColor = new StringAttr(getOrNull($data['footerBackgroundColor']), $d['footerBackgroundColor']);
640 + $instance->evenRowBackgroundColor = new StringAttr(getOrNull($data['evenRowBackgroundColor']), $d['evenRowBackgroundColor']);
641 + $instance->oddRowBackgroundColor = new StringAttr(getOrNull($data['oddRowBackgroundColor']), $d['oddRowBackgroundColor']);
591 642 $instance->border = Sides::from_array(getOrNull($data['border']), $d['border']);
592 643 $instance->borderRadius = Corners::from_array(getOrNull($data['borderRadius']), $d['borderRadius']);
593 644 $instance->cells = is_array(getOrNull($data['cells'])) ? $data['cells'] : $d['cells'];
594 645