PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
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 0.5.7 All 42 releases
← All changes | renderer/Table/TableAttrs.php +49 -87 1.1.01.1.5 View file →
@@ -35,8 +35,18 @@
35 35 /** @var CellDefaults */
36 36 public $cellDefaults;
37 37
38 38 /**
39 + * Every attribute the table block carried, untouched. Pro registers
40 + * table-level attributes of its own, so its renderer reads them from
41 + * here rather than free having to know their names — mirrors
42 + * CellData->attrs.
43 + *
44 + * @var array<string, mixed>
45 + */
46 + public $attrs;
47 +
48 + /**
39 49 * @param array $data
40 50 * @return self
41 51 */
42 52 public static function from_array($data) {
@@ -43,8 +53,9 @@
43 53 $data = is_array($data) ? $data : [];
44 54 $defaults = Defaults::get_defaults();
45 55
46 56 $instance = new self();
57 + $instance->attrs = $data;
47 58 $instance->version = new NumberAttr(
48 59 getOrNull($data['version']),
49 60 $defaults['version']
50 61 );
@@ -136,13 +147,9 @@
136 147
137 148 $columns = [];
138 149
139 150 foreach ($data as $column => $column_config) {
140 - $columns[(int) $column] = ColumnConfig::from_array(
141 - $column_config,
142 - 'text',
143 - true
144 - );
151 + $columns[(int) $column] = ColumnConfig::from_array($column_config);
145 152 }
146 153
147 154 return $columns;
148 155 }
@@ -260,39 +267,8 @@
260 267 return $instance;
261 268 }
262 269 }
263 270
264 -class SearchConfig {
265 - /** @var BoolAttr */
266 - public $enabled;
267 -
268 - /** @var StringAttr */
269 - public $placeholder;
270 -
271 - /** @var StringAttr */
272 - public $highlightColor;
273 -
274 - /** @var StringAttr */
275 - public $position;
276 -
277 - /** @return self */
278 - public static function from_array($data) {
279 - $data = is_array($data) ? $data : [];
280 - $table_defaults = TableAttrs::get_table_defaults();
281 - $d = isset($table_defaults['search']) && is_array($table_defaults['search'])
282 - ? $table_defaults['search']
283 - : [];
284 -
285 - $instance = new self();
286 - $instance->enabled = new BoolAttr(getOrNull($data['enabled']), $d['enabled']);
287 - $instance->placeholder = new StringAttr(getOrNull($data['placeholder']), $d['placeholder']);
288 - $instance->highlightColor = new StringAttr(getOrNull($data['highlightColor']), $d['highlightColor']);
289 - $instance->position = new StringAttr(getOrNull($data['position']), $d['position'], ['left', 'right']);
290 -
291 - return $instance;
292 - }
293 -}
294 -
295 271 class ResponsiveBreakpointConfig {
296 272 /** @var BoolAttr */
297 273 public $enabled;
298 274
@@ -444,13 +420,23 @@
444 420
445 421 /** @var array<string, mixed>|null */
446 422 public $ribbon;
447 423
424 + /**
425 + * Every attribute the cell block carried, untouched. Pro registers cell
426 + * attributes of its own, so its renderer reads them from here rather
427 + * than free having to know their names.
428 + *
429 + * @var array<string, mixed>
430 + */
431 + public $attrs;
432 +
448 433 /** @return self */
449 434 public static function from_array($data) {
450 435 $data = is_array($data) ? $data : [];
451 436
452 437 $instance = new self();
438 + $instance->attrs = $data;
453 439 $instance->span = Span::from_array(getOrNull($data['span']));
454 440 $instance->className = new StringAttr(getOrNull($data['className']), '');
455 441 $instance->elements = [];
456 442
@@ -486,14 +472,8 @@
486 472
487 473 /** @var BoolAttr */
488 474 public $footerEnabled;
489 475
490 - /** @var BoolAttr */
491 - public $stickyHeader;
492 -
493 - /** @var BoolAttr */
494 - public $stickyFirstCol;
495 -
496 476 /** @var StringAttr */
497 477 public $caption;
498 478
499 479 /** @var StringAttr */
@@ -519,11 +499,8 @@
519 499
520 500 /** @var PaginationConfig */
521 501 public $pagination;
522 502
523 - /** @var SearchConfig */
524 - public $search;
525 -
526 503 /** @var ResponsiveConfig */
527 504 public $responsive;
528 505
529 506 /** @return self */
@@ -536,13 +513,8 @@
536 513 $instance->cols = new NumberAttr(getOrNull($data['cols']), $d['cols']);
537 514 $instance->className = new StringAttr(getOrNull($data['className']), '');
538 515 $instance->headerEnabled = new BoolAttr(getOrNull($data['headerEnabled']), $d['headerEnabled']);
539 516 $instance->footerEnabled = new BoolAttr(getOrNull($data['footerEnabled']), $d['footerEnabled']);
540 - $instance->stickyHeader = new BoolAttr(getOrNull($data['stickyHeader']), $d['stickyHeader']);
541 - $instance->stickyFirstCol = new BoolAttr(
542 - getOrNull($data['stickyFirstCol']),
543 - getOrNull($d['stickyFirstCol']) ?? false
544 - );
545 517 $instance->caption = new StringAttr(getOrNull($data['caption']), $d['caption']);
546 518 $instance->tableWidth = new StringAttr(
547 519 getOrNull($data['tableWidth']),
548 520 $d['tableWidth']
@@ -570,9 +542,8 @@
570 542 getOrNull($data['fixedColumnWidths']),
571 543 $d['fixedColumnWidths']
572 544 );
573 545 $instance->pagination = PaginationConfig::from_array(getOrNull($data['pagination']));
574 - $instance->search = SearchConfig::from_array(getOrNull($data['search']));
575 546 $instance->responsive = ResponsiveConfig::from_array(getOrNull($data['responsive']));
576 547
577 548 return $instance;
578 549 }
@@ -582,22 +553,28 @@
582 553 /** @var Sides */
583 554 public $padding;
584 555
585 556 /** @var StringAttr */
586 - public $orientation;
557 + public $elementGap;
587 558
588 559 /** @var StringAttr */
589 - public $elementGap;
560 + public $verticalAlign;
590 561
591 562 /** @var StringAttr */
592 - public $wrap;
563 + public $backgroundColor;
593 564
594 565 /** @var StringAttr */
595 - public $verticalAlign;
566 + public $headerBackgroundColor;
596 567
597 568 /** @var StringAttr */
598 - public $backgroundColor;
569 + public $footerBackgroundColor;
599 570
571 + /** @var StringAttr */
572 + public $evenRowBackgroundColor;
573 +
574 + /** @var StringAttr */
575 + public $oddRowBackgroundColor;
576 +
600 577 /** @var Sides */
601 578 public $border;
602 579
603 580 /** @var Corners */
@@ -612,22 +589,12 @@
612 589 $d = TableAttrs::get_cell_style_defaults();
613 590
614 591 $instance = new self();
615 592 $instance->padding = Sides::from_array(getOrNull($data['padding']), $d['padding']);
616 - $instance->orientation = new StringAttr(
617 - getOrNull($data['orientation']),
618 - $d['orientation'],
619 - ['vertical', 'horizontal']
620 - );
621 593 $instance->elementGap = new StringAttr(
622 594 getOrNull($data['elementGap']),
623 595 $d['elementGap']
624 596 );
625 - $instance->wrap = new StringAttr(
626 - getOrNull($data['wrap']),
627 - $d['wrap'],
628 - ['wrap', 'nowrap']
629 - );
630 597 $instance->verticalAlign = new StringAttr(
631 598 getOrNull($data['verticalAlign']),
632 599 $d['verticalAlign'],
633 600 ['top', 'middle', 'bottom']
@@ -632,8 +599,12 @@
632 599 $d['verticalAlign'],
633 600 ['top', 'middle', 'bottom']
634 601 );
635 602 $instance->backgroundColor = new StringAttr(getOrNull($data['backgroundColor']), $d['backgroundColor']);
603 + $instance->headerBackgroundColor = new StringAttr(getOrNull($data['headerBackgroundColor']), $d['headerBackgroundColor']);
604 + $instance->footerBackgroundColor = new StringAttr(getOrNull($data['footerBackgroundColor']), $d['footerBackgroundColor']);
605 + $instance->evenRowBackgroundColor = new StringAttr(getOrNull($data['evenRowBackgroundColor']), $d['evenRowBackgroundColor']);
606 + $instance->oddRowBackgroundColor = new StringAttr(getOrNull($data['oddRowBackgroundColor']), $d['oddRowBackgroundColor']);
636 607 $instance->border = Sides::from_array(getOrNull($data['border']), $d['border']);
637 608 $instance->borderRadius = Corners::from_array(getOrNull($data['borderRadius']), $d['borderRadius']);
638 609 $instance->cells = is_array(getOrNull($data['cells'])) ? $data['cells'] : $d['cells'];
639 610
@@ -668,36 +639,17 @@
668 639 }
669 640
670 641 class ColumnConfig {
671 642 /** @var StringAttr|null */
672 - public $sortable;
673 -
674 - /** @var StringAttr|null */
675 643 public $width;
676 644
677 - /**
678 - * @param array|null $data
679 - * @param string $defaultSortable
680 - * @param bool $allowNull
681 - * @return self
682 - */
683 - public static function from_array($data, $defaultSortable = 'text', $allowNull = false) {
645 + /** @return self */
646 + public static function from_array($data) {
684 647 $data = is_array($data) ? $data : [];
685 - $sortable = getOrNull($data['sortable']);
686 648 $width = getOrNull($data['width']);
687 649
688 650 $instance = new self();
689 651
690 - if ($allowNull && ($sortable === null || $sortable === '')) {
691 - $instance->sortable = null;
692 - } else {
693 - $instance->sortable = new StringAttr(
694 - $sortable,
695 - $defaultSortable,
696 - ['text', 'number', 'date']
697 - );
698 - }
699 -
700 652 if ($width === null || $width === '') {
701 653 $instance->width = null;
702 654 } else {
703 655 $instance->width = new StringAttr($width, '');
@@ -711,8 +663,17 @@
711 663 /** @var StringAttr|null */
712 664 public $height;
713 665
714 666 /**
667 + * Every attribute the row block carried, untouched. Pro registers row
668 + * attributes of its own (e.g. backgroundColor), so its renderer reads
669 + * them from here rather than free having to know their names.
670 + *
671 + * @var array<string, mixed>
672 + */
673 + public $attrs;
674 +
675 + /**
715 676 * @param array|null $data
716 677 * @return self
717 678 */
718 679 public static function from_array($data) {
@@ -719,8 +680,9 @@
719 680 $data = is_array($data) ? $data : [];
720 681 $height = getOrNull($data['height']);
721 682
722 683 $instance = new self();
684 + $instance->attrs = $data;
723 685
724 686 if ($height === null || $height === '') {
725 687 $instance->height = null;
726 688 } else {