| @@ -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,11 +472,8 @@ | ||
| 486 | 472 | |
| 487 | 473 | /** @var BoolAttr */ |
| 488 | 474 | public $footerEnabled; |
| 489 | 475 | |
| 490 | - /** @var BoolAttr */ | |
| 491 | - public $stickyHeader; | |
| 492 | - | |
| 493 | 476 | /** @var StringAttr */ |
| 494 | 477 | public $caption; |
| 495 | 478 | |
| 496 | 479 | /** @var StringAttr */ |
| @@ -504,8 +487,14 @@ | ||
| 504 | 487 | |
| 505 | 488 | /** @var Sides */ |
| 506 | 489 | public $tableBorder; |
| 507 | 490 | |
| 491 | + /** @var Sides */ | |
| 492 | + public $margin; | |
| 493 | + | |
| 494 | + /** @var Sides */ | |
| 495 | + public $padding; | |
| 496 | + | |
| 508 | 497 | /** @var BoolAttr */ |
| 509 | 498 | public $fixedColumnWidths; |
| 510 | 499 | |
| 511 | 500 | /** @var PaginationConfig */ |
| @@ -510,11 +499,8 @@ | ||
| 510 | 499 | |
| 511 | 500 | /** @var PaginationConfig */ |
| 512 | 501 | public $pagination; |
| 513 | 502 | |
| 514 | - /** @var SearchConfig */ | |
| 515 | - public $search; | |
| 516 | - | |
| 517 | 503 | /** @var ResponsiveConfig */ |
| 518 | 504 | public $responsive; |
| 519 | 505 | |
| 520 | 506 | /** @return self */ |
| @@ -527,9 +513,8 @@ | ||
| 527 | 513 | $instance->cols = new NumberAttr(getOrNull($data['cols']), $d['cols']); |
| 528 | 514 | $instance->className = new StringAttr(getOrNull($data['className']), ''); |
| 529 | 515 | $instance->headerEnabled = new BoolAttr(getOrNull($data['headerEnabled']), $d['headerEnabled']); |
| 530 | 516 | $instance->footerEnabled = new BoolAttr(getOrNull($data['footerEnabled']), $d['footerEnabled']); |
| 531 | - $instance->stickyHeader = new BoolAttr(getOrNull($data['stickyHeader']), $d['stickyHeader']); | |
| 532 | 517 | $instance->caption = new StringAttr(getOrNull($data['caption']), $d['caption']); |
| 533 | 518 | $instance->tableWidth = new StringAttr( |
| 534 | 519 | getOrNull($data['tableWidth']), |
| 535 | 520 | $d['tableWidth'] |
| @@ -543,14 +528,22 @@ | ||
| 543 | 528 | $instance->tableBorder = Sides::from_array( |
| 544 | 529 | getOrNull($data['tableBorder']), |
| 545 | 530 | $d['tableBorder'] |
| 546 | 531 | ); |
| 532 | + $emptySides = ['top' => '', 'right' => '', 'bottom' => '', 'left' => '']; | |
| 533 | + $instance->margin = Sides::from_array( | |
| 534 | + getOrNull($data['margin']), | |
| 535 | + isset($d['margin']) && is_array($d['margin']) ? $d['margin'] : $emptySides | |
| 536 | + ); | |
| 537 | + $instance->padding = Sides::from_array( | |
| 538 | + getOrNull($data['padding']), | |
| 539 | + isset($d['padding']) && is_array($d['padding']) ? $d['padding'] : $emptySides | |
| 540 | + ); | |
| 547 | 541 | $instance->fixedColumnWidths = new BoolAttr( |
| 548 | 542 | getOrNull($data['fixedColumnWidths']), |
| 549 | 543 | $d['fixedColumnWidths'] |
| 550 | 544 | ); |
| 551 | 545 | $instance->pagination = PaginationConfig::from_array(getOrNull($data['pagination'])); |
| 552 | - $instance->search = SearchConfig::from_array(getOrNull($data['search'])); | |
| 553 | 546 | $instance->responsive = ResponsiveConfig::from_array(getOrNull($data['responsive'])); |
| 554 | 547 | |
| 555 | 548 | return $instance; |
| 556 | 549 | } |
| @@ -560,22 +553,28 @@ | ||
| 560 | 553 | /** @var Sides */ |
| 561 | 554 | public $padding; |
| 562 | 555 | |
| 563 | 556 | /** @var StringAttr */ |
| 564 | - public $orientation; | |
| 557 | + public $elementGap; | |
| 565 | 558 | |
| 566 | 559 | /** @var StringAttr */ |
| 567 | - public $elementGap; | |
| 560 | + public $verticalAlign; | |
| 568 | 561 | |
| 569 | 562 | /** @var StringAttr */ |
| 570 | - public $wrap; | |
| 563 | + public $backgroundColor; | |
| 571 | 564 | |
| 572 | 565 | /** @var StringAttr */ |
| 573 | - public $verticalAlign; | |
| 566 | + public $headerBackgroundColor; | |
| 574 | 567 | |
| 575 | 568 | /** @var StringAttr */ |
| 576 | - public $backgroundColor; | |
| 569 | + public $footerBackgroundColor; | |
| 577 | 570 | |
| 571 | + /** @var StringAttr */ | |
| 572 | + public $evenRowBackgroundColor; | |
| 573 | + | |
| 574 | + /** @var StringAttr */ | |
| 575 | + public $oddRowBackgroundColor; | |
| 576 | + | |
| 578 | 577 | /** @var Sides */ |
| 579 | 578 | public $border; |
| 580 | 579 | |
| 581 | 580 | /** @var Corners */ |
| @@ -590,22 +589,12 @@ | ||
| 590 | 589 | $d = TableAttrs::get_cell_style_defaults(); |
| 591 | 590 | |
| 592 | 591 | $instance = new self(); |
| 593 | 592 | $instance->padding = Sides::from_array(getOrNull($data['padding']), $d['padding']); |
| 594 | - $instance->orientation = new StringAttr( | |
| 595 | - getOrNull($data['orientation']), | |
| 596 | - $d['orientation'], | |
| 597 | - ['vertical', 'horizontal'] | |
| 598 | - ); | |
| 599 | 593 | $instance->elementGap = new StringAttr( |
| 600 | 594 | getOrNull($data['elementGap']), |
| 601 | 595 | $d['elementGap'] |
| 602 | 596 | ); |
| 603 | - $instance->wrap = new StringAttr( | |
| 604 | - getOrNull($data['wrap']), | |
| 605 | - $d['wrap'], | |
| 606 | - ['wrap', 'nowrap'] | |
| 607 | - ); | |
| 608 | 597 | $instance->verticalAlign = new StringAttr( |
| 609 | 598 | getOrNull($data['verticalAlign']), |
| 610 | 599 | $d['verticalAlign'], |
| 611 | 600 | ['top', 'middle', 'bottom'] |
| @@ -610,8 +599,12 @@ | ||
| 610 | 599 | $d['verticalAlign'], |
| 611 | 600 | ['top', 'middle', 'bottom'] |
| 612 | 601 | ); |
| 613 | 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']); | |
| 614 | 607 | $instance->border = Sides::from_array(getOrNull($data['border']), $d['border']); |
| 615 | 608 | $instance->borderRadius = Corners::from_array(getOrNull($data['borderRadius']), $d['borderRadius']); |
| 616 | 609 | $instance->cells = is_array(getOrNull($data['cells'])) ? $data['cells'] : $d['cells']; |
| 617 | 610 | |
| @@ -646,36 +639,17 @@ | ||
| 646 | 639 | } |
| 647 | 640 | |
| 648 | 641 | class ColumnConfig { |
| 649 | 642 | /** @var StringAttr|null */ |
| 650 | - public $sortable; | |
| 651 | - | |
| 652 | - /** @var StringAttr|null */ | |
| 653 | 643 | public $width; |
| 654 | 644 | |
| 655 | - /** | |
| 656 | - * @param array|null $data | |
| 657 | - * @param string $defaultSortable | |
| 658 | - * @param bool $allowNull | |
| 659 | - * @return self | |
| 660 | - */ | |
| 661 | - public static function from_array($data, $defaultSortable = 'text', $allowNull = false) { | |
| 645 | + /** @return self */ | |
| 646 | + public static function from_array($data) { | |
| 662 | 647 | $data = is_array($data) ? $data : []; |
| 663 | - $sortable = getOrNull($data['sortable']); | |
| 664 | 648 | $width = getOrNull($data['width']); |
| 665 | 649 | |
| 666 | 650 | $instance = new self(); |
| 667 | 651 | |
| 668 | - if ($allowNull && ($sortable === null || $sortable === '')) { | |
| 669 | - $instance->sortable = null; | |
| 670 | - } else { | |
| 671 | - $instance->sortable = new StringAttr( | |
| 672 | - $sortable, | |
| 673 | - $defaultSortable, | |
| 674 | - ['text', 'number', 'date'] | |
| 675 | - ); | |
| 676 | - } | |
| 677 | - | |
| 678 | 652 | if ($width === null || $width === '') { |
| 679 | 653 | $instance->width = null; |
| 680 | 654 | } else { |
| 681 | 655 | $instance->width = new StringAttr($width, ''); |
| @@ -689,8 +663,17 @@ | ||
| 689 | 663 | /** @var StringAttr|null */ |
| 690 | 664 | public $height; |
| 691 | 665 | |
| 692 | 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 | + /** | |
| 693 | 676 | * @param array|null $data |
| 694 | 677 | * @return self |
| 695 | 678 | */ |
| 696 | 679 | public static function from_array($data) { |
| @@ -697,8 +680,9 @@ | ||
| 697 | 680 | $data = is_array($data) ? $data : []; |
| 698 | 681 | $height = getOrNull($data['height']); |
| 699 | 682 | |
| 700 | 683 | $instance = new self(); |
| 684 | + $instance->attrs = $data; | |
| 701 | 685 | |
| 702 | 686 | if ($height === null || $height === '') { |
| 703 | 687 | $instance->height = null; |
| 704 | 688 | } else { |
| @@ -736,8 +720,9 @@ | ||
| 736 | 720 | 'list', |
| 737 | 721 | 'icon', |
| 738 | 722 | 'star-rating', |
| 739 | 723 | 'custom-html', |
| 724 | + 'styled-list', | |
| 740 | 725 | ]; |
| 741 | 726 | } |
| 742 | 727 | |
| 743 | 728 | $instance = new self(); |