@caribeng/ui 22.2.0 → 22.4.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 (121) hide show
  1. package/README.md +93 -11
  2. package/fesm2022/caribeng-ui-accordion.mjs +2 -2
  3. package/fesm2022/caribeng-ui-avatar.mjs +2 -2
  4. package/fesm2022/caribeng-ui-badge.mjs +8 -2
  5. package/fesm2022/caribeng-ui-breadcrumb.mjs +13 -6
  6. package/fesm2022/caribeng-ui-chart.mjs +8 -5
  7. package/fesm2022/caribeng-ui-chat.mjs +1303 -0
  8. package/fesm2022/caribeng-ui-code-block.mjs +332 -0
  9. package/fesm2022/caribeng-ui-colorpicker.mjs +99 -5
  10. package/fesm2022/caribeng-ui-command-palette.mjs +476 -0
  11. package/fesm2022/caribeng-ui-confirmdialog.mjs +78 -13
  12. package/fesm2022/caribeng-ui-confirmpopup.mjs +91 -16
  13. package/fesm2022/caribeng-ui-contextmenu.mjs +8 -4
  14. package/fesm2022/caribeng-ui-copy-button.mjs +230 -0
  15. package/fesm2022/caribeng-ui-dataview.mjs +4 -1
  16. package/fesm2022/caribeng-ui-dock.mjs +52 -12
  17. package/fesm2022/caribeng-ui-drawer.mjs +9 -4
  18. package/fesm2022/caribeng-ui-editor.mjs +21 -0
  19. package/fesm2022/caribeng-ui-fieldset.mjs +2 -2
  20. package/fesm2022/caribeng-ui-file-card.mjs +134 -17
  21. package/fesm2022/caribeng-ui-folder-card.mjs +122 -12
  22. package/fesm2022/caribeng-ui-inlinemessage.mjs +2 -2
  23. package/fesm2022/caribeng-ui-inputmask.mjs +8 -2
  24. package/fesm2022/caribeng-ui-kanban.mjs +4612 -0
  25. package/fesm2022/caribeng-ui-kbd.mjs +122 -0
  26. package/fesm2022/caribeng-ui-megamenu.mjs +13 -9
  27. package/fesm2022/caribeng-ui-mentions.mjs +495 -0
  28. package/fesm2022/caribeng-ui-menu.mjs +8 -4
  29. package/fesm2022/caribeng-ui-menubar.mjs +9 -5
  30. package/fesm2022/caribeng-ui-message.mjs +6 -3
  31. package/fesm2022/caribeng-ui-organizationchart.mjs +6 -10
  32. package/fesm2022/caribeng-ui-panel.mjs +6 -6
  33. package/fesm2022/caribeng-ui-panelmenu.mjs +9 -6
  34. package/fesm2022/caribeng-ui-phone-input.mjs +688 -0
  35. package/fesm2022/caribeng-ui-pricing.mjs +263 -69
  36. package/fesm2022/caribeng-ui-qrcode.mjs +564 -0
  37. package/fesm2022/caribeng-ui-ripple.mjs +2 -0
  38. package/fesm2022/caribeng-ui-scrolltop.mjs +3 -1
  39. package/fesm2022/caribeng-ui-sidebar.mjs +573 -0
  40. package/fesm2022/caribeng-ui-stepper.mjs +10 -3
  41. package/fesm2022/caribeng-ui-table.mjs +10 -4
  42. package/fesm2022/caribeng-ui-tabmenu.mjs +8 -4
  43. package/fesm2022/caribeng-ui-tieredmenu.mjs +109 -19
  44. package/fesm2022/caribeng-ui.mjs +388 -1
  45. package/package.json +42 -2
  46. package/schematics/collection.json +5 -0
  47. package/schematics/migrate-from-primeng/core-icons.json +1 -0
  48. package/schematics/migrate-from-primeng/icons.js +269 -0
  49. package/schematics/migrate-from-primeng/index.js +290 -0
  50. package/schematics/migrate-from-primeng/mappings/button.js +93 -0
  51. package/schematics/migrate-from-primeng/mappings/card.js +33 -0
  52. package/schematics/migrate-from-primeng/mappings/checkbox.js +44 -0
  53. package/schematics/migrate-from-primeng/mappings/confirm.js +221 -0
  54. package/schematics/migrate-from-primeng/mappings/datepicker.js +121 -0
  55. package/schematics/migrate-from-primeng/mappings/dialog.js +84 -0
  56. package/schematics/migrate-from-primeng/mappings/index.js +88 -0
  57. package/schematics/migrate-from-primeng/mappings/inputnumber.js +62 -0
  58. package/schematics/migrate-from-primeng/mappings/inputtext.js +60 -0
  59. package/schematics/migrate-from-primeng/mappings/menu.js +468 -0
  60. package/schematics/migrate-from-primeng/mappings/multiselect.js +49 -0
  61. package/schematics/migrate-from-primeng/mappings/radiobutton.js +22 -0
  62. package/schematics/migrate-from-primeng/mappings/rules.js +206 -0
  63. package/schematics/migrate-from-primeng/mappings/select.js +97 -0
  64. package/schematics/migrate-from-primeng/mappings/service-calls.js +100 -0
  65. package/schematics/migrate-from-primeng/mappings/table.js +613 -0
  66. package/schematics/migrate-from-primeng/mappings/tabs.js +225 -0
  67. package/schematics/migrate-from-primeng/mappings/tag.js +29 -0
  68. package/schematics/migrate-from-primeng/mappings/textarea.js +44 -0
  69. package/schematics/migrate-from-primeng/mappings/toast.js +173 -0
  70. package/schematics/migrate-from-primeng/mappings/toggleswitch.js +37 -0
  71. package/schematics/migrate-from-primeng/mappings/tooltip.js +44 -0
  72. package/schematics/migrate-from-primeng/mappings/types.js +10 -0
  73. package/schematics/migrate-from-primeng/report.js +79 -0
  74. package/schematics/migrate-from-primeng/schema.js +2 -0
  75. package/schematics/migrate-from-primeng/schema.json +34 -0
  76. package/schematics/migrate-from-primeng/template.js +387 -0
  77. package/schematics/migrate-from-primeng/todo.js +5 -0
  78. package/schematics/migrate-from-primeng/typescript.js +442 -0
  79. package/schematics/migrate-from-primeng/workspace.js +117 -0
  80. package/schematics/ng-add/index.js +16 -1
  81. package/types/caribeng-ui-badge.d.ts +3 -1
  82. package/types/caribeng-ui-breadcrumb.d.ts +8 -0
  83. package/types/caribeng-ui-chart.d.ts +3 -1
  84. package/types/caribeng-ui-chat.d.ts +299 -0
  85. package/types/caribeng-ui-code-block.d.ts +65 -0
  86. package/types/caribeng-ui-colorpicker.d.ts +5 -1
  87. package/types/caribeng-ui-command-palette.d.ts +133 -0
  88. package/types/caribeng-ui-confirmdialog.d.ts +34 -2
  89. package/types/caribeng-ui-confirmpopup.d.ts +39 -2
  90. package/types/caribeng-ui-contextmenu.d.ts +7 -0
  91. package/types/caribeng-ui-copy-button.d.ts +90 -0
  92. package/types/caribeng-ui-dataview.d.ts +2 -0
  93. package/types/caribeng-ui-dock.d.ts +13 -1
  94. package/types/caribeng-ui-drawer.d.ts +3 -1
  95. package/types/caribeng-ui-file-card.d.ts +27 -2
  96. package/types/caribeng-ui-folder-card.d.ts +27 -5
  97. package/types/caribeng-ui-inputmask.d.ts +3 -1
  98. package/types/caribeng-ui-kanban.d.ts +783 -0
  99. package/types/caribeng-ui-kbd.d.ts +36 -0
  100. package/types/caribeng-ui-megamenu.d.ts +11 -0
  101. package/types/caribeng-ui-mentions.d.ts +127 -0
  102. package/types/caribeng-ui-menu.d.ts +7 -0
  103. package/types/caribeng-ui-menubar.d.ts +7 -0
  104. package/types/caribeng-ui-message.d.ts +2 -0
  105. package/types/caribeng-ui-panelmenu.d.ts +7 -0
  106. package/types/caribeng-ui-phone-input.d.ts +168 -0
  107. package/types/caribeng-ui-pricing.d.ts +41 -4
  108. package/types/caribeng-ui-qrcode.d.ts +88 -0
  109. package/types/caribeng-ui-sidebar.d.ts +167 -0
  110. package/types/caribeng-ui-stepper.d.ts +2 -0
  111. package/types/caribeng-ui-table.d.ts +1 -1
  112. package/types/caribeng-ui-tabmenu.d.ts +7 -0
  113. package/types/caribeng-ui-tieredmenu.d.ts +17 -1
  114. package/types/caribeng-ui.d.ts +276 -2
  115. package/styles/caribeng.css +0 -380
  116. package/styles/scss/_mixins.scss +0 -46
  117. package/styles/scss/_overlay.scss +0 -15
  118. package/styles/scss/_tokens.scss +0 -267
  119. package/styles/scss/_utilities.scss +0 -73
  120. package/styles/scss/_variables.scss +0 -33
  121. package/styles/scss/index.scss +0 -16
@@ -0,0 +1,495 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, ViewContainerRef, Injector, viewChild, model, input, booleanAttribute, output, signal, computed, afterNextRender, forwardRef, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
+ import { Overlay } from '@angular/cdk/overlay';
5
+ import { TemplatePortal } from '@angular/cdk/portal';
6
+ import { injectCbTranslation, cbFieldState, cbFormat } from '@caribeng/ui';
7
+
8
+ /** Propiedades que afectan a cómo se reparte el texto en líneas. */
9
+ const MIRRORED = [
10
+ 'boxSizing',
11
+ 'width',
12
+ 'height',
13
+ 'overflowX',
14
+ 'overflowY',
15
+ 'borderTopWidth',
16
+ 'borderRightWidth',
17
+ 'borderBottomWidth',
18
+ 'borderLeftWidth',
19
+ 'paddingTop',
20
+ 'paddingRight',
21
+ 'paddingBottom',
22
+ 'paddingLeft',
23
+ 'fontStyle',
24
+ 'fontVariant',
25
+ 'fontWeight',
26
+ 'fontStretch',
27
+ 'fontSize',
28
+ 'lineHeight',
29
+ 'fontFamily',
30
+ 'textAlign',
31
+ 'textTransform',
32
+ 'textIndent',
33
+ 'letterSpacing',
34
+ 'wordSpacing',
35
+ 'tabSize',
36
+ ];
37
+ /**
38
+ * Posición (px, relativa al campo) del carácter `index` de un textarea o
39
+ * input, con un div espejo invisible que copia su tipografía y su ancho.
40
+ * Sirve para abrir el panel de sugerencias justo bajo lo que se escribe.
41
+ */
42
+ function cbCaretCoordinates(field, index) {
43
+ const doc = field.ownerDocument;
44
+ const style = doc.defaultView?.getComputedStyle(field);
45
+ const mirror = doc.createElement('div');
46
+ const isInput = field.nodeName === 'INPUT';
47
+ mirror.style.position = 'absolute';
48
+ mirror.style.visibility = 'hidden';
49
+ mirror.style.top = '0';
50
+ mirror.style.left = '-9999px';
51
+ mirror.style.whiteSpace = isInput ? 'nowrap' : 'pre-wrap';
52
+ mirror.style.overflowWrap = 'break-word';
53
+ if (style)
54
+ for (const prop of MIRRORED)
55
+ mirror.style[prop] = style[prop];
56
+ mirror.textContent = field.value.slice(0, index);
57
+ const marker = doc.createElement('span');
58
+ marker.textContent = field.value.slice(index) || '.';
59
+ mirror.appendChild(marker);
60
+ doc.body.appendChild(mirror);
61
+ const lineHeight = parseFloat(style?.lineHeight ?? '') || parseFloat(style?.fontSize ?? '') * 1.2 || 18;
62
+ const result = {
63
+ top: marker.offsetTop + (parseFloat(style?.borderTopWidth ?? '') || 0) - field.scrollTop,
64
+ left: marker.offsetLeft + (parseFloat(style?.borderLeftWidth ?? '') || 0) - field.scrollLeft,
65
+ height: lineHeight,
66
+ };
67
+ mirror.remove();
68
+ return result;
69
+ }
70
+
71
+ let nextUid = 0;
72
+ const normalize = (text) => text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
73
+ /**
74
+ * Campo de texto con menciones de CaribeNG: al escribir `@` (u otro
75
+ * disparador como `#`) muestra sugerencias junto al cursor, que se filtran
76
+ * sin tildes y se eligen con el teclado o el ratón. Funciona con Angular Forms
77
+ * (el valor es el texto) y emite las menciones presentes con su `id`.
78
+ *
79
+ * @example
80
+ * ```html
81
+ * <cb-mentions label="Comentario" [suggestions]="equipo" formControlName="comentario" (mentionsChange)="menciones = $event" />
82
+ * ```
83
+ */
84
+ class CbMentions {
85
+ constructor() {
86
+ /** Textos de interfaz en el idioma activo (`provideCaribeNG({ locale })`). */
87
+ this.t = injectCbTranslation();
88
+ this.overlay = inject(Overlay);
89
+ this.vcr = inject(ViewContainerRef);
90
+ this.injector = inject(Injector);
91
+ this.fieldEl = viewChild.required('field');
92
+ this.panelTpl = viewChild.required('panel');
93
+ this.overlayRef = null;
94
+ this.inputId = `cb-mentions-${++nextUid}`;
95
+ this.listId = `${this.inputId}-list`;
96
+ /** Texto (bidireccional y con Angular Forms). */
97
+ this.value = model('', /* @ts-ignore */
98
+ ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
99
+ /** Elementos mencionables. Cada uno puede indicar su `trigger`. */
100
+ this.suggestions = input([], /* @ts-ignore */
101
+ ...(ngDevMode ? [{ debugName: "suggestions" }] : /* istanbul ignore next */ []));
102
+ /** Caracteres que abren las sugerencias. */
103
+ this.triggers = input(['@'], /* @ts-ignore */
104
+ ...(ngDevMode ? [{ debugName: "triggers" }] : /* istanbul ignore next */ []));
105
+ /** Filtra `suggestions` con lo escrito. Desactívalo si llegan ya filtradas del servidor. */
106
+ this.filter = input(true, { ...(ngDevMode ? { debugName: "filter" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
107
+ /** Máximo de sugerencias visibles. */
108
+ this.maxResults = input(8, /* @ts-ignore */
109
+ ...(ngDevMode ? [{ debugName: "maxResults" }] : /* istanbul ignore next */ []));
110
+ /** Muestra "Cargando" mientras no hay sugerencias. */
111
+ this.loading = input(false, { ...(ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
112
+ this.label = input('', /* @ts-ignore */
113
+ ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
114
+ this.hint = input('', /* @ts-ignore */
115
+ ...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
116
+ this.placeholder = input('', /* @ts-ignore */
117
+ ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
118
+ /** Nombre accesible sin `label` visible. */
119
+ this.ariaLabel = input('', /* @ts-ignore */
120
+ ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
121
+ this.rows = input(3, /* @ts-ignore */
122
+ ...(ngDevMode ? [{ debugName: "rows" }] : /* istanbul ignore next */ []));
123
+ this.invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
124
+ this.required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
125
+ this.requiredIndicator = input(undefined, /* @ts-ignore */
126
+ ...(ngDevMode ? [{ debugName: "requiredIndicator" }] : /* istanbul ignore next */ []));
127
+ this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
128
+ /** Lo escrito tras el disparador (para pedir sugerencias). */
129
+ this.search = output();
130
+ /** Menciones presentes en el texto, cada vez que cambian. */
131
+ this.mentionsChange = output();
132
+ this.fieldState = cbFieldState({
133
+ invalid: () => this.invalid(),
134
+ required: () => this.required(),
135
+ requiredIndicator: () => this.requiredIndicator(),
136
+ });
137
+ this.cvaDisabled = signal(false, /* @ts-ignore */
138
+ ...(ngDevMode ? [{ debugName: "cvaDisabled" }] : /* istanbul ignore next */ []));
139
+ this.isDisabled = computed(() => this.disabled() || this.cvaDisabled(), /* @ts-ignore */
140
+ ...(ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []));
141
+ this.query = signal(null, /* @ts-ignore */
142
+ ...(ngDevMode ? [{ debugName: "query" }] : /* istanbul ignore next */ []));
143
+ this.open = signal(false, /* @ts-ignore */
144
+ ...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
145
+ this.active = signal(0, /* @ts-ignore */
146
+ ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
147
+ this.announcement = signal('', /* @ts-ignore */
148
+ ...(ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []));
149
+ /** Menciones elegidas (se conservan mientras su texto siga en el campo). */
150
+ this.chosen = [];
151
+ this.lastMentions = '';
152
+ this.results = computed(() => {
153
+ const q = this.query();
154
+ if (!q)
155
+ return [];
156
+ const items = this.suggestions().filter((s) => (s.trigger ?? '@') === q.trigger);
157
+ if (!this.filter())
158
+ return items.slice(0, this.maxResults());
159
+ const needle = normalize(q.query);
160
+ const scored = items
161
+ .map((item) => {
162
+ const label = normalize(item.label);
163
+ const score = !needle ? 1 : label.startsWith(needle) ? 3 : label.split(/\s+/).some((w) => w.startsWith(needle)) ? 2 : label.includes(needle) ? 1 : 0;
164
+ return { item, score };
165
+ })
166
+ .filter((e) => e.score > 0)
167
+ .sort((a, b) => b.score - a.score);
168
+ return scored.slice(0, this.maxResults()).map((e) => e.item);
169
+ }, /* @ts-ignore */
170
+ ...(ngDevMode ? [{ debugName: "results" }] : /* istanbul ignore next */ []));
171
+ this.activeId = computed(() => (this.results().length ? `${this.listId}-${this.active()}` : null), /* @ts-ignore */
172
+ ...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
173
+ this.onChange = () => { };
174
+ this.onTouched = () => { };
175
+ }
176
+ initials(item) {
177
+ return item.label
178
+ .split(/\s+/)
179
+ .filter(Boolean)
180
+ .slice(0, 2)
181
+ .map((w) => w.charAt(0).toUpperCase())
182
+ .join('');
183
+ }
184
+ // --- ControlValueAccessor ---------------------------------------------------
185
+ writeValue(value) {
186
+ this.value.set(value ?? '');
187
+ this.syncMentions(false);
188
+ }
189
+ registerOnChange(fn) {
190
+ this.onChange = fn;
191
+ }
192
+ registerOnTouched(fn) {
193
+ this.onTouched = fn;
194
+ }
195
+ setDisabledState(isDisabled) {
196
+ this.cvaDisabled.set(isDisabled);
197
+ }
198
+ // --- Escritura ----------------------------------------------------------------
199
+ onInput(event) {
200
+ const text = event.target.value;
201
+ this.value.set(text);
202
+ this.onChange(text);
203
+ this.syncMentions(true);
204
+ this.detect();
205
+ }
206
+ onBlur() {
207
+ this.onTouched();
208
+ this.close();
209
+ }
210
+ /** Busca un disparador justo antes del cursor y abre (o cierra) las sugerencias. */
211
+ detect() {
212
+ const el = this.fieldEl().nativeElement;
213
+ const caret = el.selectionStart ?? el.value.length;
214
+ if (el.selectionEnd !== caret)
215
+ return this.close();
216
+ const before = el.value.slice(0, caret);
217
+ let found = null;
218
+ for (const trigger of this.triggers()) {
219
+ const start = before.lastIndexOf(trigger);
220
+ if (start < 0 || (start > 0 && !/\s|[([{"'¿¡]/.test(before[start - 1])))
221
+ continue;
222
+ const query = before.slice(start + trigger.length);
223
+ // Admite nombres con espacios, pero no saltos de línea ni búsquedas larguísimas.
224
+ if (/\n/.test(query) || query.length > 40 || /\s{2}/.test(query))
225
+ continue;
226
+ if (!found || start > found.start)
227
+ found = { trigger, query, start };
228
+ }
229
+ if (!found)
230
+ return this.close();
231
+ const previous = this.query();
232
+ this.query.set(found);
233
+ if (previous?.query !== found.query || previous.trigger !== found.trigger) {
234
+ this.active.set(0);
235
+ this.search.emit({ trigger: found.trigger, query: found.query });
236
+ }
237
+ // Con un espacio y sin resultados, se entiende que ya no es una mención.
238
+ if (/\s/.test(found.query) && !this.results().length && !this.loading())
239
+ return this.close();
240
+ this.openPanel(found.start);
241
+ this.announcement.set(this.results().length ? cbFormat(this.t().mentionsCount, this.results().length) : this.t().noResults);
242
+ }
243
+ onKeydown(event) {
244
+ if (!this.open())
245
+ return;
246
+ const count = this.results().length;
247
+ switch (event.key) {
248
+ case 'ArrowDown':
249
+ case 'ArrowUp':
250
+ if (!count)
251
+ return;
252
+ event.preventDefault();
253
+ this.active.set((this.active() + (event.key === 'ArrowDown' ? 1 : -1) + count) % count);
254
+ this.scrollActiveIntoView();
255
+ break;
256
+ case 'Enter':
257
+ case 'Tab': {
258
+ const item = this.results()[this.active()];
259
+ if (!item)
260
+ return;
261
+ event.preventDefault();
262
+ this.choose(item);
263
+ break;
264
+ }
265
+ case 'Escape':
266
+ event.preventDefault();
267
+ event.stopPropagation();
268
+ this.close();
269
+ break;
270
+ }
271
+ }
272
+ /** Inserta la mención elegida en lugar de lo escrito tras el disparador. */
273
+ choose(item) {
274
+ const q = this.query();
275
+ const el = this.fieldEl().nativeElement;
276
+ if (!q)
277
+ return;
278
+ const caret = el.selectionStart ?? el.value.length;
279
+ const inserted = `${q.trigger}${item.label} `;
280
+ const text = el.value.slice(0, q.start) + inserted + el.value.slice(caret);
281
+ const position = q.start + inserted.length;
282
+ this.value.set(text);
283
+ el.value = text;
284
+ el.setSelectionRange(position, position);
285
+ this.chosen = [...this.chosen.filter((m) => !(m.id === item.id && m.trigger === q.trigger)), { id: item.id, label: item.label, trigger: q.trigger }];
286
+ this.onChange(text);
287
+ this.close();
288
+ this.syncMentions(true);
289
+ el.focus();
290
+ }
291
+ /** Quita las menciones cuyo texto ya no está y avisa si cambió la lista. */
292
+ syncMentions(emit) {
293
+ const text = this.value();
294
+ this.chosen = this.chosen.filter((m) => text.includes(`${m.trigger}${m.label}`));
295
+ const signature = JSON.stringify(this.chosen.map((m) => `${m.trigger}${m.id}`));
296
+ if (signature === this.lastMentions)
297
+ return;
298
+ this.lastMentions = signature;
299
+ if (emit)
300
+ this.mentionsChange.emit([...this.chosen]);
301
+ }
302
+ // --- Panel ---------------------------------------------------------------------
303
+ openPanel(start) {
304
+ const el = this.fieldEl().nativeElement;
305
+ const rect = el.getBoundingClientRect();
306
+ const caret = cbCaretCoordinates(el, start);
307
+ const origin = { x: rect.left + caret.left, y: rect.top + caret.top + caret.height };
308
+ if (this.overlayRef) {
309
+ this.overlayRef.updatePositionStrategy(this.position(origin));
310
+ return;
311
+ }
312
+ this.overlayRef = this.overlay.create({
313
+ positionStrategy: this.position(origin),
314
+ scrollStrategy: this.overlay.scrollStrategies.reposition(),
315
+ });
316
+ this.overlayRef.attach(new TemplatePortal(this.panelTpl(), this.vcr));
317
+ this.open.set(true);
318
+ }
319
+ position(origin) {
320
+ return this.overlay
321
+ .position()
322
+ .flexibleConnectedTo(origin)
323
+ .withPositions([
324
+ { originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'top', offsetY: 4 },
325
+ { originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -24 },
326
+ ])
327
+ .withPush(true);
328
+ }
329
+ /** Cierra las sugerencias. */
330
+ close() {
331
+ this.query.set(null);
332
+ if (!this.overlayRef)
333
+ return;
334
+ this.overlayRef.dispose();
335
+ this.overlayRef = null;
336
+ this.open.set(false);
337
+ this.announcement.set('');
338
+ }
339
+ scrollActiveIntoView() {
340
+ const id = this.activeId();
341
+ afterNextRender(() => (id ? this.overlayRef?.overlayElement.querySelector(`#${id}`)?.scrollIntoView?.({ block: 'nearest' }) : null), {
342
+ injector: this.injector,
343
+ });
344
+ }
345
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbMentions, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
346
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: CbMentions, isStandalone: true, selector: "cb-mentions", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, suggestions: { classPropertyName: "suggestions", publicName: "suggestions", isSignal: true, isRequired: false, transformFunction: null }, triggers: { classPropertyName: "triggers", publicName: "triggers", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, maxResults: { classPropertyName: "maxResults", publicName: "maxResults", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, rows: { classPropertyName: "rows", publicName: "rows", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, requiredIndicator: { classPropertyName: "requiredIndicator", publicName: "requiredIndicator", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", search: "search", mentionsChange: "mentionsChange" }, host: { classAttribute: "cb-mentions" }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CbMentions), multi: true }], viewQueries: [{ propertyName: "fieldEl", first: true, predicate: ["field"], descendants: true, isSignal: true }, { propertyName: "panelTpl", first: true, predicate: ["panel"], descendants: true, isSignal: true }], ngImport: i0, template: `
347
+ @if (label()) {
348
+ <label class="cb-mentions__label" [attr.for]="inputId">
349
+ {{ label() }}
350
+ @if (fieldState.indicator(); as mark) {
351
+ <span [class]="'cb-mentions__required cb-mentions__required--' + mark.kind" [attr.aria-hidden]="mark.kind === 'optional' ? null : 'true'">{{ mark.text }}</span>
352
+ }
353
+ </label>
354
+ }
355
+ <textarea
356
+ #field
357
+ class="cb-mentions__field"
358
+ [class.cb-is-invalid]="fieldState.invalid()"
359
+ [id]="inputId"
360
+ [rows]="rows()"
361
+ [value]="value()"
362
+ [placeholder]="placeholder()"
363
+ [disabled]="isDisabled()"
364
+ [required]="fieldState.required()"
365
+ aria-autocomplete="list"
366
+ [attr.aria-controls]="open() ? listId : null"
367
+ [attr.aria-activedescendant]="open() ? activeId() : null"
368
+ [attr.aria-invalid]="fieldState.invalid() ? 'true' : null"
369
+ [attr.aria-describedby]="hint() ? inputId + '-hint' : null"
370
+ [attr.aria-label]="label() ? null : (ariaLabel() || null)"
371
+ (input)="onInput($event)"
372
+ (keydown)="onKeydown($event)"
373
+ (click)="detect()"
374
+ (blur)="onBlur()"
375
+ ></textarea>
376
+ @if (hint()) {
377
+ <p class="cb-mentions__hint" [id]="inputId + '-hint'">{{ hint() }}</p>
378
+ }
379
+ <div class="cb-mentions__sr" role="status">{{ announcement() }}</div>
380
+
381
+ <ng-template #panel>
382
+ <ul class="cb-mentions__panel" role="listbox" [id]="listId" [attr.aria-label]="label() || ariaLabel() || null">
383
+ @for (item of results(); track item.id; let i = $index) {
384
+ <li
385
+ class="cb-mentions__option"
386
+ role="option"
387
+ [id]="listId + '-' + i"
388
+ [class.cb-mentions__option--active]="i === active()"
389
+ [attr.aria-selected]="i === active()"
390
+ (mousedown)="$event.preventDefault()"
391
+ (mousemove)="active.set(i)"
392
+ (click)="choose(item)"
393
+ >
394
+ <span class="cb-mentions__avatar" aria-hidden="true">
395
+ @if (item.avatar) {
396
+ <img [src]="item.avatar" alt="" />
397
+ } @else {
398
+ {{ initials(item) }}
399
+ }
400
+ </span>
401
+ <span class="cb-mentions__text">
402
+ <span class="cb-mentions__name">{{ item.label }}</span>
403
+ @if (item.description) {
404
+ <span class="cb-mentions__description">{{ item.description }}</span>
405
+ }
406
+ </span>
407
+ </li>
408
+ } @empty {
409
+ <li class="cb-mentions__empty" role="presentation">{{ loading() ? t().loading : t().noResults }}</li>
410
+ }
411
+ </ul>
412
+ </ng-template>
413
+ `, isInline: true, styles: [":host{display:block;font-family:var(--cb-font-sans)}.cb-mentions__label{display:block;margin-bottom:var(--cb-space-1);font-size:var(--cb-text-sm);font-weight:var(--cb-font-weight-medium);color:var(--cb-color-text)}.cb-mentions__required{margin-left:2px;color:var(--cb-color-danger)}.cb-mentions__required--required,.cb-mentions__required--optional{margin-left:.25rem;color:var(--cb-color-text-muted);font-size:.85em;font-weight:var(--cb-font-weight-normal, 400)}.cb-mentions__field{box-sizing:border-box;display:block;width:100%;padding:var(--cb-space-2) var(--cb-space-3);border:var(--cb-border-width, 1px) solid var(--cb-color-border-strong);border-radius:var(--cb-radius-md);background-color:var(--cb-color-bg);color:var(--cb-color-text);font:inherit;font-size:var(--cb-text-base);line-height:1.5;resize:vertical;transition:border-color var(--cb-duration-fast) var(--cb-ease),box-shadow var(--cb-duration-fast) var(--cb-ease)}.cb-mentions__field::placeholder{color:var(--cb-color-text-muted)}.cb-mentions__field:hover:not(:disabled):not(:focus){border-color:var(--cb-color-text-muted)}.cb-mentions__field:focus-visible{outline:none;border-color:var(--cb-color-primary-500);box-shadow:0 0 0 3px color-mix(in srgb,var(--cb-color-primary-500) 25%,transparent)}.cb-mentions__field.cb-is-invalid{border-color:var(--cb-color-danger)}.cb-mentions__field:disabled{cursor:not-allowed;background-color:var(--cb-color-surface);color:var(--cb-color-text-muted)}.cb-mentions__hint{margin:var(--cb-space-1) 0 0;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm)}.cb-mentions__sr{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cb-mentions__panel{width:18rem;max-width:calc(100vw - 2rem);max-height:16rem;margin:0;padding:.375rem;overflow-y:auto;border:1px solid var(--cb-color-border);border-radius:var(--cb-radius-md);background:var(--cb-color-surface-raised);box-shadow:var(--cb-shadow-lg);color:var(--cb-color-text);font-family:var(--cb-font-sans);list-style:none}.cb-mentions__option{display:flex;align-items:center;gap:.625rem;padding:.375rem .5rem;border-radius:var(--cb-radius-sm);font-size:var(--cb-text-sm);cursor:pointer}.cb-mentions__option--active{background:var(--cb-color-surface-hover);box-shadow:inset 3px 0 0 var(--cb-color-primary)}.cb-mentions__avatar{display:inline-flex;flex:none;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;overflow:hidden;border-radius:50%;background:color-mix(in srgb,var(--cb-color-primary) 14%,transparent);color:var(--cb-color-primary);font-size:.6875rem;font-weight:var(--cb-font-weight-semibold, 600)}.cb-mentions__avatar img{width:100%;height:100%;object-fit:cover}.cb-mentions__text{display:flex;flex-direction:column;min-width:0}.cb-mentions__name,.cb-mentions__description{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cb-mentions__description{color:var(--cb-color-text-muted);font-size:var(--cb-text-xs)}.cb-mentions__empty{padding:.75rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm);text-align:center}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
414
+ }
415
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbMentions, decorators: [{
416
+ type: Component,
417
+ args: [{ selector: 'cb-mentions', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.Emulated, host: { class: 'cb-mentions' }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CbMentions), multi: true }], template: `
418
+ @if (label()) {
419
+ <label class="cb-mentions__label" [attr.for]="inputId">
420
+ {{ label() }}
421
+ @if (fieldState.indicator(); as mark) {
422
+ <span [class]="'cb-mentions__required cb-mentions__required--' + mark.kind" [attr.aria-hidden]="mark.kind === 'optional' ? null : 'true'">{{ mark.text }}</span>
423
+ }
424
+ </label>
425
+ }
426
+ <textarea
427
+ #field
428
+ class="cb-mentions__field"
429
+ [class.cb-is-invalid]="fieldState.invalid()"
430
+ [id]="inputId"
431
+ [rows]="rows()"
432
+ [value]="value()"
433
+ [placeholder]="placeholder()"
434
+ [disabled]="isDisabled()"
435
+ [required]="fieldState.required()"
436
+ aria-autocomplete="list"
437
+ [attr.aria-controls]="open() ? listId : null"
438
+ [attr.aria-activedescendant]="open() ? activeId() : null"
439
+ [attr.aria-invalid]="fieldState.invalid() ? 'true' : null"
440
+ [attr.aria-describedby]="hint() ? inputId + '-hint' : null"
441
+ [attr.aria-label]="label() ? null : (ariaLabel() || null)"
442
+ (input)="onInput($event)"
443
+ (keydown)="onKeydown($event)"
444
+ (click)="detect()"
445
+ (blur)="onBlur()"
446
+ ></textarea>
447
+ @if (hint()) {
448
+ <p class="cb-mentions__hint" [id]="inputId + '-hint'">{{ hint() }}</p>
449
+ }
450
+ <div class="cb-mentions__sr" role="status">{{ announcement() }}</div>
451
+
452
+ <ng-template #panel>
453
+ <ul class="cb-mentions__panel" role="listbox" [id]="listId" [attr.aria-label]="label() || ariaLabel() || null">
454
+ @for (item of results(); track item.id; let i = $index) {
455
+ <li
456
+ class="cb-mentions__option"
457
+ role="option"
458
+ [id]="listId + '-' + i"
459
+ [class.cb-mentions__option--active]="i === active()"
460
+ [attr.aria-selected]="i === active()"
461
+ (mousedown)="$event.preventDefault()"
462
+ (mousemove)="active.set(i)"
463
+ (click)="choose(item)"
464
+ >
465
+ <span class="cb-mentions__avatar" aria-hidden="true">
466
+ @if (item.avatar) {
467
+ <img [src]="item.avatar" alt="" />
468
+ } @else {
469
+ {{ initials(item) }}
470
+ }
471
+ </span>
472
+ <span class="cb-mentions__text">
473
+ <span class="cb-mentions__name">{{ item.label }}</span>
474
+ @if (item.description) {
475
+ <span class="cb-mentions__description">{{ item.description }}</span>
476
+ }
477
+ </span>
478
+ </li>
479
+ } @empty {
480
+ <li class="cb-mentions__empty" role="presentation">{{ loading() ? t().loading : t().noResults }}</li>
481
+ }
482
+ </ul>
483
+ </ng-template>
484
+ `, styles: [":host{display:block;font-family:var(--cb-font-sans)}.cb-mentions__label{display:block;margin-bottom:var(--cb-space-1);font-size:var(--cb-text-sm);font-weight:var(--cb-font-weight-medium);color:var(--cb-color-text)}.cb-mentions__required{margin-left:2px;color:var(--cb-color-danger)}.cb-mentions__required--required,.cb-mentions__required--optional{margin-left:.25rem;color:var(--cb-color-text-muted);font-size:.85em;font-weight:var(--cb-font-weight-normal, 400)}.cb-mentions__field{box-sizing:border-box;display:block;width:100%;padding:var(--cb-space-2) var(--cb-space-3);border:var(--cb-border-width, 1px) solid var(--cb-color-border-strong);border-radius:var(--cb-radius-md);background-color:var(--cb-color-bg);color:var(--cb-color-text);font:inherit;font-size:var(--cb-text-base);line-height:1.5;resize:vertical;transition:border-color var(--cb-duration-fast) var(--cb-ease),box-shadow var(--cb-duration-fast) var(--cb-ease)}.cb-mentions__field::placeholder{color:var(--cb-color-text-muted)}.cb-mentions__field:hover:not(:disabled):not(:focus){border-color:var(--cb-color-text-muted)}.cb-mentions__field:focus-visible{outline:none;border-color:var(--cb-color-primary-500);box-shadow:0 0 0 3px color-mix(in srgb,var(--cb-color-primary-500) 25%,transparent)}.cb-mentions__field.cb-is-invalid{border-color:var(--cb-color-danger)}.cb-mentions__field:disabled{cursor:not-allowed;background-color:var(--cb-color-surface);color:var(--cb-color-text-muted)}.cb-mentions__hint{margin:var(--cb-space-1) 0 0;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm)}.cb-mentions__sr{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cb-mentions__panel{width:18rem;max-width:calc(100vw - 2rem);max-height:16rem;margin:0;padding:.375rem;overflow-y:auto;border:1px solid var(--cb-color-border);border-radius:var(--cb-radius-md);background:var(--cb-color-surface-raised);box-shadow:var(--cb-shadow-lg);color:var(--cb-color-text);font-family:var(--cb-font-sans);list-style:none}.cb-mentions__option{display:flex;align-items:center;gap:.625rem;padding:.375rem .5rem;border-radius:var(--cb-radius-sm);font-size:var(--cb-text-sm);cursor:pointer}.cb-mentions__option--active{background:var(--cb-color-surface-hover);box-shadow:inset 3px 0 0 var(--cb-color-primary)}.cb-mentions__avatar{display:inline-flex;flex:none;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;overflow:hidden;border-radius:50%;background:color-mix(in srgb,var(--cb-color-primary) 14%,transparent);color:var(--cb-color-primary);font-size:.6875rem;font-weight:var(--cb-font-weight-semibold, 600)}.cb-mentions__avatar img{width:100%;height:100%;object-fit:cover}.cb-mentions__text{display:flex;flex-direction:column;min-width:0}.cb-mentions__name,.cb-mentions__description{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cb-mentions__description{color:var(--cb-color-text-muted);font-size:var(--cb-text-xs)}.cb-mentions__empty{padding:.75rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm);text-align:center}\n"] }]
485
+ }], propDecorators: { fieldEl: [{ type: i0.ViewChild, args: ['field', { isSignal: true }] }], panelTpl: [{ type: i0.ViewChild, args: ['panel', { isSignal: true }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], suggestions: [{ type: i0.Input, args: [{ isSignal: true, alias: "suggestions", required: false }] }], triggers: [{ type: i0.Input, args: [{ isSignal: true, alias: "triggers", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], maxResults: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxResults", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], rows: [{ type: i0.Input, args: [{ isSignal: true, alias: "rows", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], requiredIndicator: [{ type: i0.Input, args: [{ isSignal: true, alias: "requiredIndicator", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], search: [{ type: i0.Output, args: ["search"] }], mentionsChange: [{ type: i0.Output, args: ["mentionsChange"] }] } });
486
+
487
+ /*
488
+ * Public API Surface de @caribeng/ui/mentions
489
+ */
490
+
491
+ /**
492
+ * Generated bundle index. Do not edit.
493
+ */
494
+
495
+ export { CbMentions, cbCaretCoordinates };
@@ -1,9 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ViewContainerRef, DestroyRef, input, output, viewChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
2
+ import { inject, ViewContainerRef, DestroyRef, input, computed, output, viewChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
3
3
  import { Overlay } from '@angular/cdk/overlay';
4
4
  import { TemplatePortal } from '@angular/cdk/portal';
5
5
  import { CbIcon } from '@caribeng/ui/icon';
6
- import { injectCbTranslation } from '@caribeng/ui';
6
+ import { injectCbTranslation, cbVisibleItems, cbRunCommand } from '@caribeng/ui';
7
7
 
8
8
  /** Popup menu anchored to any trigger element. */
9
9
  class CbMenu {
@@ -15,6 +15,9 @@ class CbMenu {
15
15
  this.destroyRef = inject(DestroyRef);
16
16
  this.items = input([], /* @ts-ignore */
17
17
  ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
18
+ /** Items sin los de `visible: false`. */
19
+ this.visibleItems = computed(() => cbVisibleItems(this.items()), /* @ts-ignore */
20
+ ...(ngDevMode ? [{ debugName: "visibleItems" }] : /* istanbul ignore next */ []));
18
21
  this.ariaLabel = input(undefined, /* @ts-ignore */
19
22
  ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
20
23
  this.itemSelect = output();
@@ -71,6 +74,7 @@ class CbMenu {
71
74
  event.preventDefault();
72
75
  return;
73
76
  }
77
+ cbRunCommand(item, event);
74
78
  this.itemSelect.emit(item);
75
79
  this.hide();
76
80
  }
@@ -100,7 +104,7 @@ class CbMenu {
100
104
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: CbMenu, isStandalone: true, selector: "cb-menu", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemSelect: "itemSelect", hidden: "hidden" }, viewQueries: [{ propertyName: "content", first: true, predicate: ["content"], descendants: true, isSignal: true }], ngImport: i0, template: `
101
105
  <ng-template #content>
102
106
  <div class="cb-menu__panel" role="menu" [attr.aria-label]="(ariaLabel() ?? t().menu) || null" (click)="onPanelClick($event)">
103
- @for (item of items(); track $index) {
107
+ @for (item of visibleItems(); track $index) {
104
108
  @if (item.separator) {
105
109
  <div class="cb-menu__separator" role="separator"></div>
106
110
  } @else {
@@ -140,7 +144,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
140
144
  args: [{ selector: 'cb-menu', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.Emulated, imports: [CbIcon], template: `
141
145
  <ng-template #content>
142
146
  <div class="cb-menu__panel" role="menu" [attr.aria-label]="(ariaLabel() ?? t().menu) || null" (click)="onPanelClick($event)">
143
- @for (item of items(); track $index) {
147
+ @for (item of visibleItems(); track $index) {
144
148
  @if (item.separator) {
145
149
  <div class="cb-menu__separator" role="separator"></div>
146
150
  } @else {
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ElementRef, Injector, input, output, signal, afterNextRender, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
2
+ import { inject, ElementRef, Injector, input, computed, output, signal, afterNextRender, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
3
3
  import { CbIcon } from '@caribeng/ui/icon';
4
- import { injectCbTranslation } from '@caribeng/ui';
4
+ import { injectCbTranslation, cbVisibleItems, cbRunCommand } from '@caribeng/ui';
5
5
 
6
6
  /** Horizontal navigation bar with optional one-level dropdown menus. */
7
7
  class CbMenubar {
@@ -12,6 +12,9 @@ class CbMenubar {
12
12
  this.injector = inject(Injector);
13
13
  this.items = input([], /* @ts-ignore */
14
14
  ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
15
+ /** Items sin los de `visible: false`. */
16
+ this.visibleItems = computed(() => cbVisibleItems(this.items()), /* @ts-ignore */
17
+ ...(ngDevMode ? [{ debugName: "visibleItems" }] : /* istanbul ignore next */ []));
15
18
  this.ariaLabel = input(undefined, /* @ts-ignore */
16
19
  ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
17
20
  this.itemSelect = output();
@@ -26,6 +29,7 @@ class CbMenubar {
26
29
  event.preventDefault();
27
30
  return;
28
31
  }
32
+ cbRunCommand(item);
29
33
  this.itemSelect.emit(item);
30
34
  if (parentIndex !== undefined)
31
35
  this.openIndex.set(null);
@@ -57,7 +61,7 @@ class CbMenubar {
57
61
  this.openIndex.set(null);
58
62
  return;
59
63
  }
60
- if (event.key === 'ArrowDown' && root && this.items()[rootIndex]?.items?.length) {
64
+ if (event.key === 'ArrowDown' && root && this.visibleItems()[rootIndex]?.items?.length) {
61
65
  event.preventDefault();
62
66
  this.openIndex.set(rootIndex);
63
67
  // El submenú se pinta en el siguiente render (zoneless): se enfoca después.
@@ -75,7 +79,7 @@ class CbMenubar {
75
79
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: CbMenubar, isStandalone: true, selector: "cb-menubar", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemSelect: "itemSelect" }, host: { listeners: { "keydown": "onKeydown($event)", "document:click": "onDocumentClick($event)" }, classAttribute: "cb-menubar" }, ngImport: i0, template: `
76
80
  <nav [attr.aria-label]="(ariaLabel() ?? t().mainNavigation)">
77
81
  <ul class="cb-menubar__list" role="menubar">
78
- @for (item of items(); track $index; let i = $index) {
82
+ @for (item of visibleItems(); track $index; let i = $index) {
79
83
  <li class="cb-menubar__entry" role="none">
80
84
  @if (item.items?.length) {
81
85
  <button
@@ -136,7 +140,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
136
140
  }, template: `
137
141
  <nav [attr.aria-label]="(ariaLabel() ?? t().mainNavigation)">
138
142
  <ul class="cb-menubar__list" role="menubar">
139
- @for (item of items(); track $index; let i = $index) {
143
+ @for (item of visibleItems(); track $index; let i = $index) {
140
144
  <li class="cb-menubar__entry" role="none">
141
145
  @if (item.items?.length) {
142
146
  <button
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, model, output, computed, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
2
+ import { input, model, computed, output, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
3
3
  import { CbIcon } from '@caribeng/ui/icon';
4
4
  import { injectCbTranslation } from '@caribeng/ui';
5
5
 
@@ -36,6 +36,9 @@ class CbMessage {
36
36
  /** Visibilidad (two-way). */
37
37
  this.visible = model(true, /* @ts-ignore */
38
38
  ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
39
+ /** danger y warning se anuncian al momento (`alert`); el resto, sin interrumpir (`status`). */
40
+ this.urgent = computed(() => this.severity() === 'danger' || this.severity() === 'warning', /* @ts-ignore */
41
+ ...(ngDevMode ? [{ debugName: "urgent" }] : /* istanbul ignore next */ []));
39
42
  /** Se emite al cerrar. */
40
43
  this.closed = output();
41
44
  this.iconName = computed(() => {
@@ -53,7 +56,7 @@ class CbMessage {
53
56
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbMessage, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
54
57
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: CbMessage, isStandalone: true, selector: "cb-message", inputs: { severity: { classPropertyName: "severity", publicName: "severity", isSignal: true, isRequired: false, transformFunction: null }, closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null }, visible: { classPropertyName: "visible", publicName: "visible", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { visible: "visibleChange", closed: "closed" }, host: { classAttribute: "cb-message-host" }, ngImport: i0, template: `
55
58
  @if (visible()) {
56
- <div class="cb-message" [class]="'cb-message--' + severity()" role="alert">
59
+ <div class="cb-message" [class]="'cb-message--' + severity()" [attr.role]="urgent() ? 'alert' : 'status'">
57
60
  @if (iconName()) {
58
61
  <cb-icon class="cb-message__icon" [name]="iconName()" [size]="18" aria-hidden="true" />
59
62
  }
@@ -71,7 +74,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
71
74
  type: Component,
72
75
  args: [{ selector: 'cb-message', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.Emulated, imports: [CbIcon], host: { class: 'cb-message-host' }, template: `
73
76
  @if (visible()) {
74
- <div class="cb-message" [class]="'cb-message--' + severity()" role="alert">
77
+ <div class="cb-message" [class]="'cb-message--' + severity()" [attr.role]="urgent() ? 'alert' : 'status'">
75
78
  @if (iconName()) {
76
79
  <cb-icon class="cb-message__icon" [name]="iconName()" [size]="18" aria-hidden="true" />
77
80
  }