Compare commits

...
Author SHA1 Message Date
kj 4b80b885e0 release(htmx): v0.2.0 2026-10-07 19:07:32 -03:00
kj e2b9fc0392 feat(htmx): drop server-side swap style/option validation 2026-10-07 19:07:28 -03:00
2 changed files with 2 additions and 75 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "htmx", "name": "htmx",
"version": "0.1.1", "version": "0.2.0",
"description": "Motor de vistas basado en componentes y HTMX", "description": "Motor de vistas basado en componentes y HTMX",
"core": { "core": {
"requires": ">=0.1", "requires": ">=0.1",
+1 -74
View File
@@ -13,29 +13,6 @@ namespace Libs;
*/ */
class HTMX extends HTMLComponent 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 * Renders a component
* *
@@ -266,8 +243,6 @@ class HTMX extends HTMLComponent
* @param bool $excludeBoosted Exclude if the request is boosted (default: false) * @param bool $excludeBoosted Exclude if the request is boosted (default: false)
* *
* @return string * @return string
*
* @throws \InvalidArgumentException On an unknown style or option.
*/ */
public static function swapOob(string $value = 'true', bool $excludeBoosted = false): string public static function swapOob(string $value = 'true', bool $excludeBoosted = false): string
{ {
@@ -275,10 +250,6 @@ class HTMX extends HTMLComponent
return ''; return '';
} }
if ($value !== 'true') {
$value = static::validateSwap($value);
}
return static::isHtmx() ? 'hx-swap-oob="' . $value . '"' : ''; return static::isHtmx() ? 'hx-swap-oob="' . $value . '"' : '';
} }
@@ -318,8 +289,6 @@ class HTMX extends HTMLComponent
return ''; return '';
} }
$swap = static::validateSwap($swap);
return '<hx-partial hx-target="' . htmlspecialchars($target) return '<hx-partial hx-target="' . htmlspecialchars($target)
. '" hx-swap="' . htmlspecialchars($swap) . '">' . '" hx-swap="' . htmlspecialchars($swap) . '">'
. $content . $content
@@ -381,52 +350,10 @@ class HTMX extends HTMLComponent
* @param string $rule * @param string $rule
* *
* @return void * @return void
*
* @throws \InvalidArgumentException On an unknown style or option.
*/ */
public static function reswap(string $rule = 'innerHTML'): void public static function reswap(string $rule = 'innerHTML'): void
{ {
header('HX-Reswap: ' . static::validateSwap($rule)); header('HX-Reswap: ' . $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);
} }
/** /**