diff --git a/packages/htmx/src/Libs/HTMX.php b/packages/htmx/src/Libs/HTMX.php index 84cecf8..fb92a53 100644 --- a/packages/htmx/src/Libs/HTMX.php +++ b/packages/htmx/src/Libs/HTMX.php @@ -13,29 +13,6 @@ namespace Libs; */ class HTMX extends HTMLComponent { - /** - * Valid HTMX swap styles. - */ - public const SWAP_STYLES = [ - 'innerHTML', 'outerHTML', 'outerSync', - 'beforebegin', 'before', - 'afterbegin', 'prepend', - 'beforeend', 'append', - 'afterend', 'after', - 'delete', 'none', - 'innerMorph', 'outerMorph', - 'textContent', - ]; - - /** - * Valid HTMX swap option keys (used as key:value after the style). - */ - public const SWAP_OPTIONS = [ - 'swap', 'settle', 'transition', 'ignoreTitle', 'strip', - 'focusScroll', 'swapEmpty', 'scroll', 'show', 'showTarget', - 'scrollTarget', 'target', - ]; - /** * Renders a component * @@ -266,8 +243,6 @@ class HTMX extends HTMLComponent * @param bool $excludeBoosted Exclude if the request is boosted (default: false) * * @return string - * - * @throws \InvalidArgumentException On an unknown style or option. */ public static function swapOob(string $value = 'true', bool $excludeBoosted = false): string { @@ -275,10 +250,6 @@ class HTMX extends HTMLComponent return ''; } - if ($value !== 'true') { - $value = static::validateSwap($value); - } - return static::isHtmx() ? 'hx-swap-oob="' . $value . '"' : ''; } @@ -318,8 +289,6 @@ class HTMX extends HTMLComponent return ''; } - $swap = static::validateSwap($swap); - return '' . $content @@ -381,52 +350,10 @@ class HTMX extends HTMLComponent * @param string $rule * * @return void - * - * @throws \InvalidArgumentException On an unknown style or option. */ public static function reswap(string $rule = 'innerHTML'): void { - header('HX-Reswap: ' . static::validateSwap($rule)); - } - - /** - * Validates a HTMX swap value ("style [key:value]..."). - * - * @param string $value - * - * @return string The normalized value. - * - * @throws \InvalidArgumentException On an unknown style or option. - */ - public static function validateSwap(string $value): string - { - $parts = preg_split( - '/\s+/', - trim($value), - -1, - PREG_SPLIT_NO_EMPTY - ); - - if (empty($parts)) { - throw new \InvalidArgumentException('Empty swap value.'); - } - - if (!in_array($parts[0], static::SWAP_STYLES, true)) { - throw new \InvalidArgumentException( - 'Invalid swap style: ' . $parts[0] - ); - } - - foreach (array_slice($parts, 1) as $option) { - $key = explode(':', $option)[0]; - if (!in_array($key, static::SWAP_OPTIONS, true)) { - throw new \InvalidArgumentException( - 'Invalid swap option: ' . $option - ); - } - } - - return implode(' ', $parts); + header('HX-Reswap: ' . $rule); } /**