@times-design-system/components-wordpress 1.14.0 → 1.16.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/STYLE_HANDLES.md +3 -1
  2. package/dist/blocks/ad-container/block.json +5 -0
  3. package/dist/blocks/ad-container/render.php +10 -1
  4. package/dist/blocks/ad-container/style.css +1 -1
  5. package/dist/blocks/ad-container/style.scss +3 -2
  6. package/dist/blocks/button/block.json +5 -0
  7. package/dist/blocks/button/render.php +12 -2
  8. package/dist/blocks/button/style.css +1 -1
  9. package/dist/blocks/button/style.scss +33 -33
  10. package/dist/blocks/chip/block.json +15 -0
  11. package/dist/blocks/chip/render.php +54 -21
  12. package/dist/blocks/chip/style.css +1 -1
  13. package/dist/blocks/chip/style.scss +136 -76
  14. package/dist/blocks/dialog-box/block.json +5 -0
  15. package/dist/blocks/dialog-box/render.php +9 -1
  16. package/dist/blocks/dialog-box/style.css +1 -1
  17. package/dist/blocks/dialog-box/style.scss +6 -5
  18. package/dist/blocks/divider/block.json +21 -1
  19. package/dist/blocks/divider/render.php +9 -1
  20. package/dist/blocks/divider/style.css +1 -1
  21. package/dist/blocks/divider/style.scss +4 -3
  22. package/dist/blocks/icon/block.json +5 -0
  23. package/dist/blocks/icon/render.php +10 -12
  24. package/dist/blocks/icon/style.css +1 -1
  25. package/dist/blocks/icon/style.scss +4 -0
  26. package/dist/blocks/icon-button/block.json +5 -0
  27. package/dist/blocks/icon-button/render.php +14 -4
  28. package/dist/blocks/icon-button/style.css +1 -1
  29. package/dist/blocks/icon-button/style.scss +33 -32
  30. package/dist/blocks/input/block.json +5 -0
  31. package/dist/blocks/input/render.php +10 -1
  32. package/dist/blocks/input/style.css +1 -1
  33. package/dist/blocks/input/style.scss +14 -13
  34. package/dist/blocks/input-helper-message/block.json +5 -0
  35. package/dist/blocks/input-helper-message/render.php +9 -1
  36. package/dist/blocks/input-helper-message/style.css +1 -1
  37. package/dist/blocks/input-helper-message/style.scss +6 -5
  38. package/dist/blocks/label/block.json +68 -0
  39. package/dist/blocks/label/edit.js +79 -0
  40. package/dist/blocks/label/index.js +11 -0
  41. package/dist/blocks/label/render.php +56 -0
  42. package/dist/blocks/label/save.js +21 -0
  43. package/dist/blocks/label/style.css +1 -0
  44. package/dist/blocks/label/style.scss +39 -0
  45. package/dist/blocks/link/block.json +5 -0
  46. package/dist/blocks/link/render.php +3 -1
  47. package/dist/blocks/link/style.css +1 -1
  48. package/dist/blocks/link/style.scss +19 -18
  49. package/dist/blocks/tab/block.json +5 -0
  50. package/dist/blocks/tab/render.php +9 -1
  51. package/dist/blocks/tab/style.css +1 -1
  52. package/dist/blocks/tab/style.scss +16 -15
  53. package/dist/blocks/tab-group/block.json +5 -0
  54. package/dist/blocks/tab-group/render.php +9 -1
  55. package/dist/blocks/tab-group/style.css +1 -1
  56. package/dist/blocks/tab-group/style.scss +2 -1
  57. package/dist/blocks/tag/block.json +5 -0
  58. package/dist/blocks/tag/render.php +10 -1
  59. package/dist/blocks/tag/style.css +1 -1
  60. package/dist/blocks/tag/style.scss +23 -25
  61. package/dist/blocks/text/block.json +5 -0
  62. package/dist/blocks/text/render.php +9 -1
  63. package/dist/blocks/toast/block.json +5 -0
  64. package/dist/blocks/toast/render.php +10 -1
  65. package/dist/blocks/toast/style.css +1 -1
  66. package/dist/blocks/toast/style.scss +13 -12
  67. package/dist/icon-data.json +1 -1
  68. package/dist/index.cjs +485 -177
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.css +1 -1
  71. package/dist/index.css.map +1 -1
  72. package/dist/index.js +485 -177
  73. package/dist/index.js.map +1 -1
  74. package/dist/plugin.php +1 -0
  75. package/dist/style-handles.json +5 -0
  76. package/dist/utils/render-icon.php +3 -0
  77. package/dist/utils/sanitize-aria-attributes.php +109 -0
  78. package/package.json +4 -4
  79. package/plugin.php +1 -0
  80. package/dist/blocks/utils/render-icon.php +0 -106
  81. package/dist/blocks/utils/sanitize-data-attributes.php +0 -37
package/dist/plugin.php CHANGED
@@ -40,6 +40,7 @@ function tds_register_block_styles() {
40
40
  'icon-button' => 'tds-icon-button-style',
41
41
  'input' => 'tds-input-style',
42
42
  'input-helper-message' => 'tds-input-helper-message-style',
43
+ 'label' => 'tds-label-style',
43
44
  'link' => 'tds-link-style',
44
45
  'tab' => 'tds-tab-style',
45
46
  'tab-group' => 'tds-tab-group-style',
@@ -44,6 +44,11 @@
44
44
  "cssFile": "blocks/input-helper-message/style.css",
45
45
  "phpPath": "blocks/input-helper-message/style.css"
46
46
  },
47
+ "label": {
48
+ "handle": "tds-label-style",
49
+ "cssFile": "blocks/label/style.css",
50
+ "phpPath": "blocks/label/style.css"
51
+ },
47
52
  "link": {
48
53
  "handle": "tds-link-style",
49
54
  "cssFile": "blocks/link/style.css",
@@ -243,6 +243,7 @@ if (!function_exists('tds_kses_svg')) {
243
243
  'svg' => array(
244
244
  'xmlns' => true,
245
245
  'viewBox' => true,
246
+ 'viewbox' => true,
246
247
  'width' => true,
247
248
  'height' => true,
248
249
  'class' => true,
@@ -345,6 +346,8 @@ if (!function_exists('tds_kses_svg')) {
345
346
  'y' => true,
346
347
  'width' => true,
347
348
  'height' => true,
349
+ 'viewBox' => true,
350
+ 'viewbox' => true,
348
351
  'class' => true,
349
352
  ),
350
353
  );
@@ -0,0 +1,109 @@
1
+ <?php
2
+ /**
3
+ * ARIA Attributes Sanitization Utility
4
+ *
5
+ * Provides shared sanitization logic for block aria-* attributes.
6
+ * Ensures consistent security and validation across all blocks.
7
+ *
8
+ * @package TimesDesignSystem\ComponentsWordPress
9
+ */
10
+
11
+ /**
12
+ * Sanitize and validate custom aria-* attributes
13
+ *
14
+ * Applies a whitelist filter to determine which aria-* attributes are allowed,
15
+ * then validates and sanitizes each attribute before output.
16
+ *
17
+ * @param array $aria_attributes Raw aria attributes from block attributes
18
+ * @param string $block_name Block name without 'tds/' prefix (e.g., 'button', 'chip')
19
+ * @param array $attributes Full block attributes array (for filter context)
20
+ *
21
+ * @return array Sanitized and validated aria attributes ready for HTML output
22
+ *
23
+ * @example
24
+ * // In render.php:
25
+ * $sanitized_aria_attributes = tds_sanitize_aria_attributes(
26
+ * $attributes['ariaAttributes'] ?? [],
27
+ * 'button',
28
+ * $attributes
29
+ * );
30
+ *
31
+ * $aria_attrs_html = '';
32
+ * foreach ($sanitized_aria_attributes as $key => $value) {
33
+ * $aria_attrs_html .= ' ' . esc_attr($key) . '="' . esc_attr($value) . '"';
34
+ * }
35
+ *
36
+ * // Then in HTML:
37
+ * // <button <?php echo $aria_attrs_html; ?>>...</button>
38
+ */
39
+ function tds_sanitize_aria_attributes($aria_attributes, $block_name, $attributes = []) {
40
+ // Validate inputs
41
+ if (!is_array($aria_attributes)) {
42
+ return [];
43
+ }
44
+
45
+ if (!is_string($block_name)) {
46
+ return [];
47
+ }
48
+
49
+ if (!is_array($attributes)) {
50
+ $attributes = [];
51
+ }
52
+
53
+ // Get allowed aria attribute keys from filter
54
+ $allowed_aria_attribute_keys = apply_filters(
55
+ "tds_{$block_name}_allowed_aria_attributes",
56
+ [],
57
+ $attributes
58
+ );
59
+
60
+ // Ensure it's an array
61
+ if (!is_array($allowed_aria_attribute_keys)) {
62
+ $allowed_aria_attribute_keys = [];
63
+ }
64
+
65
+ // Limits for DoS prevention
66
+ $max_aria_attributes = 10;
67
+ $max_aria_value_length = 200;
68
+ $sanitized_aria_attributes = [];
69
+
70
+ // Regex for valid aria attribute names: aria-*, case-insensitive, allows numbers/hyphens/underscores
71
+ $valid_aria_attr_pattern = '/^aria-[a-z0-9_-]+$/i';
72
+
73
+ foreach ($aria_attributes as $key => $value) {
74
+ // Enforce maximum attribute count
75
+ if (count($sanitized_aria_attributes) >= $max_aria_attributes) {
76
+ break;
77
+ }
78
+
79
+ // Validate key and value are scalar types
80
+ if (!is_string($key) || !is_scalar($value)) {
81
+ continue;
82
+ }
83
+
84
+ // Must start with 'aria-'
85
+ if (strpos($key, 'aria-') !== 0) {
86
+ continue;
87
+ }
88
+
89
+ // Must match valid aria attribute pattern
90
+ if (!preg_match($valid_aria_attr_pattern, $key)) {
91
+ continue;
92
+ }
93
+
94
+ // Must be in allowed list (set via filter)
95
+ if (!in_array($key, $allowed_aria_attribute_keys, true)) {
96
+ continue;
97
+ }
98
+
99
+ // Sanitize and truncate value
100
+ $sanitized_value = sanitize_text_field((string) $value);
101
+ if (strlen($sanitized_value) > $max_aria_value_length) {
102
+ $sanitized_value = substr($sanitized_value, 0, $max_aria_value_length);
103
+ }
104
+
105
+ $sanitized_aria_attributes[$key] = $sanitized_value;
106
+ }
107
+
108
+ return $sanitized_aria_attributes;
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@times-design-system/components-wordpress",
3
- "version": "1.14.0",
3
+ "version": "1.16.1-alpha.0+91f353d4",
4
4
  "type": "module",
5
5
  "description": "Times Design System Gutenberg blocks for WordPress Full Site Editing",
6
6
  "keywords": [
@@ -70,7 +70,7 @@
70
70
  "access": "public"
71
71
  },
72
72
  "dependencies": {
73
- "@times-design-system/theme-scss": "^2.9.0",
73
+ "@times-design-system/theme-scss": "^2.10.2-alpha.0+91f353d4",
74
74
  "@wordpress/block-editor": "^12.0.0",
75
75
  "@wordpress/blocks": "^12.0.0",
76
76
  "@wordpress/components": "^25.0.0",
@@ -88,7 +88,7 @@
88
88
  "@testing-library/jest-dom": "^6.1.5",
89
89
  "@testing-library/react": "^14.1.2",
90
90
  "@testing-library/user-event": "^14.5.1",
91
- "@times-design-system/icons": "^1.2.0",
91
+ "@times-design-system/icons": "^1.2.2-alpha.0+91f353d4",
92
92
  "@types/react": "19.2.5",
93
93
  "@vitest/ui": "^1.0.4",
94
94
  "jsdom": "^23.0.0",
@@ -101,5 +101,5 @@
101
101
  "typescript": "^5.0.0",
102
102
  "vitest": "^1.0.4"
103
103
  },
104
- "gitHead": "4546787f4cf8edb08cd9f63f6905b6e2182edda8"
104
+ "gitHead": "91f353d41d06d1066d2345a933d6e9b58ae54a1d"
105
105
  }
package/plugin.php CHANGED
@@ -40,6 +40,7 @@ function tds_register_block_styles() {
40
40
  'icon-button' => 'tds-icon-button-style',
41
41
  'input' => 'tds-input-style',
42
42
  'input-helper-message' => 'tds-input-helper-message-style',
43
+ 'label' => 'tds-label-style',
43
44
  'link' => 'tds-link-style',
44
45
  'tab' => 'tds-tab-style',
45
46
  'tab-group' => 'tds-tab-group-style',
@@ -1,106 +0,0 @@
1
- <?php
2
- /**
3
- * Icon Rendering Utility
4
- *
5
- * Renders icon SVG markup from icon names.
6
- *
7
- * @package TimesDesignSystem\ComponentsWordPress
8
- */
9
-
10
- if (!function_exists('tds_resolve_icon_size')) {
11
- /**
12
- * Size map matching React Icon component
13
- * Maps named sizes to pixel dimensions
14
- */
15
- $icon_size_map = [
16
- '2xsmall' => ['width' => 12, 'height' => 12],
17
- 'xsmall' => ['width' => 16, 'height' => 16],
18
- 'small' => ['width' => 20, 'height' => 20],
19
- 'medium' => ['width' => 24, 'height' => 24],
20
- 'large' => ['width' => 28, 'height' => 28],
21
- 'xlarge' => ['width' => 32, 'height' => 32],
22
- '2xlarge' => ['width' => 40, 'height' => 40],
23
- ];
24
-
25
- /**
26
- * Resolve size to width and height dimensions
27
- *
28
- * @param mixed $size Named size string ('small', 'medium', etc) or numeric pixel value
29
- * @return array Array with 'width' and 'height' keys
30
- */
31
- function tds_resolve_icon_size($size) {
32
- $size_map = [
33
- '2xsmall' => ['width' => 12, 'height' => 12],
34
- 'xsmall' => ['width' => 16, 'height' => 16],
35
- 'small' => ['width' => 20, 'height' => 20],
36
- 'medium' => ['width' => 24, 'height' => 24],
37
- 'large' => ['width' => 28, 'height' => 28],
38
- 'xlarge' => ['width' => 32, 'height' => 32],
39
- '2xlarge' => ['width' => 40, 'height' => 40],
40
- ];
41
-
42
- if (is_numeric($size)) {
43
- // Numeric size: return as both width and height
44
- $pixels = (int) $size;
45
- return ['width' => $pixels, 'height' => $pixels];
46
- }
47
-
48
- // Named size: look up in size map
49
- if (isset($size_map[$size])) {
50
- return $size_map[$size];
51
- }
52
-
53
- // Default to medium if unrecognized
54
- return $size_map['medium'];
55
- }
56
- }
57
-
58
- if (!function_exists('tds_render_icon')) {
59
- /**
60
- * Render an icon by name with size and variant support
61
- *
62
- * @param string $icon Icon identifier (e.g., 'filled_search', 'outline_close')
63
- * @param mixed $size Icon size: named string ('small', 'medium', 'large') or numeric pixels
64
- * @return string SVG markup for the icon
65
- */
66
- function tds_render_icon($icon, $size = 'medium') {
67
- if (!$icon) {
68
- return '';
69
- }
70
-
71
- // Sanitize icon name
72
- $icon = sanitize_text_field($icon);
73
-
74
- // Resolve size to dimensions
75
- $dimensions = tds_resolve_icon_size($size);
76
- $width = $dimensions['width'];
77
- $height = $dimensions['height'];
78
-
79
- // Build SVG class list
80
- $classes = ['tds-icon'];
81
- // Add size class if it's a named size
82
- $size_map = [
83
- '2xsmall' => true,
84
- 'xsmall' => true,
85
- 'small' => true,
86
- 'medium' => true,
87
- 'large' => true,
88
- 'xlarge' => true,
89
- '2xlarge' => true,
90
- ];
91
- if (is_string($size) && isset($size_map[$size])) {
92
- $classes[] = 'tds-icon--' . sanitize_text_field($size);
93
- }
94
-
95
- // Return SVG with width/height attributes
96
- // In production, this would use an actual icon library
97
- // For static preview purposes, return a simple SVG placeholder
98
- return sprintf(
99
- '<svg class="%s" width="%d" height="%d" aria-hidden="true"><use href="#icon-%s"></use></svg>',
100
- esc_attr(implode(' ', $classes)),
101
- (int) $width,
102
- (int) $height,
103
- esc_attr($icon)
104
- );
105
- }
106
- }
@@ -1,37 +0,0 @@
1
- <?php
2
- /**
3
- * Data Attributes Sanitization Utility
4
- *
5
- * Sanitizes and prepares data-* attributes for blocks.
6
- *
7
- * @package TimesDesignSystem\ComponentsWordPress
8
- */
9
-
10
- if (!function_exists('tds_sanitize_data_attributes')) {
11
- /**
12
- * Sanitize data-* attributes for a block
13
- *
14
- * @param array $attributes Data attributes to sanitize
15
- * @param string $block_name Name of the block
16
- * @param array $full_attributes Full block attributes array
17
- * @return array Sanitized data attributes
18
- */
19
- function tds_sanitize_data_attributes($attributes = [], $block_name = '', $full_attributes = []) {
20
- if (!is_array($attributes)) {
21
- return [];
22
- }
23
-
24
- $sanitized = [];
25
- foreach ($attributes as $key => $value) {
26
- // Sanitize the key and value
27
- $safe_key = 'data-' . sanitize_html_class($key);
28
- $safe_value = sanitize_text_field($value);
29
-
30
- if ($safe_key && $safe_value) {
31
- $sanitized[$safe_key] = $safe_value;
32
- }
33
- }
34
-
35
- return $sanitized;
36
- }
37
- }