This commit is contained in:
root
2025-11-13 19:04:05 +03:00
commit 240d0aba5f
75129 changed files with 11118122 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
<?
namespace Bitrix\UI\Toolbar;
abstract class ButtonLocation
{
const AFTER_TITLE = "after_title";
const RIGHT = "right";
const AFTER_FILTER = "after_filter";
const AFTER_NAVIGATION = "after_navigation";
/** @deprecated */
const FILTER_RIGHT = self::AFTER_FILTER;
}

View File

@@ -0,0 +1,127 @@
<?php
namespace Bitrix\UI\Toolbar\Facade;
use Bitrix\UI\Toolbar\ButtonLocation;
use Bitrix\UI\Toolbar\Manager;
/**
* Class Toolbar
* @package Bitrix\UI\Toolbar\Facade
* @method static getId();
* @see \Bitrix\UI\Toolbar\Toolbar::getId
* @method static addButton($button, $location = ButtonLocation::RIGHT);
* @see \Bitrix\UI\Toolbar\Toolbar::addButton
* @method static deleteButtons(\Closure $closure)
* @see \Bitrix\UI\Toolbar\Toolbar::deleteButtons
* @method static shuffleButtons(\Closure $closure, $buttonLocation)
* @see \Bitrix\UI\Toolbar\Toolbar::shuffleButtons
* @method static isEnabled();
* @see \Bitrix\UI\Toolbar\Toolbar::isEnabled
* @method static enable();
* @see \Bitrix\UI\Toolbar\Toolbar::enable
* @method static disable();
* @see \Bitrix\UI\Toolbar\Toolbar::disable
* @method static setTitle(string $title);
* @see \Bitrix\UI\Toolbar\Toolbar::setTitle
* @method static getTitle($propertyName = false, $stripTags = false);
* @see \Bitrix\UI\Toolbar\Toolbar::getTitle()
* @method static hideTitle();
* @see \Bitrix\UI\Toolbar\Toolbar::hideTitle
* @method static hasTitle();
* @see \Bitrix\UI\Toolbar\Toolbar::hasTitle
* @method static addEditableTitle(null|string $defaultTitle = null);
* @see \Bitrix\UI\Toolbar\Toolbar::addEditableTitle()
* // * @method static getEditableTitleSelector();
* // * @see \Bitrix\UI\Toolbar\Toolbar::getEditableTitleSelector
* @method static getDefaultEditableTitle();
* @see \Bitrix\UI\Toolbar\Toolbar::getDefaultEditableTitle
* @method static hasEditableTitle();
* @see \Bitrix\UI\Toolbar\Toolbar::hasEditableTitle()
* @method static hasFavoriteStar();
* @see \Bitrix\UI\Toolbar\Toolbar::hasFavoriteStar
* @method static addFavoriteStar();
* @see \Bitrix\UI\Toolbar\Toolbar::addFavoriteStar
* @method static deleteFavoriteStar();
* @see \Bitrix\UI\Toolbar\Toolbar::deleteFavoriteStar
* @method static addFilter($options = []);
* @see \Bitrix\UI\Toolbar\Toolbar::addFilter
* @method static setFilter(string $filter);
* @see \Bitrix\UI\Toolbar\Toolbar::setFilter
* @method static getFilter();
* @see \Bitrix\UI\Toolbar\Toolbar::getFilter
* @method static addBeforeTitleBoxHtml(string $html);
* @see \Bitrix\UI\Toolbar\Toolbar::addBeforeTitleHtml
* @method static getBeforeTitleBoxHtml();
* @see \Bitrix\UI\Toolbar\Toolbar::getBeforeTitleHtml
* @method static addBeforeTitleHtml(string $html);
* @see \Bitrix\UI\Toolbar\Toolbar::addBeforeTitleHtml
* @method static getBeforeTitleHtml();
* @see \Bitrix\UI\Toolbar\Toolbar::getBeforeTitleHtml
* @method static addAfterTitleHtml(string $html)
* @see \Bitrix\UI\Toolbar\Toolbar::addAfterTitleHtml
* @method static getAfterTitleHtml();
* @see \Bitrix\UI\Toolbar\Toolbar::getAfterTitleHtml
* * @method static addUnderTitleHtml(string $html)
* @see \Bitrix\UI\Toolbar\Toolbar::addUnderTitleHtml
*
* @method static void setCopyLinkButton(?array $params = []) Set params for copy link button. <br> <code>link</code> string, not required,<br> <code>successfulCopyMessage</code> string, not required.<br> <code>title</code> string, not required.
* @see \Bitrix\UI\Toolbar\Toolbar::setCopyLinkButton
*
* @method static void getCopyLinkButtonParams()
* @see \Bitrix\UI\Toolbar\Toolbar::getCopyLinkButtonParams
*
* @method static getUnderTitleHtml();
* @see \Bitrix\UI\Toolbar\Toolbar::getUnderTitleHtml
* @method static addRightCustomHtml(string $html, array $options = []);
* @see \Bitrix\UI\Toolbar\Toolbar::addRightCustomHtml
* @method static getRightCustomHtml();
* @see \Bitrix\UI\Toolbar\Toolbar::getRightCustomHtml
* @method static getRightCustomHtmlOptions();
* @see \Bitrix\UI\Toolbar\Toolbar::getRightCustomHtmlOptions
* @method static getButtons()
* @see \Bitrix\UI\Toolbar\Toolbar::getButtons
* @method static renderAfterTitleButtons();
* @see \Bitrix\UI\Toolbar\Toolbar::renderAfterTitleButtons
* @method static renderRightButtons();
* @see \Bitrix\UI\Toolbar\Toolbar::renderRightButtons
* @method static renderAfterFilterButtons();
* @see \Bitrix\UI\Toolbar\Toolbar::renderAfterFilterButtons
* @method static renderFilterRightButtons();
* @see \Bitrix\UI\Toolbar\Toolbar::renderFilterRightButtons
* @method static setTitleMinWidth($width);
* @see \Bitrix\UI\Toolbar\Toolbar::setTitleMinWidth
* @method static getTitleMinWidth();
* @see \Bitrix\UI\Toolbar\Toolbar::getTitleMinWidth
* @method static setTitleMaxWidth($width);
* @see \Bitrix\UI\Toolbar\Toolbar::setTitleMaxWidth
* @method static getTitleMaxWidth();
* @see \Bitrix\UI\Toolbar\Toolbar::getTitleMaxWidth
* @method static setTitleNoShrink();
* @see \Bitrix\UI\Toolbar\Toolbar::setTitleNoShrink()
* @method static isTitleNoShrink();
* @see \Bitrix\UI\Toolbar\Toolbar::isTitleNoShrink()
* @method static enableMultiLineTitle();
* @see \Bitrix\UI\Toolbar\Toolbar::enableMultiLineTitle
* @method static disableMultiLineTitle();
* @see \Bitrix\UI\Toolbar\Toolbar::disableMultiLineTitle
* @method static isMultiLineTitleEnabled();
* @see \Bitrix\UI\Toolbar\Toolbar::isMultiLineTitleEnabled
*/
final class Toolbar
{
const DEFAULT_ID = 'default-toolbar';
public static function __callStatic($name, $arguments)
{
$manager = Manager::getInstance();
$toolbar = $manager->getToolbarById(self::DEFAULT_ID)?: $manager->createToolbar(self::DEFAULT_ID, []);
if (!$toolbar)
{
//or exception?
return null;
}
return call_user_func_array([$toolbar, $name], $arguments);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Bitrix\UI\Toolbar;
use Bitrix\Main\ArgumentException;
final class Manager
{
/** @var Manager */
private static $instance;
/** @var Toolbar[] */
protected $toolbars = [];
private function __construct()
{}
private function __clone()
{}
/**
* Returns Singleton of Manager
* @return Manager
*/
public static function getInstance()
{
if (!isset(self::$instance))
{
self::$instance = new Manager;
}
return self::$instance;
}
/**
* @param $id
*
* @return Toolbar|null
*/
public function getToolbarById($id)
{
if (isset($this->toolbars[$id]))
{
return $this->toolbars[$id];
}
return null;
}
public function createToolbar($id, $options)
{
if (empty($id))
{
throw new ArgumentException("id is required", 'id');
}
$toolbar = new Toolbar($id, $options);
$this->toolbars[$id] = $toolbar;
return $toolbar;
}
}

View File

@@ -0,0 +1,535 @@
<?php
namespace Bitrix\UI\Toolbar;
use Bitrix\Main\ArgumentTypeException;
use Bitrix\Main\UI\Filter\Theme;
use Bitrix\UI\Buttons\AirButtonStyle;
use Bitrix\UI\Buttons\BaseButton;
use Bitrix\UI\Buttons\Button;
use Bitrix\UI\Buttons\Color;
use Bitrix\UI\Buttons\Size;
use Bitrix\UI\Buttons\Icon;
class Toolbar
{
private $id;
private $filter;
private ?string $title = null;
private bool $isMultiLineTitleEnabled = false;
private ?string $beforeTitleBoxHtml = null;
private $beforeTitleHtml;
private $afterTitleHtml;
private $underTitleHtml;
private string $rightCustomHtml;
private array $rightCustomHtmlOptions = [];
private $titleMinWidth;
private $titleMaxWidth;
private bool $isTitleNoShrink = false;
private $titleVisibility = true;
private $favoriteStar = true;
private bool $editableTitle = false;
private string $defaultEditableTitle;
// private string $editableTitleSelector;
private ?array $copyLinkButtonParams = null;
private $enabled = true;
/**
* @param Button[] $buttons
*/
private $afterTitleButtons = [];
/**
* @param Button[] $buttons
*/
private $buttons = [];
private $filterButtons = [];
private $options;
/**
* Toolbar constructor.
*
* @param string $id
* @param array $options
*/
public function __construct($id, $options)
{
$this->id = $id;
$this->options = $options;
if (isset($this->options['filter']))
{
$this->addFilter($this->options['filter']);
}
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function enable(): void
{
$this->enabled = true;
}
public function disable(): void
{
$this->enabled = false;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getTitle($propertyName = false, $stripTags = false): string
{
if ($this->title !== null)
{
return $stripTags ? strip_tags($this->title) : $this->title;
}
$title = $GLOBALS['APPLICATION']->getTitle($propertyName, $stripTags);
return is_string($title) ? $title : '';
}
public function hideTitle(): void
{
$this->titleVisibility = false;
}
public function hasTitle(): bool
{
return $this->titleVisibility;
}
public function addEditableTitle(string $defaultTitle = null): void
{
$this->defaultEditableTitle = $defaultTitle ?? '';
$this->editableTitle = true;
}
public function getDefaultEditableTitle(): ?string
{
return $this->hasEditableTitle()
? $this->defaultEditableTitle
: null
;
}
// public function getEditableTitleSelector(): ?string
// {
// return $this->hasEditableTitle()
// ? $this->editableTitleSelector
// : null
// ;
// }
public function hasEditableTitle(): bool
{
return $this->editableTitle;
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param array|Button $button
* @param string $location
* @see ButtonLocation
*
* @throws ArgumentTypeException
*/
public function addButton($button, $location = ButtonLocation::RIGHT)
{
if (is_array($button))
{
$button = new Button($button);
}
if ($this->hasAirDesign())
{
$button->setAirDesign(true);
$button->setNoCaps(true);
if ($button->getIcon() && $button->hasCollapsedIcon() === false)
{
// Set classname modifiers for air buttons
$button->setIcon($button->getIcon());
}
if ($button->getStyle() === null && $button->getColor() !== null)
{
$button->setStyle($this->convertColorToAirButtonStyle($button->getColor()));
}
if ($location === ButtonLocation::RIGHT && $button->getSize() === null)
{
$button->setSize(Size::SMALL);
}
if (
$location === ButtonLocation::AFTER_TITLE
&& $button->getStyle() === AirButtonStyle::FILLED_SUCCESS
&& $button->getIcon() === null
)
{
$button->setIcon(Icon::ADD_M);
}
}
if (!($button instanceof Button))
{
throw new ArgumentTypeException("button", Button::class);
}
if ($location === ButtonLocation::AFTER_FILTER)
{
$this->filterButtons[] = $button;
}
elseif($location === ButtonLocation::AFTER_TITLE)
{
$this->afterTitleButtons[] = $button;
}
else
{
$this->buttons[] = $button;
}
}
public function deleteButtons(\Closure $closure)
{
foreach ($this->buttons as $i => $button)
{
if ($closure($button, ButtonLocation::RIGHT) === true)
{
unset($this->buttons[$i]);
}
}
foreach ($this->filterButtons as $i => $button)
{
if ($closure($button, ButtonLocation::AFTER_FILTER) === true)
{
unset($this->filterButtons[$i]);
}
}
foreach ($this->afterTitleButtons as $i => $button)
{
if ($closure($button, ButtonLocation::AFTER_TITLE) === true)
{
unset($this->afterTitleButtons[$i]);
}
}
}
public function shuffleButtons(\Closure $closure, $buttonLocation)
{
$buttonList = null;
switch ($buttonLocation)
{
case ButtonLocation::RIGHT:
$buttonList = $this->buttons;
break;
case ButtonLocation::AFTER_FILTER:
$buttonList = $this->filterButtons;
break;
}
if ($buttonList)
{
$buttonList = $closure($buttonList);
if (!is_array($buttonList))
{
throw new ArgumentTypeException('buttonList', 'array');
}
switch ($buttonLocation)
{
case ButtonLocation::RIGHT:
$this->buttons = $buttonList;
break;
case ButtonLocation::AFTER_FILTER:
$this->filterButtons = $buttonList;
break;
}
}
}
public function hasFavoriteStar()
{
return (bool)$this->favoriteStar;
}
public function addFavoriteStar()
{
$this->favoriteStar = true;
return $this;
}
public function deleteFavoriteStar()
{
$this->favoriteStar = false;
return $this;
}
public function addFilter(array $filterOptions = [])
{
ob_start();
if ($this->hasAirDesign())
{
$updatedFilterOptions = [
...$filterOptions,
'THEME' => Theme::AIR,
];
if (isset($updatedFilterOptions['CONFIG']) === false)
{
$updatedFilterOptions['CONFIG'] = [];
}
$updatedFilterOptions['CONFIG']['AUTOFOCUS'] = false;
$GLOBALS['APPLICATION']->includeComponent('bitrix:main.ui.filter', '', $updatedFilterOptions);
}
else
{
$GLOBALS['APPLICATION']->includeComponent('bitrix:main.ui.filter', '', $filterOptions);
}
$this->filter = ob_get_clean();
}
public function setFilter(string $filter)
{
$this->filter = $filter;
}
public function getFilter()
{
return $this->filter;
}
public function addBeforeTitleBoxHtml(string $html): void
{
$this->beforeTitleBoxHtml = $html;
}
public function getBeforeTitleBoxHtml(): ?string
{
return $this->beforeTitleBoxHtml;
}
public function addBeforeTitleHtml(string $html)
{
$this->beforeTitleHtml = $html;
}
public function getBeforeTitleHtml(): ?string
{
return $this->beforeTitleHtml;
}
public function addAfterTitleHtml(string $html)
{
$this->afterTitleHtml = $html;
}
public function getAfterTitleHtml(): ?string
{
return $this->afterTitleHtml;
}
public function addUnderTitleHtml(string $html)
{
$this->underTitleHtml = $html;
}
public function getUnderTitleHtml(): ?string
{
return $this->underTitleHtml;
}
public function addRightCustomHtml(string $html, array $options = []): void
{
$this->rightCustomHtml = $html;
$this->rightCustomHtmlOptions = $options;
}
public function getRightCustomHtml(): string
{
return $this->rightCustomHtml ?? '';
}
public function getRightCustomHtmlOptions(): array
{
return $this->rightCustomHtmlOptions ?? [];
}
/**
* @param null|array{link?: string, successfulCopyMessage?: string, title?: string} $params
*
* @return void
*/
public function setCopyLinkButton(?array $params = []): void
{
if (is_array($params))
{
$this->copyLinkButtonParams = $params;
$this->copyLinkButtonParams['active'] = true;
}
else
{
$this->copyLinkButtonParams = null;
}
}
/**
* @return null|array{link: string, successfulCopyMessage?: string, title?: string}
*/
public function getCopyLinkButton(): ?array
{
return $this->copyLinkButtonParams;
}
/**
* @return BaseButton[]
*/
public function getButtons()
{
return array_merge($this->afterTitleButtons, $this->filterButtons, $this->buttons);
}
public function renderAfterTitleButtons()
{
return implode(array_map(function(Button $button) {
return self::processButtonRender($button);
}, $this->afterTitleButtons));
}
public function renderRightButtons()
{
return implode(array_map(function(Button $button) {
return self::processButtonRender($button);
}, $this->buttons));
}
public function renderAfterFilterButtons()
{
return implode(array_map(function(Button $button) {
return self::processButtonRender($button);
}, $this->filterButtons));
}
/**
* @deprecated
* @return string
*/
public function renderFilterRightButtons()
{
return $this->renderAfterFilterButtons();
}
protected function processButtonRender(Button $button)
{
$shouldAddThemeModifier = (bool)array_intersect($button->getClassList(), [
'ui-btn-light-border',
'ui-btn-light',
'ui-btn-link',
]) && $button->hasAirDesign() === false;
if ($shouldAddThemeModifier)
{
$button->addClass('ui-btn-themes');
}
return $button->render(false);
}
public function setTitleMinWidth($width)
{
if (is_int($width) && $width > 0)
{
$this->titleMinWidth = $width;
}
}
public function getTitleMinWidth()
{
return $this->titleMinWidth;
}
public function setTitleMaxWidth($width)
{
if (is_int($width) && $width > 0)
{
$this->titleMaxWidth = $width;
}
}
public function setTitleNoShrink(bool $flag = true): void
{
$this->isTitleNoShrink = $flag;
}
public function isTitleNoShrink(): bool
{
return $this->isTitleNoShrink;
}
public function getTitleMaxWidth()
{
return $this->titleMaxWidth;
}
public function enableMultiLineTitle(): void
{
$this->isMultiLineTitleEnabled = true;
}
public function disableMultiLineTitle(): void
{
$this->isMultiLineTitleEnabled = false;
}
public function isMultiLineTitleEnabled(): bool
{
return $this->isMultiLineTitleEnabled;
}
/**
* @param string|null $color
* @return string|null
*/
protected function convertColorToAirButtonStyle(string $color = null): ?string
{
$map = [
Color::DANGER => AirButtonStyle::FILLED_ALERT,
Color::DANGER_LIGHT => AirButtonStyle::FILLED_ALERT,
Color::DANGER_DARK => AirButtonStyle::FILLED_ALERT,
Color::SUCCESS => AirButtonStyle::FILLED_SUCCESS,
Color::SUCCESS_LIGHT => AirButtonStyle::FILLED_SUCCESS,
Color::PRIMARY => AirButtonStyle::FILLED_SUCCESS,
Color::PRIMARY_DARK => AirButtonStyle::FILLED_SUCCESS,
Color::LIGHT_BORDER => AirButtonStyle::OUTLINE,
Color::LINK => AirButtonStyle::OUTLINE,
Color::SECONDARY => AirButtonStyle::TINTED,
Color::LIGHT => AirButtonStyle::PLAIN_ACCENT,
];
return $map[$color] ?? null;
}
public function hasAirDesign(): bool
{
return defined('AIR_SITE_TEMPLATE');
}
}