@aiaiai-pt/design-system 0.55.1 → 0.56.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.
@@ -45,6 +45,7 @@
45
45
  isRelationshipParam,
46
46
  normalizeRelIds,
47
47
  relationshipTypeCode,
48
+ relationshipDisplayName,
48
49
  } from "./action-form-renderer-relationships";
49
50
  // #36/#37 — widget-first dispatch (field summaries carry render intent in
50
51
  // `widget`; derived-action params in `ui_schema.widget`; legacy params fall
@@ -141,6 +142,12 @@
141
142
  * in submit modes. */
142
143
  captcha?: Snippet;
143
144
  submitLabel?: string;
145
+ /** Consumer-provided placeholder builder for relationship pickers.
146
+ * Receives the target type's display name (or type code as fallback);
147
+ * returns the full placeholder string. The consumer owns the translation
148
+ * (e.g. `(name) => t('Search {0}...', name)`); the DS provides the
149
+ * English default. Consistent with the `submitLabel` pattern. */
150
+ searchPlaceholder?: (displayName: string) => string;
144
151
  /** Forwarded VERBATIM to every `geo` parameter's MapPicker (the renderer
145
152
  * stays generic — boundary/overlay semantics live in the consumer):
146
153
  * `boundary` draws the dashed tenant-boundary overlay and arms the
@@ -185,6 +192,7 @@
185
192
  fieldErrors = undefined,
186
193
  captcha = undefined,
187
194
  submitLabel = "Submit",
195
+ searchPlaceholder = (name: string) => name ? `Search ${name}...` : "Search...",
188
196
  boundary = undefined,
189
197
  layers = [],
190
198
  onoutofbounds = undefined,
@@ -907,9 +915,7 @@
907
915
  value: id,
908
916
  label: relLabel(key, id),
909
917
  }))}
910
- placeholder={relationshipTypeCode(parameter)
911
- ? `Search ${relationshipTypeCode(parameter)}...`
912
- : "Search..."}
918
+ placeholder={searchPlaceholder(relationshipDisplayName(parameter))}
913
919
  disabled={!searchEntities || !editable || fieldDisabled}
914
920
  loading={(referenceLoading[key] ?? false) || parameter.loading === true}
915
921
  error={fieldError}
@@ -922,9 +928,7 @@
922
928
  label={String(parameter.label ?? key)}
923
929
  items={relComboItems(parameter)}
924
930
  value={String(values[key] ?? "")}
925
- placeholder={relationshipTypeCode(parameter)
926
- ? `Search ${relationshipTypeCode(parameter)}...`
927
- : "Search..."}
931
+ placeholder={searchPlaceholder(relationshipDisplayName(parameter))}
928
932
  disabled={!searchEntities || !editable || fieldDisabled}
929
933
  loading={(referenceLoading[key] ?? false) || parameter.loading === true}
930
934
  error={fieldError}
@@ -84,6 +84,12 @@ interface Props {
84
84
  * in submit modes. */
85
85
  captcha?: Snippet;
86
86
  submitLabel?: string;
87
+ /** Consumer-provided placeholder builder for relationship pickers.
88
+ * Receives the target type's display name (or type code as fallback);
89
+ * returns the full placeholder string. The consumer owns the translation
90
+ * (e.g. `(name) => t('Search {0}...', name)`); the DS provides the
91
+ * English default. Consistent with the `submitLabel` pattern. */
92
+ searchPlaceholder?: (displayName: string) => string;
87
93
  /** Forwarded VERBATIM to every `geo` parameter's MapPicker (the renderer
88
94
  * stays generic — boundary/overlay semantics live in the consumer):
89
95
  * `boundary` draws the dashed tenant-boundary overlay and arms the
@@ -46,14 +46,21 @@
46
46
  let typeaheadBuffer = $state('');
47
47
  let typeaheadTimer = $state(0);
48
48
 
49
+ /** Every WAI-ARIA menu item role: plain, radio and checkbox items. */
50
+ const ITEM_ROLES = ['menuitem', 'menuitemradio', 'menuitemcheckbox'];
51
+ const ITEM_SELECTOR = ITEM_ROLES.map((r) => `[role="${r}"]`).join(', ');
52
+
49
53
  /**
50
- * Get all enabled menu items inside the menu container.
54
+ * Get all enabled menu items (any item role) inside the menu container.
55
+ * Skips items that are aria-disabled or natively :disabled.
51
56
  * @returns {HTMLElement[]}
52
57
  */
53
58
  function getItems() {
54
59
  if (!menuEl) return [];
55
60
  return /** @type {HTMLElement[]} */ (
56
- Array.from(menuEl.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])'))
61
+ Array.from(menuEl.querySelectorAll(ITEM_SELECTOR)).filter(
62
+ (el) => !el.matches(':disabled, [aria-disabled="true"]')
63
+ )
57
64
  );
58
65
  }
59
66
 
@@ -101,7 +108,7 @@
101
108
  case 'Enter':
102
109
  case ' ': {
103
110
  e.preventDefault();
104
- if (current && current.getAttribute('role') === 'menuitem') {
111
+ if (current && ITEM_ROLES.includes(current.getAttribute('role') ?? '')) {
105
112
  current.click();
106
113
  }
107
114
  break;
@@ -3,6 +3,8 @@
3
3
 
4
4
  A single actionable row inside a Menu.
5
5
  Renders as <button role="menuitem"> with optional leading/trailing snippets.
6
+ Set role="menuitemradio" or role="menuitemcheckbox" with `checked` for
7
+ selectable items; aria-checked is rendered only for those two roles.
6
8
 
7
9
  Consumes --menu-item-* tokens from components.css.
8
10
 
@@ -18,6 +20,11 @@
18
20
  Delete
19
21
  </MenuItem>
20
22
 
23
+ @example Radio item
24
+ <MenuItem role="menuitemradio" checked={sort === 'name'} onclick={() => (sort = 'name')}>
25
+ Sort by name
26
+ </MenuItem>
27
+
21
28
  @example With keyboard shortcut
22
29
  <MenuItem onclick={handleCopy}>
23
30
  Copy
@@ -25,9 +32,29 @@
25
32
  </MenuItem>
26
33
  -->
27
34
  <script>
35
+ /**
36
+ * @typedef {'menuitem' | 'menuitemradio' | 'menuitemcheckbox'} MenuItemRole
37
+ * @typedef {{
38
+ * variant?: string,
39
+ * role?: MenuItemRole,
40
+ * checked?: boolean,
41
+ * disabled?: boolean,
42
+ * leading?: import('svelte').Snippet,
43
+ * trailing?: import('svelte').Snippet,
44
+ * children?: import('svelte').Snippet,
45
+ * class?: string,
46
+ * [key: string]: unknown,
47
+ * }} Props
48
+ */
49
+
50
+ /** @type {Props} */
28
51
  let {
29
52
  /** @type {'default' | 'destructive'} */
30
53
  variant = 'default',
54
+ /** @type {MenuItemRole} */
55
+ role = 'menuitem',
56
+ /** Checked state; rendered as aria-checked only for menuitemradio/menuitemcheckbox. @type {boolean} */
57
+ checked = false,
31
58
  /** @type {boolean} */
32
59
  disabled = false,
33
60
  /** @type {import('svelte').Snippet | undefined} */
@@ -40,10 +67,15 @@
40
67
  class: className = '',
41
68
  ...rest
42
69
  } = $props();
70
+
71
+ const ariaChecked = $derived(
72
+ role === 'menuitemradio' || role === 'menuitemcheckbox' ? (checked ? 'true' : 'false') : undefined
73
+ );
43
74
  </script>
44
75
 
45
76
  <button
46
- role="menuitem"
77
+ {role}
78
+ aria-checked={ariaChecked}
47
79
  class="menu-item menu-item-{variant} {className}"
48
80
  class:menu-item-disabled={disabled}
49
81
  disabled={disabled || undefined}
@@ -1,13 +1,15 @@
1
1
  export default MenuItem;
2
2
  type MenuItem = {
3
3
  $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<$$ComponentProps>): void;
4
+ $set?(props: Partial<Props>): void;
5
5
  };
6
6
  /**
7
7
  * MenuItem
8
8
  *
9
9
  * A single actionable row inside a Menu.
10
10
  * Renders as <button role="menuitem"> with optional leading/trailing snippets.
11
+ * Set role="menuitemradio" or role="menuitemcheckbox" with `checked` for
12
+ * selectable items; aria-checked is rendered only for those two roles.
11
13
  *
12
14
  * Consumes --menu-item-* tokens from components.css.
13
15
  *
@@ -23,6 +25,11 @@ type MenuItem = {
23
25
  * Delete
24
26
  * </MenuItem>
25
27
  *
28
+ * @example Radio item
29
+ * <MenuItem role="menuitemradio" checked={sort === 'name'} onclick={() => (sort = 'name')}>
30
+ * Sort by name
31
+ * </MenuItem>
32
+ *
26
33
  * @example With keyboard shortcut
27
34
  * <MenuItem onclick={handleCopy}>
28
35
  * Copy
@@ -30,18 +37,24 @@ type MenuItem = {
30
37
  * </MenuItem>
31
38
  */
32
39
  declare const MenuItem: import("svelte").Component<{
40
+ [key: string]: unknown;
33
41
  variant?: string;
42
+ role?: "menuitem" | "menuitemradio" | "menuitemcheckbox";
43
+ checked?: boolean;
34
44
  disabled?: boolean;
35
- leading?: any;
36
- trailing?: any;
37
- children?: any;
45
+ leading?: import("svelte").Snippet;
46
+ trailing?: import("svelte").Snippet;
47
+ children?: import("svelte").Snippet;
38
48
  class?: string;
39
- } & Record<string, any>, {}, "">;
40
- type $$ComponentProps = {
49
+ }, {}, "">;
50
+ type Props = {
41
51
  variant?: string;
52
+ role?: "menuitem" | "menuitemradio" | "menuitemcheckbox";
53
+ checked?: boolean;
42
54
  disabled?: boolean;
43
- leading?: any;
44
- trailing?: any;
45
- children?: any;
55
+ leading?: import("svelte").Snippet;
56
+ trailing?: import("svelte").Snippet;
57
+ children?: import("svelte").Snippet;
46
58
  class?: string;
47
- } & Record<string, any>;
59
+ [key: string]: unknown;
60
+ };
@@ -99,11 +99,15 @@
99
99
  /** @type {HTMLElement | null} */
100
100
  const previouslyFocused = /** @type {HTMLElement | null} */ (document.activeElement);
101
101
 
102
- // Focus first focusable child
102
+ // Focus the first focusable child that is enabled (not :disabled and not
103
+ // aria-disabled). With none, leave focus where it is.
103
104
  requestAnimationFrame(() => {
104
- const focusable = popoverEl?.querySelector(
105
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
106
- );
105
+ if (!popoverEl) return;
106
+ const focusable = Array.from(
107
+ popoverEl.querySelectorAll(
108
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
109
+ )
110
+ ).find((el) => !el.matches(':disabled, [aria-disabled="true"]'));
107
111
  if (focusable) /** @type {HTMLElement} */ (focusable).focus();
108
112
  });
109
113
 
@@ -1,6 +1,11 @@
1
1
  export type RelationshipMeta = {
2
2
  relCode?: string;
3
3
  targetTypeCode: string;
4
+ /** Human display name for the target type (e.g. "Pessoa Vulneravel" instead
5
+ * of "vulnerable_person"). Consumers pass it from the ontology schema; the
6
+ * renderer prefers it for the picker placeholder. Falls back to
7
+ * `targetTypeCode` when absent (backward-compatible). */
8
+ targetDisplayName?: string;
4
9
  cardinality?: string;
5
10
  };
6
11
  type Entity = Record<string, unknown>;
@@ -15,6 +20,11 @@ export declare function isRelationshipParam(parameter: Entity): boolean;
15
20
  export declare function isMultiRelationship(parameter: Entity): boolean;
16
21
  /** The entity type code the picker searches/hydrates against. */
17
22
  export declare function relationshipTypeCode(parameter: Entity): string;
23
+ /** Human display name for the relationship target, for use in the picker
24
+ * placeholder. Prefers `targetDisplayName` from the relationship metadata
25
+ * (populated by the consumer from the ontology schema); falls back to the
26
+ * raw type code so existing consumers without the display name are unchanged. */
27
+ export declare function relationshipDisplayName(parameter: Entity): string;
18
28
  /** Normalize a rel value-bag entry onto the ID-list wire shape. */
19
29
  export declare function normalizeRelIds(value: unknown): string[];
20
30
  export {};
@@ -10,6 +10,11 @@
10
10
  export type RelationshipMeta = {
11
11
  relCode?: string;
12
12
  targetTypeCode: string;
13
+ /** Human display name for the target type (e.g. "Pessoa Vulneravel" instead
14
+ * of "vulnerable_person"). Consumers pass it from the ontology schema; the
15
+ * renderer prefers it for the picker placeholder. Falls back to
16
+ * `targetTypeCode` when absent (backward-compatible). */
17
+ targetDisplayName?: string;
13
18
  cardinality?: string;
14
19
  };
15
20
 
@@ -34,9 +39,14 @@ export function relationshipMeta(parameter: Entity): RelationshipMeta | null {
34
39
  if (!targetTypeCode) return null;
35
40
  const relCode = carrier.relCode ?? carrier.rel_code;
36
41
  const cardinality = carrier.cardinality;
42
+ const targetDisplayName =
43
+ carrier.targetDisplayName ?? carrier.target_display_name;
37
44
  return {
38
45
  relCode: relCode ? String(relCode) : undefined,
39
46
  targetTypeCode,
47
+ ...(targetDisplayName
48
+ ? { targetDisplayName: String(targetDisplayName) }
49
+ : {}),
40
50
  cardinality: cardinality ? String(cardinality) : undefined,
41
51
  };
42
52
  }
@@ -67,6 +77,19 @@ export function relationshipTypeCode(parameter: Entity): string {
67
77
  );
68
78
  }
69
79
 
80
+ /** Human display name for the relationship target, for use in the picker
81
+ * placeholder. Prefers `targetDisplayName` from the relationship metadata
82
+ * (populated by the consumer from the ontology schema); falls back to the
83
+ * raw type code so existing consumers without the display name are unchanged. */
84
+ export function relationshipDisplayName(parameter: Entity): string {
85
+ const meta = relationshipMeta(parameter);
86
+ return (
87
+ meta?.targetDisplayName ??
88
+ meta?.targetTypeCode ??
89
+ String(parameter.object_type ?? "")
90
+ );
91
+ }
92
+
70
93
  /** Normalize a rel value-bag entry onto the ID-list wire shape. */
71
94
  export function normalizeRelIds(value: unknown): string[] {
72
95
  if (Array.isArray(value)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.55.1",
3
+ "version": "0.56.0",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",