mn-angular-lib 1.0.178 → 1.0.179
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.
- package/fesm2022/mn-angular-lib-alert.mjs +535 -0
- package/fesm2022/mn-angular-lib-alert.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-bottom-sheet.mjs +356 -0
- package/fesm2022/mn-angular-lib-bottom-sheet.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-button.mjs +382 -0
- package/fesm2022/mn-angular-lib-button.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-calendar-core.mjs +377 -0
- package/fesm2022/mn-angular-lib-calendar-core.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-calendar.mjs +1513 -0
- package/fesm2022/mn-angular-lib-calendar.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-collection.mjs +2277 -0
- package/fesm2022/mn-angular-lib-collection.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-core.mjs +1232 -0
- package/fesm2022/mn-angular-lib-core.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-display.mjs +728 -0
- package/fesm2022/mn-angular-lib-display.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-forms.mjs +4260 -0
- package/fesm2022/mn-angular-lib-forms.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-keyboard.mjs +195 -0
- package/fesm2022/mn-angular-lib-keyboard.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-modal-core.mjs +945 -0
- package/fesm2022/mn-angular-lib-modal-core.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-modal-ui.mjs +2016 -0
- package/fesm2022/mn-angular-lib-modal-ui.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-modal.mjs +126 -0
- package/fesm2022/mn-angular-lib-modal.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-rich-text-editor.mjs +275 -0
- package/fesm2022/mn-angular-lib-rich-text-editor.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-segmented.mjs +246 -0
- package/fesm2022/mn-angular-lib-segmented.mjs.map +1 -0
- package/fesm2022/mn-angular-lib-tab.mjs +573 -0
- package/fesm2022/mn-angular-lib-tab.mjs.map +1 -0
- package/fesm2022/mn-angular-lib.mjs +21 -15517
- package/fesm2022/mn-angular-lib.mjs.map +1 -1
- package/package.json +66 -1
- package/src/lib/styles/index.css +2 -2
- package/types/mn-angular-lib-alert.d.ts +258 -0
- package/types/mn-angular-lib-bottom-sheet.d.ts +173 -0
- package/types/mn-angular-lib-button.d.ts +318 -0
- package/types/mn-angular-lib-calendar-core.d.ts +378 -0
- package/types/mn-angular-lib-calendar.d.ts +636 -0
- package/types/mn-angular-lib-collection.d.ts +1550 -0
- package/types/mn-angular-lib-core.d.ts +756 -0
- package/types/mn-angular-lib-display.d.ts +1075 -0
- package/types/mn-angular-lib-forms.d.ts +3235 -0
- package/types/mn-angular-lib-keyboard.d.ts +128 -0
- package/types/mn-angular-lib-modal-core.d.ts +1130 -0
- package/types/mn-angular-lib-modal-ui.d.ts +492 -0
- package/types/mn-angular-lib-modal.d.ts +27 -0
- package/types/mn-angular-lib-rich-text-editor.d.ts +157 -0
- package/types/mn-angular-lib-segmented.d.ts +395 -0
- package/types/mn-angular-lib-tab.d.ts +313 -0
- package/types/mn-angular-lib.d.ts +16 -10822
- /package/{src/lib/features → alert/src}/mn-alert/mn-alert-outlet/mn-alert-outlet.css +0 -0
- /package/{src/lib/features → bottom-sheet/src}/mn-bottom-sheet/mn-bottom-sheet.component.css +0 -0
- /package/{src/lib/features → button/src}/mn-skeleton/mn-skeleton.css +0 -0
- /package/{src/lib/features → collection/src}/mn-list/mn-list.component.css +0 -0
- /package/{src/lib/features → forms/src}/mn-checkbox/mn-checkbox.css +0 -0
- /package/{src/lib/features → forms/src}/mn-dropdown/mn-dropdown.css +0 -0
- /package/{src/lib/features → forms/src}/mn-multi-select/mn-multi-select.css +0 -0
- /package/{src/lib/features → keyboard/src}/mn-keyboard/mn-keyboard.component.css +0 -0
- /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-confirmation-body/mn-confirmation-body.component.css +0 -0
- /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-form-body/mn-form-body.component.css +0 -0
- /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-modal-shell/mn-modal-shell.component.css +0 -0
- /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-wizard-body/mn-wizard-body.component.css +0 -0
- /package/{src/lib/features → rich-text-editor/src}/mn-rich-text-editor/mn-rich-text-editor.component.css +0 -0
|
@@ -0,0 +1,4260 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Input, Component, InjectionToken, inject, ElementRef, DestroyRef, EventEmitter, Output, signal, computed, Renderer2, ChangeDetectorRef, Injector, afterNextRender, HostListener, ViewChild, TemplateRef } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/common';
|
|
4
|
+
import { CommonModule, NgClass, NgTemplateOutlet } from '@angular/common';
|
|
5
|
+
import * as i1$1 from '@angular/forms';
|
|
6
|
+
import { NgControl, Validators, FormsModule } from '@angular/forms';
|
|
7
|
+
import { tv } from 'tailwind-variants';
|
|
8
|
+
import { MnConfigService, MN_SECTION_PATH, MN_INSTANCE_ID, MnLanguageService, lucideIcons } from 'mn-angular-lib/core';
|
|
9
|
+
import { skip } from 'rxjs';
|
|
10
|
+
import { LucideDynamicIcon } from '@lucide/angular';
|
|
11
|
+
import * as lucide from 'lucide';
|
|
12
|
+
import { MnBottomSheet } from 'mn-angular-lib/bottom-sheet';
|
|
13
|
+
import { MnButton } from 'mn-angular-lib/button';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* MnInputField Adapters
|
|
17
|
+
*
|
|
18
|
+
* This module implements the Adapter Pattern to handle type-specific behavior
|
|
19
|
+
* for different HTML input types in the MnInputField component.
|
|
20
|
+
*
|
|
21
|
+
* The adapter pattern allows the component to support multiple input types
|
|
22
|
+
* (text, number, date, time, etc.) without coupling the component logic to
|
|
23
|
+
* type-specific implementations. Each adapter handles:
|
|
24
|
+
* - Parsing: converting raw string input to the appropriate data type
|
|
25
|
+
* - Formatting: converting typed values back to string for display
|
|
26
|
+
* - Attributes: providing type-specific DOM attributes (min, max, step, inputmode)
|
|
27
|
+
* - Validation: implementing type-specific validation rules
|
|
28
|
+
*
|
|
29
|
+
* This approach keeps the component code clean and makes it easy to add
|
|
30
|
+
* support for new input types by creating new adapters.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Utility function to convert empty strings to null.
|
|
34
|
+
* This is a common pattern for optional form fields where empty input
|
|
35
|
+
* should be treated as "no value" rather than an empty string.
|
|
36
|
+
*
|
|
37
|
+
* @param raw - Raw input string
|
|
38
|
+
* @returns The input string if non-empty, null if empty
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* emptyToNull('hello') // => 'hello'
|
|
42
|
+
* emptyToNull('') // => null
|
|
43
|
+
*/
|
|
44
|
+
const emptyToNull = (raw) => (raw === '' ? null : raw);
|
|
45
|
+
/**
|
|
46
|
+
* Default adapter for text-based input types.
|
|
47
|
+
* Used for: text, email, password, search, tel, url
|
|
48
|
+
*
|
|
49
|
+
* Behavior:
|
|
50
|
+
* - Empty strings are converted to null
|
|
51
|
+
* - Values are stored as strings in the FormControl
|
|
52
|
+
* - No special DOM attributes
|
|
53
|
+
* - No additional validation (relies on Angular's built-in validators)
|
|
54
|
+
* - Supports simple masking (0 for digit, A for alpha, * for any)
|
|
55
|
+
*/
|
|
56
|
+
const defaultTextAdapter = {
|
|
57
|
+
parse: (raw) => emptyToNull(raw),
|
|
58
|
+
format: (val) => (val == null ? '' : String(val)),
|
|
59
|
+
attrs: () => ({}),
|
|
60
|
+
validate: () => null,
|
|
61
|
+
applyMask: (value, mask) => {
|
|
62
|
+
if (!mask || !value)
|
|
63
|
+
return value;
|
|
64
|
+
let result = '';
|
|
65
|
+
let maskIndex = 0;
|
|
66
|
+
let dataIndex = 0;
|
|
67
|
+
// Remove non-alphanumeric if we want to re-mask from clean data
|
|
68
|
+
// But usually we just want to restrict input.
|
|
69
|
+
// A simple implementation:
|
|
70
|
+
while (maskIndex < mask.length && dataIndex < value.length) {
|
|
71
|
+
const maskChar = mask[maskIndex];
|
|
72
|
+
const dataChar = value[dataIndex];
|
|
73
|
+
if (maskChar === '0') {
|
|
74
|
+
if (/\d/.test(dataChar)) {
|
|
75
|
+
result += dataChar;
|
|
76
|
+
dataIndex++;
|
|
77
|
+
maskIndex++;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
dataIndex++; // skip invalid
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (maskChar === 'A') {
|
|
84
|
+
if (/[a-zA-Z]/.test(dataChar)) {
|
|
85
|
+
result += dataChar;
|
|
86
|
+
dataIndex++;
|
|
87
|
+
maskIndex++;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
dataIndex++; // skip invalid
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (maskChar === '*') {
|
|
94
|
+
result += dataChar;
|
|
95
|
+
dataIndex++;
|
|
96
|
+
maskIndex++;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
result += maskChar;
|
|
100
|
+
if (dataChar === maskChar) {
|
|
101
|
+
dataIndex++;
|
|
102
|
+
}
|
|
103
|
+
maskIndex++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Auto-append static characters if next in mask
|
|
107
|
+
while (maskIndex < mask.length && !/[0A*]/.test(mask[maskIndex])) {
|
|
108
|
+
result += mask[maskIndex];
|
|
109
|
+
maskIndex++;
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Adapter for date and time input types.
|
|
116
|
+
* Used for: date, time, datetime-local
|
|
117
|
+
*
|
|
118
|
+
* Behavior:
|
|
119
|
+
* - Empty strings are converted to null
|
|
120
|
+
* - Values are stored as ISO 8601 strings in the FormControl
|
|
121
|
+
* - Provides min/max attributes from startDate/endDate props
|
|
122
|
+
* - Validates date/time ranges using string comparison
|
|
123
|
+
*
|
|
124
|
+
* Note: String comparison works for ISO 8601 dates/times because they are
|
|
125
|
+
* lexicographically ordered (e.g., '2024-01-15' < '2024-12-31').
|
|
126
|
+
*/
|
|
127
|
+
const dateTimeAdapter = {
|
|
128
|
+
parse: (raw) => emptyToNull(raw),
|
|
129
|
+
format: (val) => (val == null ? '' : String(val)),
|
|
130
|
+
attrs: (props) => ({
|
|
131
|
+
min: props.startDate ?? null,
|
|
132
|
+
max: props.endDate ?? null,
|
|
133
|
+
}),
|
|
134
|
+
validate: (props, _control, currentRaw) => {
|
|
135
|
+
const value = currentRaw;
|
|
136
|
+
if (!value)
|
|
137
|
+
return null; // Don't validate empty values (use 'required' validator for that)
|
|
138
|
+
const min = props.startDate;
|
|
139
|
+
const max = props.endDate;
|
|
140
|
+
// Validate minimum date/time constraint
|
|
141
|
+
if (min && value < min) {
|
|
142
|
+
return { mnMin: { min, actual: value } };
|
|
143
|
+
}
|
|
144
|
+
// Validate maximum date/time constraint
|
|
145
|
+
if (max && value > max) {
|
|
146
|
+
return { mnMax: { max, actual: value } };
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Adapter for number input type.
|
|
153
|
+
*
|
|
154
|
+
* Behavior:
|
|
155
|
+
* - Empty strings are converted to null
|
|
156
|
+
* - Valid numbers are parsed to number type
|
|
157
|
+
* - Invalid numbers (NaN, Infinity) are converted to null
|
|
158
|
+
* - Values are stored as numbers (or null) in the FormControl
|
|
159
|
+
* - Sets inputmode='decimal' for optimized mobile keyboards
|
|
160
|
+
* - No additional validation (relies on Angular's built-in validators)
|
|
161
|
+
*
|
|
162
|
+
* Note: The browser's native number input validation handles
|
|
163
|
+
* basic number format validation automatically.
|
|
164
|
+
*/
|
|
165
|
+
const numberAdapter = {
|
|
166
|
+
parse: (raw) => {
|
|
167
|
+
if (raw === '')
|
|
168
|
+
return null;
|
|
169
|
+
const num = Number(raw);
|
|
170
|
+
return Number.isFinite(num) ? num : null;
|
|
171
|
+
},
|
|
172
|
+
format: (val) => (val == null ? '' : String(val)),
|
|
173
|
+
attrs: () => ({
|
|
174
|
+
inputmode: 'decimal',
|
|
175
|
+
}),
|
|
176
|
+
validate: () => null,
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Selects the appropriate adapter based on the input type.
|
|
180
|
+
* This is the main factory function used by the MnInputField component
|
|
181
|
+
* to determine which adapter to use for a given input type.
|
|
182
|
+
*
|
|
183
|
+
* @param type - The input type (e.g., 'text', 'email', 'date', 'number')
|
|
184
|
+
* @returns The appropriate adapter instance
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* pickAdapter('text') // => defaultTextAdapter
|
|
188
|
+
* pickAdapter('email') // => defaultTextAdapter
|
|
189
|
+
* pickAdapter('date') // => dateTimeAdapter
|
|
190
|
+
* pickAdapter('number') // => numberAdapter
|
|
191
|
+
*/
|
|
192
|
+
function pickAdapter(type) {
|
|
193
|
+
// Date/time inputs use the dateTimeAdapter for range validation
|
|
194
|
+
if (type === 'date' || type === 'time' || type === 'datetime-local') {
|
|
195
|
+
return dateTimeAdapter;
|
|
196
|
+
}
|
|
197
|
+
// Number inputs use the numberAdapter for type conversion
|
|
198
|
+
if (type === 'number') {
|
|
199
|
+
return numberAdapter;
|
|
200
|
+
}
|
|
201
|
+
// All other input types use the default text adapter
|
|
202
|
+
return defaultTextAdapter;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const mnInputFieldVariants = tv({
|
|
206
|
+
base: 'bg-base-100 border-1 border-base-300 placeholder-base-content/50 text-base-content text-sm outline-none focus:ring-1 focus:ring-primary',
|
|
207
|
+
variants: {
|
|
208
|
+
shadow: {
|
|
209
|
+
true: 'shadow-lg',
|
|
210
|
+
},
|
|
211
|
+
size: {
|
|
212
|
+
sm: 'p-2',
|
|
213
|
+
md: 'p-3',
|
|
214
|
+
lg: 'p-4',
|
|
215
|
+
},
|
|
216
|
+
borderRadius: {
|
|
217
|
+
none: 'rounded-none',
|
|
218
|
+
xs: 'rounded-xs',
|
|
219
|
+
sm: 'rounded-sm',
|
|
220
|
+
md: 'rounded-md',
|
|
221
|
+
lg: 'rounded-lg',
|
|
222
|
+
xl: 'rounded-xl',
|
|
223
|
+
two_xl: 'rounded-2xl',
|
|
224
|
+
three_xl: 'rounded-3xl',
|
|
225
|
+
four_xl: 'rounded-4xl',
|
|
226
|
+
},
|
|
227
|
+
fullWidth: {
|
|
228
|
+
true: 'w-full',
|
|
229
|
+
},
|
|
230
|
+
hover: {
|
|
231
|
+
true: 'hover:cursor-pointer hover:bg-base-200 transition-colors duration-300 ease-in-out',
|
|
232
|
+
},
|
|
233
|
+
disabled: {
|
|
234
|
+
true: 'opacity-50 cursor-not-allowed',
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
defaultVariants: {
|
|
238
|
+
size: 'md',
|
|
239
|
+
borderRadius: 'md',
|
|
240
|
+
hover: true,
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
class MnErrorMessage {
|
|
245
|
+
errorMessage;
|
|
246
|
+
id;
|
|
247
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnErrorMessage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
248
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.1.3", type: MnErrorMessage, isStandalone: true, selector: "mn-error-message", inputs: { errorMessage: "errorMessage", id: "id" }, ngImport: i0, template: "<div [id]=\"id + '-error'\" role=\"alert\" class=\"text-error mt-2 text-sm\">\n {{ errorMessage }}\n</div>\n" });
|
|
249
|
+
}
|
|
250
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnErrorMessage, decorators: [{
|
|
251
|
+
type: Component,
|
|
252
|
+
args: [{ selector: 'mn-error-message', imports: [], template: "<div [id]=\"id + '-error'\" role=\"alert\" class=\"text-error mt-2 text-sm\">\n {{ errorMessage }}\n</div>\n" }]
|
|
253
|
+
}], propDecorators: { errorMessage: [{
|
|
254
|
+
type: Input,
|
|
255
|
+
args: [{ required: true }]
|
|
256
|
+
}], id: [{
|
|
257
|
+
type: Input,
|
|
258
|
+
args: [{ required: true }]
|
|
259
|
+
}] } });
|
|
260
|
+
|
|
261
|
+
const MN_INPUT_FIELD_CONFIG = new InjectionToken('MN_INPUT_FIELD_CONFIG');
|
|
262
|
+
/**
|
|
263
|
+
* MnInputField Component
|
|
264
|
+
*
|
|
265
|
+
* A flexible, accessible input field component that implements Angular's ControlValueAccessor
|
|
266
|
+
* and Validator interfaces. Supports multiple input types, custom validation messages,
|
|
267
|
+
* and configurable error display (single or multiple errors).
|
|
268
|
+
*
|
|
269
|
+
* Features:
|
|
270
|
+
* - Works with Angular Reactive Forms (FormControl, FormGroup)
|
|
271
|
+
* - Supports standard and date/time input types
|
|
272
|
+
* - Built-in error messages with internationalization support
|
|
273
|
+
* - Custom error messages per field
|
|
274
|
+
* - Priority-based error display or show all errors
|
|
275
|
+
* - Full accessibility (ARIA attributes)
|
|
276
|
+
* - Type-safe adapter pattern for different input types
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* <mn-input-field
|
|
281
|
+
* formControlName="email"
|
|
282
|
+
* [props]="{
|
|
283
|
+
* id: 'email',
|
|
284
|
+
* type: 'email',
|
|
285
|
+
* label: 'Email Address',
|
|
286
|
+
* size: 'md',
|
|
287
|
+
* borderRadius: 'md',
|
|
288
|
+
* errorMessages: { required: 'Email is required' }
|
|
289
|
+
* }"
|
|
290
|
+
* ></mn-input-field>
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
class MnInputField {
|
|
294
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
295
|
+
/** Resolved UI configuration for the input field */
|
|
296
|
+
uiConfig = {};
|
|
297
|
+
el = inject(ElementRef);
|
|
298
|
+
/** Configuration properties for the input field */
|
|
299
|
+
props;
|
|
300
|
+
configService = inject(MnConfigService);
|
|
301
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
302
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
303
|
+
lang = inject(MnLanguageService);
|
|
304
|
+
destroyRef = inject(DestroyRef);
|
|
305
|
+
/** Current raw string value of the input element */
|
|
306
|
+
value = null;
|
|
307
|
+
/** Whether the input is disabled */
|
|
308
|
+
isDisabled = false;
|
|
309
|
+
/** Callback function to notify Angular forms of value changes */
|
|
310
|
+
onChange = () => {
|
|
311
|
+
};
|
|
312
|
+
/** Callback function to notify Angular forms when input is touched/blurred */
|
|
313
|
+
onTouched = () => { };
|
|
314
|
+
/**
|
|
315
|
+
* Built-in default error messages in English.
|
|
316
|
+
* These are used when useBuiltInErrorMessages is true (default).
|
|
317
|
+
* Can be overridden per-field using props.errorMessages.
|
|
318
|
+
*/
|
|
319
|
+
builtInErrorMessages = {
|
|
320
|
+
required: 'This field is required',
|
|
321
|
+
email: 'Please enter a valid email address',
|
|
322
|
+
minlength: (args) => `Minimum ${args.requiredLength} characters required`,
|
|
323
|
+
maxlength: (args) => `Maximum ${args.requiredLength} characters allowed`,
|
|
324
|
+
mnMin: (args) => `Date/time must be from ${args.min} onwards`,
|
|
325
|
+
mnMax: (args) => `Date/time must be up to ${args.max}`,
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Constructor - Registers this component as the ControlValueAccessor
|
|
329
|
+
* for the injected NgControl (FormControl).
|
|
330
|
+
*
|
|
331
|
+
*/
|
|
332
|
+
constructor() {
|
|
333
|
+
if (this.ngControl)
|
|
334
|
+
this.ngControl.valueAccessor = this;
|
|
335
|
+
}
|
|
336
|
+
ngOnInit() {
|
|
337
|
+
this.resolveConfig();
|
|
338
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
339
|
+
this.resolveConfig();
|
|
340
|
+
});
|
|
341
|
+
this.destroyRef.onDestroy(() => sub.unsubscribe());
|
|
342
|
+
if (this.props.autoFocus) {
|
|
343
|
+
setTimeout(() => this.focus(), 0);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Focuses the input element.
|
|
348
|
+
*/
|
|
349
|
+
focus() {
|
|
350
|
+
const input = this.el.nativeElement.querySelector('input');
|
|
351
|
+
// `preventScroll` so autofocusing inside a popover (e.g. mn-dropdown's search) never
|
|
352
|
+
// scrolls the input into view — a scroll would trip the host's scroll-to-close logic.
|
|
353
|
+
if (input)
|
|
354
|
+
input.focus({ preventScroll: true });
|
|
355
|
+
}
|
|
356
|
+
resolveConfig() {
|
|
357
|
+
const instanceId = this.explicitInstanceId || `mn-input-${this.props.id}`;
|
|
358
|
+
this.uiConfig = this.configService.resolve('mn-input-field', this.sectionPath, instanceId);
|
|
359
|
+
// Allow props to override uiConfig for label and placeholder
|
|
360
|
+
if (this.props) {
|
|
361
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
362
|
+
this.uiConfig = { ...this.uiConfig, placeholder: this.props.placeholder };
|
|
363
|
+
if (this.props.ariaLabel) {
|
|
364
|
+
this.uiConfig = { ...this.uiConfig, ariaLabel: this.props.ariaLabel };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Gets the appropriate adapter based on the input type.
|
|
370
|
+
* Adapters handle type-specific formatting, parsing, and validation.
|
|
371
|
+
*/
|
|
372
|
+
get adapter() {
|
|
373
|
+
return pickAdapter(this.props.type);
|
|
374
|
+
}
|
|
375
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
376
|
+
/**
|
|
377
|
+
* Writes a new value to the input element (called by Angular Forms).
|
|
378
|
+
* Formats the value using the type-specific adapter.
|
|
379
|
+
*
|
|
380
|
+
* @param val - The value to write (type depends on input type)
|
|
381
|
+
*/
|
|
382
|
+
writeValue(val) {
|
|
383
|
+
this.value = this.adapter.format(val);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Registers a callback function to be called when the input value changes.
|
|
387
|
+
*
|
|
388
|
+
* @param fn - Callback function to notify Angular Forms of changes
|
|
389
|
+
*/
|
|
390
|
+
registerOnChange(fn) {
|
|
391
|
+
this.onChange = fn;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Registers a callback function to be called when the input is touched/blurred.
|
|
395
|
+
*
|
|
396
|
+
* @param fn - Callback function to notify Angular Forms of touch events
|
|
397
|
+
*/
|
|
398
|
+
registerOnTouched(fn) {
|
|
399
|
+
this.onTouched = fn;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Sets the disabled state of the input element.
|
|
403
|
+
*
|
|
404
|
+
* @param isDisabled - Whether the input should be disabled
|
|
405
|
+
*/
|
|
406
|
+
setDisabledState(isDisabled) {
|
|
407
|
+
this.isDisabled = isDisabled;
|
|
408
|
+
}
|
|
409
|
+
// ========== Event Handlers ==========
|
|
410
|
+
/**
|
|
411
|
+
* Handles input events from the input element.
|
|
412
|
+
* Parses the raw string value and notifies Angular Forms.
|
|
413
|
+
*
|
|
414
|
+
* @param raw - Raw string value from the input element
|
|
415
|
+
*/
|
|
416
|
+
handleInput(raw) {
|
|
417
|
+
let finalValue = raw;
|
|
418
|
+
// Apply mask if available
|
|
419
|
+
if (this.props.mask && typeof this.adapter.applyMask === 'function') {
|
|
420
|
+
finalValue = this.adapter.applyMask(raw, this.props.mask);
|
|
421
|
+
// Force-update the DOM input when the mask stripped characters,
|
|
422
|
+
// because Angular won't re-render if this.value hasn't changed.
|
|
423
|
+
if (finalValue !== raw) {
|
|
424
|
+
const input = this.el.nativeElement.querySelector('input');
|
|
425
|
+
if (input)
|
|
426
|
+
input.value = finalValue;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
this.value = finalValue;
|
|
430
|
+
this.onChange(this.adapter.parse(finalValue));
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Handles blur events from the input element.
|
|
434
|
+
* Notifies Angular Forms that the input has been touched.
|
|
435
|
+
*/
|
|
436
|
+
handleBlur() {
|
|
437
|
+
this.onTouched();
|
|
438
|
+
}
|
|
439
|
+
// ========== Validator Implementation ==========
|
|
440
|
+
/**
|
|
441
|
+
* Validates the control using the type-specific adapter.
|
|
442
|
+
* Called by Angular Forms during validation.
|
|
443
|
+
*
|
|
444
|
+
* @param control - The AbstractControl to validate
|
|
445
|
+
* @returns ValidationErrors if invalid, null if valid
|
|
446
|
+
*/
|
|
447
|
+
validate(control) {
|
|
448
|
+
return this.adapter.validate(this.props, control, this.value);
|
|
449
|
+
}
|
|
450
|
+
// ========== Template Attribute Getters ==========
|
|
451
|
+
/**
|
|
452
|
+
* Gets all DOM attributes from the adapter.
|
|
453
|
+
* These are input-type-specific attributes (min, max, step, inputmode).
|
|
454
|
+
*/
|
|
455
|
+
get domAttrs() {
|
|
456
|
+
return this.adapter.attrs(this.props);
|
|
457
|
+
}
|
|
458
|
+
/** Min attribute for date/time/number inputs */
|
|
459
|
+
get minAttr() {
|
|
460
|
+
return this.domAttrs.min ?? null;
|
|
461
|
+
}
|
|
462
|
+
/** Max attribute for date/time/number inputs */
|
|
463
|
+
get maxAttr() {
|
|
464
|
+
return this.domAttrs.max ?? null;
|
|
465
|
+
}
|
|
466
|
+
/** Step attribute for number/date/time inputs */
|
|
467
|
+
get stepAttr() {
|
|
468
|
+
return this.domAttrs.step ?? null;
|
|
469
|
+
}
|
|
470
|
+
/** Inputmode attribute for mobile keyboard optimization */
|
|
471
|
+
get inputmodeAttr() {
|
|
472
|
+
return this.domAttrs.inputmode ?? null;
|
|
473
|
+
}
|
|
474
|
+
// ========== Error Handling ==========
|
|
475
|
+
/**
|
|
476
|
+
* Gets the FormControl instance from Angular Forms.
|
|
477
|
+
* Returns null if no control is attached.
|
|
478
|
+
*/
|
|
479
|
+
get control() {
|
|
480
|
+
return this.ngControl?.control ?? null;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Determines whether to show error messages.
|
|
484
|
+
* Errors are shown when the control is invalid and has been touched or modified.
|
|
485
|
+
*/
|
|
486
|
+
/**
|
|
487
|
+
* Ids of the rendered error messages, space-separated, for `aria-describedby`. Mirrors the
|
|
488
|
+
* `{id}-error` / `{id}-{index}-error` ids `mn-error-message` renders in single and show-all mode.
|
|
489
|
+
*/
|
|
490
|
+
get errorDescribedBy() {
|
|
491
|
+
return this.props.showAllErrors
|
|
492
|
+
? this.errorMessages.map((_, index) => `${this.resolvedId}-${index}-error`).join(' ')
|
|
493
|
+
: `${this.resolvedId}-error`;
|
|
494
|
+
}
|
|
495
|
+
get showError() {
|
|
496
|
+
const c = this.control;
|
|
497
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Picks the error key to display based on errorPriority.
|
|
501
|
+
* Used when showAllErrors is false (default).
|
|
502
|
+
*
|
|
503
|
+
* @param errors - ValidationErrors object from the control
|
|
504
|
+
* @returns The error key to display
|
|
505
|
+
*/
|
|
506
|
+
pickErrorKey(errors) {
|
|
507
|
+
// If priority is specified, use the first matching error from the priority list
|
|
508
|
+
if (this.props.errorPriority) {
|
|
509
|
+
for (const key of this.props.errorPriority) {
|
|
510
|
+
if (errors[key] !== undefined) {
|
|
511
|
+
return key;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
// Otherwise, use the first error key
|
|
516
|
+
return Object.keys(errors)[0];
|
|
517
|
+
}
|
|
518
|
+
isRequired() {
|
|
519
|
+
if (!this.control)
|
|
520
|
+
return false;
|
|
521
|
+
return this.control.hasValidator(Validators.required);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Resolves a single error message for a specific error key.
|
|
525
|
+
* Checks custom messages, built-in messages, and fallback in order.
|
|
526
|
+
*
|
|
527
|
+
* @param errorKey - The error key (e.g., 'required', 'email')
|
|
528
|
+
* @param errors - All validation errors on the control
|
|
529
|
+
* @returns The resolved error message string
|
|
530
|
+
*/
|
|
531
|
+
resolveErrorMessageForKey(errorKey, errors) {
|
|
532
|
+
const errorArgs = errors[errorKey];
|
|
533
|
+
// Priority: custom (props) > config > built-in > fallback > default
|
|
534
|
+
const customMsg = this.props.errorMessages?.[errorKey];
|
|
535
|
+
const configMsg = this.uiConfig.errorMessages?.[errorKey];
|
|
536
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
537
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[errorKey] : undefined;
|
|
538
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
539
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
540
|
+
// If the message is a function, call it with error arguments
|
|
541
|
+
if (typeof msgDef === 'function') {
|
|
542
|
+
return msgDef(errorArgs, errors);
|
|
543
|
+
}
|
|
544
|
+
// Interpolate {{placeholder}} tokens with error arguments (e.g. {{requiredLength}})
|
|
545
|
+
if (errorArgs && typeof errorArgs === 'object') {
|
|
546
|
+
return msgDef.replace(/\{\{(\w+)}}/g, (_, key) => errorArgs[key] !== undefined ? String(errorArgs[key]) : `{{${key}}}`);
|
|
547
|
+
}
|
|
548
|
+
return msgDef;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Gets all error messages for the current control state.
|
|
552
|
+
* Returns an array of error messages (used when showAllErrors is true).
|
|
553
|
+
*
|
|
554
|
+
* @returns Array of error message strings
|
|
555
|
+
*/
|
|
556
|
+
get errorMessages() {
|
|
557
|
+
const errors = this.control?.errors;
|
|
558
|
+
if (!errors)
|
|
559
|
+
return [];
|
|
560
|
+
const errorKeys = Object.keys(errors);
|
|
561
|
+
return errorKeys.map(key => this.resolveErrorMessageForKey(key, errors));
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Gets a single error message for the current control state.
|
|
565
|
+
* Uses errorPriority to determine which error to show (when showAllErrors is false).
|
|
566
|
+
*
|
|
567
|
+
* @returns Single error message string, or null if no errors
|
|
568
|
+
*/
|
|
569
|
+
get errorMessage() {
|
|
570
|
+
const errors = this.control?.errors;
|
|
571
|
+
if (!errors)
|
|
572
|
+
return null;
|
|
573
|
+
const errorKey = this.pickErrorKey(errors);
|
|
574
|
+
return this.resolveErrorMessageForKey(errorKey, errors);
|
|
575
|
+
}
|
|
576
|
+
// ========== Resolved Properties ==========
|
|
577
|
+
/** Resolved ID for the input element */
|
|
578
|
+
get resolvedId() {
|
|
579
|
+
return this.props.id;
|
|
580
|
+
}
|
|
581
|
+
/** Resolved name attribute for the input element */
|
|
582
|
+
get resolvedName() {
|
|
583
|
+
return this.props?.name ?? null;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Computes the CSS classes from tailwind-variants based on the props.
|
|
587
|
+
* Returns the variant classes for styling the input element.
|
|
588
|
+
*/
|
|
589
|
+
get inputClasses() {
|
|
590
|
+
return mnInputFieldVariants({
|
|
591
|
+
size: this.props.size,
|
|
592
|
+
borderRadius: this.props.borderRadius,
|
|
593
|
+
shadow: this.props.shadow,
|
|
594
|
+
fullWidth: this.props.fullWidth,
|
|
595
|
+
hover: this.isDisabled ? false : this.props.hover,
|
|
596
|
+
disabled: this.isDisabled,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnInputField, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
600
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnInputField, isStandalone: true, selector: "mn-lib-input-field", inputs: { props: "props" }, host: { properties: { "style.display": "props?.fullWidth ? 'block' : null", "style.width": "props?.fullWidth ? '100%' : null" } }, ngImport: i0, template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n <!-- Label -->\n @if (uiConfig.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Input Element -->\n <input\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [type]=\"props.type\"\n [attr.placeholder]=\"uiConfig.placeholder || null\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? errorDescribedBy : null\"\n [attr.aria-activedescendant]=\"props.ariaActiveDescendant || null\"\n [disabled]=\"isDisabled\"\n [attr.autocomplete]=\"props.autocomplete || null\"\n [attr.min]=\"minAttr\"\n [attr.max]=\"maxAttr\"\n [ngModel]=\"value\"\n [ngClass]=\"inputClasses\"\n (input)=\"handleInput(($any($event.target)).value)\"\n (search)=\"handleInput(($any($event.target)).value)\"\n (blur)=\"handleBlur()\"\n />\n\n <!-- Error Messages -->\n @if (showError) {\n <!-- Show all errors mode -->\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n\n }\n }\n }\n</div>\n", styles: ["input::-webkit-search-cancel-button{cursor:pointer}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
|
|
601
|
+
}
|
|
602
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnInputField, decorators: [{
|
|
603
|
+
type: Component,
|
|
604
|
+
args: [{ selector: 'mn-lib-input-field', standalone: true, imports: [CommonModule, NgClass, MnErrorMessage, FormsModule], host: {
|
|
605
|
+
// Native inputs (notably `type="date"`) have a platform-specific intrinsic width.
|
|
606
|
+
// Without an explicit host width the inline host collapses to that intrinsic size,
|
|
607
|
+
// so the input's `w-full` (width:100%) resolves against a content-sized box and
|
|
608
|
+
// fails to fill the parent on real mobile devices (desktop devtools hides this
|
|
609
|
+
// because it still renders the control with the desktop engine). Give the host a
|
|
610
|
+
// real width when fullWidth is requested so 100% has something to fill.
|
|
611
|
+
'[style.display]': "props?.fullWidth ? 'block' : null",
|
|
612
|
+
'[style.width]': "props?.fullWidth ? '100%' : null",
|
|
613
|
+
}, template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n <!-- Label -->\n @if (uiConfig.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Input Element -->\n <input\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [type]=\"props.type\"\n [attr.placeholder]=\"uiConfig.placeholder || null\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? errorDescribedBy : null\"\n [attr.aria-activedescendant]=\"props.ariaActiveDescendant || null\"\n [disabled]=\"isDisabled\"\n [attr.autocomplete]=\"props.autocomplete || null\"\n [attr.min]=\"minAttr\"\n [attr.max]=\"maxAttr\"\n [ngModel]=\"value\"\n [ngClass]=\"inputClasses\"\n (input)=\"handleInput(($any($event.target)).value)\"\n (search)=\"handleInput(($any($event.target)).value)\"\n (blur)=\"handleBlur()\"\n />\n\n <!-- Error Messages -->\n @if (showError) {\n <!-- Show all errors mode -->\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n\n }\n }\n }\n</div>\n", styles: ["input::-webkit-search-cancel-button{cursor:pointer}\n"] }]
|
|
614
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
615
|
+
type: Input,
|
|
616
|
+
args: [{ required: true }]
|
|
617
|
+
}] } });
|
|
618
|
+
|
|
619
|
+
const mnCheckboxVariants = tv({
|
|
620
|
+
base: 'mn-checkbox',
|
|
621
|
+
variants: {
|
|
622
|
+
size: {
|
|
623
|
+
xs: 'size-4 p-0.5',
|
|
624
|
+
sm: 'size-5 p-[0.1875rem]',
|
|
625
|
+
md: 'size-6 p-1',
|
|
626
|
+
lg: 'size-7 p-[0.3125rem]',
|
|
627
|
+
xl: 'size-8 p-1.5',
|
|
628
|
+
},
|
|
629
|
+
color: {
|
|
630
|
+
primary: 'border-primary checked:bg-primary indeterminate:bg-primary focus-visible:outline-primary text-primary-content',
|
|
631
|
+
secondary: 'border-secondary checked:bg-secondary indeterminate:bg-secondary focus-visible:outline-secondary text-secondary-content',
|
|
632
|
+
accent: 'border-accent checked:bg-accent indeterminate:bg-accent focus-visible:outline-accent text-accent-content',
|
|
633
|
+
neutral: 'border-neutral checked:bg-neutral indeterminate:bg-neutral focus-visible:outline-neutral text-neutral-content',
|
|
634
|
+
info: 'border-info checked:bg-info indeterminate:bg-info focus-visible:outline-info text-info-content',
|
|
635
|
+
success: 'border-success checked:bg-success indeterminate:bg-success focus-visible:outline-success text-success-content',
|
|
636
|
+
warning: 'border-warning checked:bg-warning indeterminate:bg-warning focus-visible:outline-warning text-warning-content',
|
|
637
|
+
error: 'border-error checked:bg-error indeterminate:bg-error focus-visible:outline-error text-error-content',
|
|
638
|
+
},
|
|
639
|
+
borderRadius: {
|
|
640
|
+
none: 'rounded-none',
|
|
641
|
+
xs: 'rounded-xs',
|
|
642
|
+
sm: 'rounded-sm',
|
|
643
|
+
md: 'rounded-md',
|
|
644
|
+
lg: 'rounded-lg',
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
defaultVariants: {
|
|
648
|
+
size: 'md',
|
|
649
|
+
color: 'primary',
|
|
650
|
+
borderRadius: 'sm',
|
|
651
|
+
},
|
|
652
|
+
});
|
|
653
|
+
const mnCheckboxWrapperVariants = tv({
|
|
654
|
+
base: 'text-base-content',
|
|
655
|
+
variants: {
|
|
656
|
+
size: {
|
|
657
|
+
xs: 'text-sm',
|
|
658
|
+
sm: 'text-sm',
|
|
659
|
+
md: 'text-sm',
|
|
660
|
+
lg: 'text-base',
|
|
661
|
+
xl: 'text-base',
|
|
662
|
+
},
|
|
663
|
+
fullWidth: {
|
|
664
|
+
true: 'w-full',
|
|
665
|
+
},
|
|
666
|
+
hover: {
|
|
667
|
+
true: 'hover:bg-base-200 rounded-md transition-colors duration-200 ease-in-out px-2 -mx-2',
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
defaultVariants: {
|
|
671
|
+
size: 'md',
|
|
672
|
+
hover: false,
|
|
673
|
+
},
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
const MN_CHECKBOX_CONFIG = new InjectionToken('MN_CHECKBOX_CONFIG');
|
|
677
|
+
class MnCheckbox {
|
|
678
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
679
|
+
uiConfig = {};
|
|
680
|
+
props;
|
|
681
|
+
/** Direct checked binding for non-form usage */
|
|
682
|
+
checked;
|
|
683
|
+
/** Emits when checked state changes (for non-form usage) */
|
|
684
|
+
checkedChange = new EventEmitter();
|
|
685
|
+
configService = inject(MnConfigService);
|
|
686
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
687
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
688
|
+
lang = inject(MnLanguageService);
|
|
689
|
+
destroyRef = inject(DestroyRef);
|
|
690
|
+
value = false;
|
|
691
|
+
isDisabled = false;
|
|
692
|
+
onChange = () => {
|
|
693
|
+
};
|
|
694
|
+
onTouched = () => { };
|
|
695
|
+
builtInErrorMessages = {
|
|
696
|
+
required: 'This field is required',
|
|
697
|
+
};
|
|
698
|
+
constructor() {
|
|
699
|
+
if (this.ngControl)
|
|
700
|
+
this.ngControl.valueAccessor = this;
|
|
701
|
+
}
|
|
702
|
+
ngOnInit() {
|
|
703
|
+
this.resolveConfig();
|
|
704
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
705
|
+
this.resolveConfig();
|
|
706
|
+
});
|
|
707
|
+
this.destroyRef.onDestroy(() => sub.unsubscribe());
|
|
708
|
+
}
|
|
709
|
+
resolveConfig() {
|
|
710
|
+
const instanceId = this.explicitInstanceId || `mn-checkbox-${this.props.id}`;
|
|
711
|
+
this.uiConfig = this.configService.resolve('mn-checkbox', this.sectionPath, instanceId);
|
|
712
|
+
if (this.props.label) {
|
|
713
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
717
|
+
writeValue(val) {
|
|
718
|
+
this.value = !!val;
|
|
719
|
+
}
|
|
720
|
+
/** Sync value from checked input when not using forms */
|
|
721
|
+
ngOnChanges() {
|
|
722
|
+
if (this.checked !== undefined) {
|
|
723
|
+
this.value = this.checked;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
registerOnChange(fn) {
|
|
727
|
+
this.onChange = fn;
|
|
728
|
+
}
|
|
729
|
+
registerOnTouched(fn) {
|
|
730
|
+
this.onTouched = fn;
|
|
731
|
+
}
|
|
732
|
+
setDisabledState(isDisabled) {
|
|
733
|
+
this.isDisabled = isDisabled;
|
|
734
|
+
}
|
|
735
|
+
// ========== Event Handlers ==========
|
|
736
|
+
handleChange(checked) {
|
|
737
|
+
this.value = checked;
|
|
738
|
+
this.onChange(checked);
|
|
739
|
+
this.checkedChange.emit(checked);
|
|
740
|
+
}
|
|
741
|
+
handleBlur() {
|
|
742
|
+
this.onTouched();
|
|
743
|
+
}
|
|
744
|
+
// ========== Error Handling ==========
|
|
745
|
+
get control() {
|
|
746
|
+
return this.ngControl?.control ?? null;
|
|
747
|
+
}
|
|
748
|
+
get showError() {
|
|
749
|
+
const c = this.control;
|
|
750
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
751
|
+
}
|
|
752
|
+
pickErrorKey(errors) {
|
|
753
|
+
if (this.props.errorPriority) {
|
|
754
|
+
for (const key of this.props.errorPriority) {
|
|
755
|
+
if (errors[key] !== undefined) {
|
|
756
|
+
return key;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return Object.keys(errors)[0];
|
|
761
|
+
}
|
|
762
|
+
isRequired() {
|
|
763
|
+
if (!this.control)
|
|
764
|
+
return false;
|
|
765
|
+
return this.control.hasValidator(Validators.required);
|
|
766
|
+
}
|
|
767
|
+
resolveErrorMessageForKey(errorKey, errors) {
|
|
768
|
+
const errorArgs = errors[errorKey];
|
|
769
|
+
const customMsg = this.props.errorMessages?.[errorKey];
|
|
770
|
+
const configMsg = this.uiConfig.errorMessages?.[errorKey];
|
|
771
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
772
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[errorKey] : undefined;
|
|
773
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
774
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
775
|
+
if (typeof msgDef === 'function') {
|
|
776
|
+
return msgDef(errorArgs, errors);
|
|
777
|
+
}
|
|
778
|
+
return msgDef;
|
|
779
|
+
}
|
|
780
|
+
get errorMessages() {
|
|
781
|
+
const errors = this.control?.errors;
|
|
782
|
+
if (!errors)
|
|
783
|
+
return [];
|
|
784
|
+
return Object.keys(errors).map(key => this.resolveErrorMessageForKey(key, errors));
|
|
785
|
+
}
|
|
786
|
+
get errorMessage() {
|
|
787
|
+
const errors = this.control?.errors;
|
|
788
|
+
if (!errors)
|
|
789
|
+
return null;
|
|
790
|
+
const errorKey = this.pickErrorKey(errors);
|
|
791
|
+
return this.resolveErrorMessageForKey(errorKey, errors);
|
|
792
|
+
}
|
|
793
|
+
// ========== Resolved Properties ==========
|
|
794
|
+
get resolvedId() {
|
|
795
|
+
return this.props.id;
|
|
796
|
+
}
|
|
797
|
+
get resolvedName() {
|
|
798
|
+
return this.props?.name ?? null;
|
|
799
|
+
}
|
|
800
|
+
get checkboxClasses() {
|
|
801
|
+
return mnCheckboxVariants({
|
|
802
|
+
size: this.props.size,
|
|
803
|
+
color: this.props.color,
|
|
804
|
+
borderRadius: this.props.borderRadius,
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
get wrapperClasses() {
|
|
808
|
+
return mnCheckboxWrapperVariants({
|
|
809
|
+
size: this.props.size,
|
|
810
|
+
fullWidth: this.props.fullWidth,
|
|
811
|
+
hover: this.props.hover,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnCheckbox, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
815
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnCheckbox, isStandalone: true, selector: "mn-lib-checkbox", inputs: { props: "props", checked: "checked" }, outputs: { checkedChange: "checkedChange" }, usesOnChanges: true, ngImport: i0, template: "<div [class.is-fullwidth]=\"props.fullWidth\" class=\"flex flex-col items-start\">\n <label [attr.for]=\"resolvedId\" [ngClass]=\"wrapperClasses\"\n class=\"flex flex-row items-center gap-x-2 select-none cursor-pointer\">\n <input\n type=\"checkbox\"\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || props.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [disabled]=\"isDisabled\"\n [checked]=\"value\"\n [ngClass]=\"checkboxClasses\"\n (change)=\"handleChange($any($event.target).checked)\"\n (blur)=\"handleBlur()\"\n />\n @if (uiConfig.label || props.label) {\n <span class=\"flex flex-row items-center gap-x-0.5\">\n <span>{{ uiConfig.label || props.label }}</span>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </span>\n }\n </label>\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1 mt-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n", styles: [".mn-checkbox{position:relative;display:inline-block;flex-shrink:0;box-sizing:border-box;vertical-align:middle;cursor:pointer;appearance:none;-webkit-appearance:none;border-width:1px;border-style:solid;box-shadow:0 1px #0000001a inset,0 0 #0000 inset,0 0 #0000;transition:background-color .2s,box-shadow .2s}.mn-checkbox:before{content:\"\";display:block;width:100%;height:100%;rotate:45deg;background-color:currentColor;opacity:0;box-shadow:0 3px #ffffff1a inset;clip-path:polygon(20% 100%,20% 80%,50% 80%,50% 80%,70% 80%,70% 100%);transition:clip-path .3s,opacity .1s,rotate .3s,translate .3s;transition-delay:.1s}.mn-checkbox:focus-visible{outline-width:2px;outline-style:solid;outline-offset:2px}.mn-checkbox:checked,.mn-checkbox[aria-checked=true]{box-shadow:0 0 #0000 inset,0 8px 0 -4px #ffffff1a inset,0 1px #0000001a}.mn-checkbox:checked:before,.mn-checkbox[aria-checked=true]:before{opacity:1;clip-path:polygon(20% 100%,20% 80%,50% 80%,50% 0%,70% 0%,70% 100%)}.mn-checkbox:indeterminate:before{opacity:1;rotate:0deg;translate:0 -35%;clip-path:polygon(20% 100%,20% 80%,50% 80%,50% 80%,80% 80%,80% 100%)}.mn-checkbox:disabled{cursor:not-allowed;opacity:.2}\n"], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }] });
|
|
816
|
+
}
|
|
817
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnCheckbox, decorators: [{
|
|
818
|
+
type: Component,
|
|
819
|
+
args: [{ selector: 'mn-lib-checkbox', standalone: true, imports: [NgClass, MnErrorMessage], template: "<div [class.is-fullwidth]=\"props.fullWidth\" class=\"flex flex-col items-start\">\n <label [attr.for]=\"resolvedId\" [ngClass]=\"wrapperClasses\"\n class=\"flex flex-row items-center gap-x-2 select-none cursor-pointer\">\n <input\n type=\"checkbox\"\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || props.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [disabled]=\"isDisabled\"\n [checked]=\"value\"\n [ngClass]=\"checkboxClasses\"\n (change)=\"handleChange($any($event.target).checked)\"\n (blur)=\"handleBlur()\"\n />\n @if (uiConfig.label || props.label) {\n <span class=\"flex flex-row items-center gap-x-0.5\">\n <span>{{ uiConfig.label || props.label }}</span>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </span>\n }\n </label>\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1 mt-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n", styles: [".mn-checkbox{position:relative;display:inline-block;flex-shrink:0;box-sizing:border-box;vertical-align:middle;cursor:pointer;appearance:none;-webkit-appearance:none;border-width:1px;border-style:solid;box-shadow:0 1px #0000001a inset,0 0 #0000 inset,0 0 #0000;transition:background-color .2s,box-shadow .2s}.mn-checkbox:before{content:\"\";display:block;width:100%;height:100%;rotate:45deg;background-color:currentColor;opacity:0;box-shadow:0 3px #ffffff1a inset;clip-path:polygon(20% 100%,20% 80%,50% 80%,50% 80%,70% 80%,70% 100%);transition:clip-path .3s,opacity .1s,rotate .3s,translate .3s;transition-delay:.1s}.mn-checkbox:focus-visible{outline-width:2px;outline-style:solid;outline-offset:2px}.mn-checkbox:checked,.mn-checkbox[aria-checked=true]{box-shadow:0 0 #0000 inset,0 8px 0 -4px #ffffff1a inset,0 1px #0000001a}.mn-checkbox:checked:before,.mn-checkbox[aria-checked=true]:before{opacity:1;clip-path:polygon(20% 100%,20% 80%,50% 80%,50% 0%,70% 0%,70% 100%)}.mn-checkbox:indeterminate:before{opacity:1;rotate:0deg;translate:0 -35%;clip-path:polygon(20% 100%,20% 80%,50% 80%,50% 80%,80% 80%,80% 100%)}.mn-checkbox:disabled{cursor:not-allowed;opacity:.2}\n"] }]
|
|
820
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
821
|
+
type: Input,
|
|
822
|
+
args: [{ required: true }]
|
|
823
|
+
}], checked: [{
|
|
824
|
+
type: Input
|
|
825
|
+
}], checkedChange: [{
|
|
826
|
+
type: Output
|
|
827
|
+
}] } });
|
|
828
|
+
|
|
829
|
+
const mnTextareaVariants = tv({
|
|
830
|
+
base: 'bg-base-100 border-1 border-base-300 placeholder-base-content/50 text-base-content text-sm outline-none focus:ring-1 focus:ring-primary',
|
|
831
|
+
variants: {
|
|
832
|
+
shadow: {
|
|
833
|
+
true: 'shadow-lg',
|
|
834
|
+
},
|
|
835
|
+
size: {
|
|
836
|
+
sm: 'p-2',
|
|
837
|
+
md: 'p-3',
|
|
838
|
+
lg: 'p-4',
|
|
839
|
+
},
|
|
840
|
+
borderRadius: {
|
|
841
|
+
none: 'rounded-none',
|
|
842
|
+
xs: 'rounded-xs',
|
|
843
|
+
sm: 'rounded-sm',
|
|
844
|
+
md: 'rounded-md',
|
|
845
|
+
lg: 'rounded-lg',
|
|
846
|
+
xl: 'rounded-xl',
|
|
847
|
+
two_xl: 'rounded-2xl',
|
|
848
|
+
three_xl: 'rounded-3xl',
|
|
849
|
+
four_xl: 'rounded-4xl',
|
|
850
|
+
},
|
|
851
|
+
fullWidth: {
|
|
852
|
+
true: 'w-full',
|
|
853
|
+
},
|
|
854
|
+
resize: {
|
|
855
|
+
none: 'resize-none',
|
|
856
|
+
vertical: 'resize-y',
|
|
857
|
+
horizontal: 'resize-x',
|
|
858
|
+
both: 'resize',
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
defaultVariants: {
|
|
862
|
+
size: 'md',
|
|
863
|
+
borderRadius: 'md',
|
|
864
|
+
resize: 'vertical',
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
const MN_TEXTAREA_CONFIG = new InjectionToken('MN_TEXTAREA_CONFIG');
|
|
869
|
+
/**
|
|
870
|
+
* MnTextarea Component
|
|
871
|
+
*
|
|
872
|
+
* A flexible, accessible textarea component that implements Angular's ControlValueAccessor
|
|
873
|
+
* and Validator interfaces. Works similarly to MnInputField but uses a textarea element,
|
|
874
|
+
* allowing users to set the height (rows), width (cols), and resize behavior.
|
|
875
|
+
*
|
|
876
|
+
* Features:
|
|
877
|
+
* - Works with Angular Reactive Forms (FormControl, FormGroup)
|
|
878
|
+
* - Configurable rows, cols, and resize behavior
|
|
879
|
+
* - Built-in error messages with internationalization support
|
|
880
|
+
* - Custom error messages per field
|
|
881
|
+
* - Priority-based error display or show all errors
|
|
882
|
+
* - Full accessibility (ARIA attributes)
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```typescript
|
|
886
|
+
* <mn-textarea
|
|
887
|
+
* formControlName="description"
|
|
888
|
+
* [props]="{
|
|
889
|
+
* id: 'description',
|
|
890
|
+
* rows: 5,
|
|
891
|
+
* label: 'Description',
|
|
892
|
+
* size: 'md',
|
|
893
|
+
* borderRadius: 'md',
|
|
894
|
+
* resize: 'vertical',
|
|
895
|
+
* errorMessages: { required: 'Description is required' }
|
|
896
|
+
* }"
|
|
897
|
+
* ></mn-textarea>
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
class MnTextarea {
|
|
901
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
902
|
+
/** Resolved UI configuration for the textarea */
|
|
903
|
+
uiConfig = {};
|
|
904
|
+
el = inject(ElementRef);
|
|
905
|
+
/** Configuration properties for the textarea */
|
|
906
|
+
props;
|
|
907
|
+
configService = inject(MnConfigService);
|
|
908
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
909
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
910
|
+
lang = inject(MnLanguageService);
|
|
911
|
+
destroyRef = inject(DestroyRef);
|
|
912
|
+
/** Current raw string value of the textarea element */
|
|
913
|
+
value = null;
|
|
914
|
+
/** Whether the textarea is disabled */
|
|
915
|
+
isDisabled = false;
|
|
916
|
+
/** Callback function to notify Angular forms of value changes */
|
|
917
|
+
onChange = () => {
|
|
918
|
+
};
|
|
919
|
+
/** Callback function to notify Angular forms when textarea is touched/blurred */
|
|
920
|
+
onTouched = () => { };
|
|
921
|
+
/**
|
|
922
|
+
* Built-in default error messages in English.
|
|
923
|
+
* These are used when useBuiltInErrorMessages is true (default).
|
|
924
|
+
* Can be overridden per-field using props.errorMessages.
|
|
925
|
+
*/
|
|
926
|
+
builtInErrorMessages = {
|
|
927
|
+
required: 'This field is required',
|
|
928
|
+
minlength: (args) => `Minimum ${args.requiredLength} characters required`,
|
|
929
|
+
maxlength: (args) => `Maximum ${args.requiredLength} characters allowed`,
|
|
930
|
+
};
|
|
931
|
+
/**
|
|
932
|
+
* Constructor - Registers this component as the ControlValueAccessor
|
|
933
|
+
* for the injected NgControl (FormControl).
|
|
934
|
+
*
|
|
935
|
+
*/
|
|
936
|
+
constructor() {
|
|
937
|
+
if (this.ngControl)
|
|
938
|
+
this.ngControl.valueAccessor = this;
|
|
939
|
+
}
|
|
940
|
+
ngOnInit() {
|
|
941
|
+
this.resolveConfig();
|
|
942
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
943
|
+
this.resolveConfig();
|
|
944
|
+
});
|
|
945
|
+
this.destroyRef.onDestroy(() => sub.unsubscribe());
|
|
946
|
+
if (this.props.autoFocus) {
|
|
947
|
+
setTimeout(() => this.focus(), 0);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Focuses the textarea element.
|
|
952
|
+
*/
|
|
953
|
+
focus() {
|
|
954
|
+
const textarea = this.el.nativeElement.querySelector('textarea');
|
|
955
|
+
if (textarea)
|
|
956
|
+
textarea.focus();
|
|
957
|
+
}
|
|
958
|
+
resolveConfig() {
|
|
959
|
+
const instanceId = this.explicitInstanceId || `mn-textarea-${this.props.id}`;
|
|
960
|
+
this.uiConfig = this.configService.resolve('mn-textarea', this.sectionPath, instanceId);
|
|
961
|
+
// Allow props to override uiConfig for label and placeholder
|
|
962
|
+
if (this.props.label) {
|
|
963
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
964
|
+
}
|
|
965
|
+
if (this.props.placeholder) {
|
|
966
|
+
this.uiConfig = { ...this.uiConfig, placeholder: this.props.placeholder };
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
970
|
+
/**
|
|
971
|
+
* Writes a new value to the textarea element (called by Angular Forms).
|
|
972
|
+
*
|
|
973
|
+
* @param val - The value to write
|
|
974
|
+
*/
|
|
975
|
+
writeValue(val) {
|
|
976
|
+
this.value = val != null ? String(val) : null;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Registers a callback function to be called when the textarea value changes.
|
|
980
|
+
*
|
|
981
|
+
* @param fn - Callback function to notify Angular Forms of changes
|
|
982
|
+
*/
|
|
983
|
+
registerOnChange(fn) {
|
|
984
|
+
this.onChange = fn;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Registers a callback function to be called when the textarea is touched/blurred.
|
|
988
|
+
*
|
|
989
|
+
* @param fn - Callback function to notify Angular Forms of touch events
|
|
990
|
+
*/
|
|
991
|
+
registerOnTouched(fn) {
|
|
992
|
+
this.onTouched = fn;
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Sets the disabled state of the textarea element.
|
|
996
|
+
*
|
|
997
|
+
* @param isDisabled - Whether the textarea should be disabled
|
|
998
|
+
*/
|
|
999
|
+
setDisabledState(isDisabled) {
|
|
1000
|
+
this.isDisabled = isDisabled;
|
|
1001
|
+
}
|
|
1002
|
+
// ========== Event Handlers ==========
|
|
1003
|
+
/**
|
|
1004
|
+
* Handles input events from the textarea element.
|
|
1005
|
+
* Notifies Angular Forms of the new value.
|
|
1006
|
+
*
|
|
1007
|
+
* @param raw - Raw string value from the textarea element
|
|
1008
|
+
*/
|
|
1009
|
+
handleInput(raw) {
|
|
1010
|
+
this.value = raw;
|
|
1011
|
+
this.onChange(raw);
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Handles blur events from the textarea element.
|
|
1015
|
+
* Notifies Angular Forms that the textarea has been touched.
|
|
1016
|
+
*/
|
|
1017
|
+
handleBlur() {
|
|
1018
|
+
this.onTouched();
|
|
1019
|
+
}
|
|
1020
|
+
// ========== Error Handling ==========
|
|
1021
|
+
/**
|
|
1022
|
+
* Gets the FormControl instance from Angular Forms.
|
|
1023
|
+
* Returns null if no control is attached.
|
|
1024
|
+
*/
|
|
1025
|
+
get control() {
|
|
1026
|
+
return this.ngControl?.control ?? null;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Determines whether to show error messages.
|
|
1030
|
+
* Errors are shown when the control is invalid and has been touched or modified.
|
|
1031
|
+
*/
|
|
1032
|
+
/**
|
|
1033
|
+
* Ids of the rendered error messages, space-separated, for `aria-describedby`. Mirrors the
|
|
1034
|
+
* `{id}-error` / `{id}-{index}-error` ids `mn-error-message` renders in single and show-all mode.
|
|
1035
|
+
*/
|
|
1036
|
+
get errorDescribedBy() {
|
|
1037
|
+
return this.props.showAllErrors
|
|
1038
|
+
? this.errorMessages.map((_, index) => `${this.resolvedId}-${index}-error`).join(' ')
|
|
1039
|
+
: `${this.resolvedId}-error`;
|
|
1040
|
+
}
|
|
1041
|
+
get showError() {
|
|
1042
|
+
const c = this.control;
|
|
1043
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Picks the error key to display based on errorPriority.
|
|
1047
|
+
* Used when showAllErrors is false (default).
|
|
1048
|
+
*
|
|
1049
|
+
* @param errors - ValidationErrors object from the control
|
|
1050
|
+
* @returns The error key to display
|
|
1051
|
+
*/
|
|
1052
|
+
pickErrorKey(errors) {
|
|
1053
|
+
if (this.props.errorPriority) {
|
|
1054
|
+
for (const key of this.props.errorPriority) {
|
|
1055
|
+
if (errors[key] !== undefined) {
|
|
1056
|
+
return key;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return Object.keys(errors)[0];
|
|
1061
|
+
}
|
|
1062
|
+
isRequired() {
|
|
1063
|
+
if (!this.control)
|
|
1064
|
+
return false;
|
|
1065
|
+
return this.control.hasValidator(Validators.required);
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Resolves a single error message for a specific error key.
|
|
1069
|
+
*
|
|
1070
|
+
* @param errorKey - The error key (e.g., 'required', 'minlength')
|
|
1071
|
+
* @param errors - All validation errors on the control
|
|
1072
|
+
* @returns The resolved error message string
|
|
1073
|
+
*/
|
|
1074
|
+
resolveErrorMessageForKey(errorKey, errors) {
|
|
1075
|
+
const errorArgs = errors[errorKey];
|
|
1076
|
+
const customMsg = this.props.errorMessages?.[errorKey];
|
|
1077
|
+
const configMsg = this.uiConfig.errorMessages?.[errorKey];
|
|
1078
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
1079
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[errorKey] : undefined;
|
|
1080
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
1081
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
1082
|
+
if (typeof msgDef === 'function') {
|
|
1083
|
+
return msgDef(errorArgs, errors);
|
|
1084
|
+
}
|
|
1085
|
+
// Interpolate {{placeholder}} tokens with validation error args
|
|
1086
|
+
if (errorArgs && typeof errorArgs === 'object') {
|
|
1087
|
+
return msgDef.replace(/\{\{(\w+)}}/g, (_, key) => errorArgs[key] ?? _);
|
|
1088
|
+
}
|
|
1089
|
+
return msgDef;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Gets all error messages for the current control state.
|
|
1093
|
+
*
|
|
1094
|
+
* @returns Array of error message strings
|
|
1095
|
+
*/
|
|
1096
|
+
get errorMessages() {
|
|
1097
|
+
const errors = this.control?.errors;
|
|
1098
|
+
if (!errors)
|
|
1099
|
+
return [];
|
|
1100
|
+
const errorKeys = Object.keys(errors);
|
|
1101
|
+
return errorKeys.map(key => this.resolveErrorMessageForKey(key, errors));
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Gets a single error message for the current control state.
|
|
1105
|
+
*
|
|
1106
|
+
* @returns Single error message string, or null if no errors
|
|
1107
|
+
*/
|
|
1108
|
+
get errorMessage() {
|
|
1109
|
+
const errors = this.control?.errors;
|
|
1110
|
+
if (!errors)
|
|
1111
|
+
return null;
|
|
1112
|
+
const errorKey = this.pickErrorKey(errors);
|
|
1113
|
+
return this.resolveErrorMessageForKey(errorKey, errors);
|
|
1114
|
+
}
|
|
1115
|
+
// ========== Resolved Properties ==========
|
|
1116
|
+
/** Resolved ID for the textarea element */
|
|
1117
|
+
get resolvedId() {
|
|
1118
|
+
return this.props.id;
|
|
1119
|
+
}
|
|
1120
|
+
/** Resolved name attribute for the textarea element */
|
|
1121
|
+
get resolvedName() {
|
|
1122
|
+
return this.props?.name ?? null;
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* Computes the CSS classes from tailwind-variants based on the props.
|
|
1126
|
+
* Returns the variant classes for styling the textarea element.
|
|
1127
|
+
*/
|
|
1128
|
+
get textareaClasses() {
|
|
1129
|
+
return mnTextareaVariants({
|
|
1130
|
+
size: this.props.size,
|
|
1131
|
+
borderRadius: this.props.borderRadius,
|
|
1132
|
+
shadow: this.props.shadow,
|
|
1133
|
+
fullWidth: this.props.fullWidth,
|
|
1134
|
+
resize: this.props.resize,
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTextarea, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1138
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnTextarea, isStandalone: true, selector: "mn-lib-textarea", inputs: { props: "props" }, ngImport: i0, template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n <!-- Label -->\n @if (uiConfig.label || props.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Textarea Element -->\n <textarea\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [attr.placeholder]=\"uiConfig.placeholder || null\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? errorDescribedBy : null\"\n [disabled]=\"isDisabled\"\n [attr.autocomplete]=\"props.autocomplete || null\"\n [attr.rows]=\"props.rows ?? null\"\n [attr.cols]=\"props.cols ?? null\"\n [ngClass]=\"textareaClasses\"\n (input)=\"handleInput(($any($event.target)).value)\"\n (blur)=\"handleBlur()\"\n >{{ value ?? '' }}</textarea>\n\n <!-- Error Messages -->\n @if (showError) {\n <!-- Show all errors mode -->\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }] });
|
|
1139
|
+
}
|
|
1140
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTextarea, decorators: [{
|
|
1141
|
+
type: Component,
|
|
1142
|
+
args: [{ selector: 'mn-lib-textarea', standalone: true, imports: [NgClass, MnErrorMessage], template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n <!-- Label -->\n @if (uiConfig.label || props.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Textarea Element -->\n <textarea\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [attr.placeholder]=\"uiConfig.placeholder || null\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? errorDescribedBy : null\"\n [disabled]=\"isDisabled\"\n [attr.autocomplete]=\"props.autocomplete || null\"\n [attr.rows]=\"props.rows ?? null\"\n [attr.cols]=\"props.cols ?? null\"\n [ngClass]=\"textareaClasses\"\n (input)=\"handleInput(($any($event.target)).value)\"\n (blur)=\"handleBlur()\"\n >{{ value ?? '' }}</textarea>\n\n <!-- Error Messages -->\n @if (showError) {\n <!-- Show all errors mode -->\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n" }]
|
|
1143
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
1144
|
+
type: Input,
|
|
1145
|
+
args: [{ required: true }]
|
|
1146
|
+
}] } });
|
|
1147
|
+
|
|
1148
|
+
const mnDatetimeVariants = tv({
|
|
1149
|
+
base: 'bg-base-100 border-1 border-base-300 placeholder-base-content/50 cursor-pointer text-base-content text-sm',
|
|
1150
|
+
variants: {
|
|
1151
|
+
shadow: {
|
|
1152
|
+
true: 'shadow-lg',
|
|
1153
|
+
},
|
|
1154
|
+
size: {
|
|
1155
|
+
sm: 'px-2 py-1.5',
|
|
1156
|
+
md: 'px-3 py-2',
|
|
1157
|
+
lg: 'px-4 py-3',
|
|
1158
|
+
},
|
|
1159
|
+
borderRadius: {
|
|
1160
|
+
none: 'rounded-none',
|
|
1161
|
+
xs: 'rounded-xs',
|
|
1162
|
+
sm: 'rounded-sm',
|
|
1163
|
+
md: 'rounded-md',
|
|
1164
|
+
lg: 'rounded-lg',
|
|
1165
|
+
xl: 'rounded-xl',
|
|
1166
|
+
two_xl: 'rounded-2xl',
|
|
1167
|
+
three_xl: 'rounded-3xl',
|
|
1168
|
+
four_xl: 'rounded-4xl',
|
|
1169
|
+
},
|
|
1170
|
+
fullWidth: {
|
|
1171
|
+
true: 'w-full',
|
|
1172
|
+
},
|
|
1173
|
+
hover: {
|
|
1174
|
+
true: 'hover:cursor-pointer hover:bg-base-200 transition-colors duration-300 ease-in-out',
|
|
1175
|
+
},
|
|
1176
|
+
},
|
|
1177
|
+
defaultVariants: {
|
|
1178
|
+
size: 'md',
|
|
1179
|
+
borderRadius: 'md',
|
|
1180
|
+
hover: true,
|
|
1181
|
+
},
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
/** Lucide icons this file renders. */
|
|
1185
|
+
const ICONS$4 = lucideIcons({ CalendarDays: lucide.CalendarDays });
|
|
1186
|
+
const MN_DATETIME_CONFIG = new InjectionToken('MN_DATETIME_CONFIG');
|
|
1187
|
+
class MnDatetime {
|
|
1188
|
+
/** Lucide icons the template renders. */
|
|
1189
|
+
icons = ICONS$4;
|
|
1190
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
1191
|
+
uiConfig = {};
|
|
1192
|
+
props;
|
|
1193
|
+
configService = inject(MnConfigService);
|
|
1194
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
1195
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
1196
|
+
lang = inject(MnLanguageService);
|
|
1197
|
+
destroyRef = inject(DestroyRef);
|
|
1198
|
+
value = null;
|
|
1199
|
+
isDisabled = false;
|
|
1200
|
+
onChange = () => {
|
|
1201
|
+
};
|
|
1202
|
+
onTouched = () => { };
|
|
1203
|
+
builtInErrorMessages = {
|
|
1204
|
+
required: 'This field is required',
|
|
1205
|
+
mnMin: (args) => `Date/time must be from ${args.min} onwards`,
|
|
1206
|
+
mnMax: (args) => `Date/time must be up to ${args.max}`,
|
|
1207
|
+
};
|
|
1208
|
+
constructor() {
|
|
1209
|
+
if (this.ngControl)
|
|
1210
|
+
this.ngControl.valueAccessor = this;
|
|
1211
|
+
}
|
|
1212
|
+
ngOnInit() {
|
|
1213
|
+
this.resolveConfig();
|
|
1214
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
1215
|
+
this.resolveConfig();
|
|
1216
|
+
});
|
|
1217
|
+
this.destroyRef.onDestroy(() => sub.unsubscribe());
|
|
1218
|
+
}
|
|
1219
|
+
resolveConfig() {
|
|
1220
|
+
const instanceId = this.explicitInstanceId || `mn-datetime-${this.props.id}`;
|
|
1221
|
+
this.uiConfig = this.configService.resolve('mn-datetime', this.sectionPath, instanceId);
|
|
1222
|
+
if (this.props.label) {
|
|
1223
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
1224
|
+
}
|
|
1225
|
+
if (this.props.placeholder) {
|
|
1226
|
+
this.uiConfig = { ...this.uiConfig, placeholder: this.props.placeholder };
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
1230
|
+
writeValue(val) {
|
|
1231
|
+
if (val != null) {
|
|
1232
|
+
let str = String(val);
|
|
1233
|
+
// Convert ISO 8601 strings (e.g. "2025-01-01T10:00:00.000Z") to datetime-local format
|
|
1234
|
+
if (str.includes('T') && (str.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(str))) {
|
|
1235
|
+
const date = new Date(str);
|
|
1236
|
+
if (!isNaN(date.getTime())) {
|
|
1237
|
+
const pad = (n) => n.toString().padStart(2, '0');
|
|
1238
|
+
str = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
this.value = str;
|
|
1242
|
+
}
|
|
1243
|
+
else {
|
|
1244
|
+
this.value = null;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
registerOnChange(fn) {
|
|
1248
|
+
this.onChange = fn;
|
|
1249
|
+
}
|
|
1250
|
+
registerOnTouched(fn) {
|
|
1251
|
+
this.onTouched = fn;
|
|
1252
|
+
}
|
|
1253
|
+
setDisabledState(isDisabled) {
|
|
1254
|
+
this.isDisabled = isDisabled;
|
|
1255
|
+
}
|
|
1256
|
+
// ========== Event Handlers ==========
|
|
1257
|
+
handleInput(raw) {
|
|
1258
|
+
this.value = raw;
|
|
1259
|
+
this.onChange(raw);
|
|
1260
|
+
}
|
|
1261
|
+
handleBlur() {
|
|
1262
|
+
this.onTouched();
|
|
1263
|
+
}
|
|
1264
|
+
handleClick(input) {
|
|
1265
|
+
try {
|
|
1266
|
+
input.showPicker();
|
|
1267
|
+
}
|
|
1268
|
+
catch {
|
|
1269
|
+
// picker already open (icon click) or browser restriction
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
// ========== Error Handling ==========
|
|
1273
|
+
get control() {
|
|
1274
|
+
return this.ngControl?.control ?? null;
|
|
1275
|
+
}
|
|
1276
|
+
get showError() {
|
|
1277
|
+
const c = this.control;
|
|
1278
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
1279
|
+
}
|
|
1280
|
+
pickErrorKey(errors) {
|
|
1281
|
+
if (this.props.errorPriority) {
|
|
1282
|
+
for (const key of this.props.errorPriority) {
|
|
1283
|
+
if (errors[key] !== undefined) {
|
|
1284
|
+
return key;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
return Object.keys(errors)[0];
|
|
1289
|
+
}
|
|
1290
|
+
isRequired() {
|
|
1291
|
+
if (!this.control)
|
|
1292
|
+
return false;
|
|
1293
|
+
return this.control.hasValidator(Validators.required);
|
|
1294
|
+
}
|
|
1295
|
+
resolveErrorMessageForKey(errorKey, errors) {
|
|
1296
|
+
const errorArgs = errors[errorKey];
|
|
1297
|
+
const customMsg = this.props.errorMessages?.[errorKey];
|
|
1298
|
+
const configMsg = this.uiConfig.errorMessages?.[errorKey];
|
|
1299
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
1300
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[errorKey] : undefined;
|
|
1301
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
1302
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
1303
|
+
if (typeof msgDef === 'function') {
|
|
1304
|
+
return msgDef(errorArgs, errors);
|
|
1305
|
+
}
|
|
1306
|
+
return msgDef;
|
|
1307
|
+
}
|
|
1308
|
+
get errorMessages() {
|
|
1309
|
+
const errors = this.control?.errors;
|
|
1310
|
+
if (!errors)
|
|
1311
|
+
return [];
|
|
1312
|
+
return Object.keys(errors).map(key => this.resolveErrorMessageForKey(key, errors));
|
|
1313
|
+
}
|
|
1314
|
+
get errorMessage() {
|
|
1315
|
+
const errors = this.control?.errors;
|
|
1316
|
+
if (!errors)
|
|
1317
|
+
return null;
|
|
1318
|
+
const errorKey = this.pickErrorKey(errors);
|
|
1319
|
+
return this.resolveErrorMessageForKey(errorKey, errors);
|
|
1320
|
+
}
|
|
1321
|
+
// ========== Resolved Properties ==========
|
|
1322
|
+
get resolvedId() {
|
|
1323
|
+
return this.props.id;
|
|
1324
|
+
}
|
|
1325
|
+
get resolvedName() {
|
|
1326
|
+
return this.props?.name ?? null;
|
|
1327
|
+
}
|
|
1328
|
+
get resolvedMode() {
|
|
1329
|
+
return this.props.mode ?? 'datetime-local';
|
|
1330
|
+
}
|
|
1331
|
+
/** Whether the control renders as an icon-only button rather than a full input. */
|
|
1332
|
+
get iconOnly() {
|
|
1333
|
+
return this.props.iconOnly === true;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Accessible name for the input. Prefers an explicit ariaLabel/label; for the
|
|
1337
|
+
* icon-only variant — which has no visible text — it falls back to the
|
|
1338
|
+
* placeholder so the button is never left unnamed.
|
|
1339
|
+
*/
|
|
1340
|
+
get resolvedAriaLabel() {
|
|
1341
|
+
const explicit = this.uiConfig.ariaLabel || this.uiConfig.label || this.props.label;
|
|
1342
|
+
if (explicit)
|
|
1343
|
+
return explicit;
|
|
1344
|
+
return this.iconOnly ? (this.uiConfig.placeholder || this.props.placeholder || null) : null;
|
|
1345
|
+
}
|
|
1346
|
+
/** Lucide icon size (px) tracking the field size, used only in the icon-only variant. */
|
|
1347
|
+
get iconSize() {
|
|
1348
|
+
if (this.props.size === 'sm')
|
|
1349
|
+
return 16;
|
|
1350
|
+
if (this.props.size === 'lg')
|
|
1351
|
+
return 20;
|
|
1352
|
+
return 18;
|
|
1353
|
+
}
|
|
1354
|
+
get inputClasses() {
|
|
1355
|
+
// Icon-only: the input becomes a transparent click target filling the icon box,
|
|
1356
|
+
// which carries the visible styling. `iconBoxClasses` provides the box itself.
|
|
1357
|
+
if (this.iconOnly) {
|
|
1358
|
+
return 'absolute inset-0 h-full w-full cursor-pointer opacity-0';
|
|
1359
|
+
}
|
|
1360
|
+
return mnDatetimeVariants({
|
|
1361
|
+
size: this.props.size,
|
|
1362
|
+
borderRadius: this.props.borderRadius,
|
|
1363
|
+
shadow: this.props.shadow,
|
|
1364
|
+
fullWidth: this.props.fullWidth,
|
|
1365
|
+
hover: this.props.hover,
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Classes for the icon-only box: the same border/background/radius/hover the full
|
|
1370
|
+
* input would wear (reused from the variant), made a positioning context for the
|
|
1371
|
+
* overlaid input, with a `focus-within` ring standing in for the transparent
|
|
1372
|
+
* input's own focus outline.
|
|
1373
|
+
*/
|
|
1374
|
+
get iconBoxClasses() {
|
|
1375
|
+
return [
|
|
1376
|
+
mnDatetimeVariants({
|
|
1377
|
+
size: this.props.size,
|
|
1378
|
+
borderRadius: this.props.borderRadius,
|
|
1379
|
+
shadow: this.props.shadow,
|
|
1380
|
+
hover: this.props.hover,
|
|
1381
|
+
}),
|
|
1382
|
+
'relative inline-flex items-center justify-center text-base-content/70',
|
|
1383
|
+
'focus-within:outline-2 focus-within:outline-offset-2 focus-within:outline-primary',
|
|
1384
|
+
].join(' ');
|
|
1385
|
+
}
|
|
1386
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnDatetime, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1387
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnDatetime, isStandalone: true, selector: "mn-lib-datetime", inputs: { props: "props" }, host: { properties: { "style.display": "props?.fullWidth ? 'block' : null", "style.width": "props?.fullWidth ? '100%' : null" } }, ngImport: i0, template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n @if (uiConfig.label || props.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n @if (iconOnly) {\n <!--\n Icon-only variant: a bordered box holding a calendar icon, with the native\n input layered on top at zero opacity. The box carries the look (border,\n background, radius, hover, focus ring); the input stays a real, focusable\n form control that opens the picker on click. `focus-within` on the box\n surfaces the keyboard focus ring, since the input itself is transparent.\n -->\n <div [ngClass]=\"iconBoxClasses\">\n <svg [size]=\"iconSize\" [lucideIcon]=\"icons.CalendarDays\" aria-hidden=\"true\" class=\"pointer-events-none\"></svg>\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"></ng-container>\n </div>\n } @else {\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"></ng-container>\n }\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n\n<!-- Single input definition, rendered either bare or inside the icon box above,\n so both variants share exactly the same bindings and behaviour. -->\n<ng-template #inputTemplate>\n <input\n #dateInput\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [type]=\"resolvedMode\"\n [attr.placeholder]=\"uiConfig.placeholder || props.placeholder || null\"\n [attr.aria-label]=\"resolvedAriaLabel\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [disabled]=\"isDisabled\"\n [attr.min]=\"props.min || null\"\n [attr.max]=\"props.max || null\"\n [attr.step]=\"props.step || null\"\n [value]=\"value ?? ''\"\n [ngClass]=\"inputClasses\"\n (click)=\"handleClick(dateInput)\"\n (input)=\"handleInput(($any($event.target)).value)\"\n (blur)=\"handleBlur()\"\n />\n</ng-template>\n", styles: ["input::-webkit-calendar-picker-indicator{cursor:pointer}@media(pointer:coarse){input[type=date],input[type=datetime-local],input[type=time],input[type=month],input[type=week]{-webkit-appearance:none;appearance:none;min-width:0;box-sizing:border-box}}\n"], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }] });
|
|
1388
|
+
}
|
|
1389
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnDatetime, decorators: [{
|
|
1390
|
+
type: Component,
|
|
1391
|
+
args: [{ selector: 'mn-lib-datetime', standalone: true, imports: [NgClass, NgTemplateOutlet, MnErrorMessage, LucideDynamicIcon], host: {
|
|
1392
|
+
// Native date/time inputs have a platform-specific intrinsic width. Without an
|
|
1393
|
+
// explicit host width the inline host collapses to that intrinsic size, so the
|
|
1394
|
+
// input's `w-full` (width:100%) resolves against a content-sized box and fails to
|
|
1395
|
+
// fill the parent on real mobile devices (desktop devtools hides this because it
|
|
1396
|
+
// still renders the control with the desktop engine). Give the host a real width
|
|
1397
|
+
// when fullWidth is requested so 100% has something to fill.
|
|
1398
|
+
'[style.display]': "props?.fullWidth ? 'block' : null",
|
|
1399
|
+
'[style.width]': "props?.fullWidth ? '100%' : null",
|
|
1400
|
+
}, template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n @if (uiConfig.label || props.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n @if (iconOnly) {\n <!--\n Icon-only variant: a bordered box holding a calendar icon, with the native\n input layered on top at zero opacity. The box carries the look (border,\n background, radius, hover, focus ring); the input stays a real, focusable\n form control that opens the picker on click. `focus-within` on the box\n surfaces the keyboard focus ring, since the input itself is transparent.\n -->\n <div [ngClass]=\"iconBoxClasses\">\n <svg [size]=\"iconSize\" [lucideIcon]=\"icons.CalendarDays\" aria-hidden=\"true\" class=\"pointer-events-none\"></svg>\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"></ng-container>\n </div>\n } @else {\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"></ng-container>\n }\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n\n<!-- Single input definition, rendered either bare or inside the icon box above,\n so both variants share exactly the same bindings and behaviour. -->\n<ng-template #inputTemplate>\n <input\n #dateInput\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n [attr.name]=\"resolvedName\"\n [type]=\"resolvedMode\"\n [attr.placeholder]=\"uiConfig.placeholder || props.placeholder || null\"\n [attr.aria-label]=\"resolvedAriaLabel\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [disabled]=\"isDisabled\"\n [attr.min]=\"props.min || null\"\n [attr.max]=\"props.max || null\"\n [attr.step]=\"props.step || null\"\n [value]=\"value ?? ''\"\n [ngClass]=\"inputClasses\"\n (click)=\"handleClick(dateInput)\"\n (input)=\"handleInput(($any($event.target)).value)\"\n (blur)=\"handleBlur()\"\n />\n</ng-template>\n", styles: ["input::-webkit-calendar-picker-indicator{cursor:pointer}@media(pointer:coarse){input[type=date],input[type=datetime-local],input[type=time],input[type=month],input[type=week]{-webkit-appearance:none;appearance:none;min-width:0;box-sizing:border-box}}\n"] }]
|
|
1401
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
1402
|
+
type: Input,
|
|
1403
|
+
args: [{ required: true }]
|
|
1404
|
+
}] } });
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* Tailwind-variants definition for the MnFileInput component.
|
|
1408
|
+
*
|
|
1409
|
+
* Mirrors the styling vocabulary of {@link mnInputFieldVariants} (size,
|
|
1410
|
+
* borderRadius, shadow, fullWidth, disabled) so a file input visually matches the
|
|
1411
|
+
* rest of the input family, and adds a `dropzone` toggle for the large dashed
|
|
1412
|
+
* drop area used by the default display mode plus a `dragging` toggle for the
|
|
1413
|
+
* "release to drop" state while files hover over that dropzone.
|
|
1414
|
+
*/
|
|
1415
|
+
const mnFileInputVariants = tv({
|
|
1416
|
+
base: 'bg-base-100 border-1 border-base-300 text-base-content text-sm outline-none transition-all duration-300 ease-in-out',
|
|
1417
|
+
variants: {
|
|
1418
|
+
/** Inner padding scale of the clickable control. */
|
|
1419
|
+
size: {
|
|
1420
|
+
sm: 'p-2',
|
|
1421
|
+
md: 'p-3',
|
|
1422
|
+
lg: 'p-4',
|
|
1423
|
+
},
|
|
1424
|
+
/** Corner rounding of the control. */
|
|
1425
|
+
borderRadius: {
|
|
1426
|
+
none: 'rounded-none',
|
|
1427
|
+
xs: 'rounded-xs',
|
|
1428
|
+
sm: 'rounded-sm',
|
|
1429
|
+
md: 'rounded-md',
|
|
1430
|
+
lg: 'rounded-lg',
|
|
1431
|
+
xl: 'rounded-xl',
|
|
1432
|
+
two_xl: 'rounded-2xl',
|
|
1433
|
+
three_xl: 'rounded-3xl',
|
|
1434
|
+
four_xl: 'rounded-4xl',
|
|
1435
|
+
},
|
|
1436
|
+
/** Drop shadow toggle. */
|
|
1437
|
+
shadow: {
|
|
1438
|
+
true: 'shadow-lg',
|
|
1439
|
+
},
|
|
1440
|
+
/** Stretch the control to the full width of its container. */
|
|
1441
|
+
fullWidth: {
|
|
1442
|
+
true: 'w-full',
|
|
1443
|
+
},
|
|
1444
|
+
/** Renders the control as a large dashed dropzone with a hover accent. */
|
|
1445
|
+
dropzone: {
|
|
1446
|
+
true: 'flex flex-col items-center justify-center gap-2 p-6 border-2 border-dashed text-center cursor-pointer hover:border-primary',
|
|
1447
|
+
},
|
|
1448
|
+
/** Highlighted "release to drop" appearance while files hover the dropzone. */
|
|
1449
|
+
dragging: {
|
|
1450
|
+
true: 'border-primary bg-primary/10 ring-4 ring-primary/20 scale-[1.01] duration-150',
|
|
1451
|
+
},
|
|
1452
|
+
/** Dimmed, non-interactive appearance. */
|
|
1453
|
+
disabled: {
|
|
1454
|
+
true: 'opacity-50 cursor-not-allowed pointer-events-none',
|
|
1455
|
+
},
|
|
1456
|
+
},
|
|
1457
|
+
defaultVariants: {
|
|
1458
|
+
size: 'md',
|
|
1459
|
+
borderRadius: 'lg',
|
|
1460
|
+
},
|
|
1461
|
+
});
|
|
1462
|
+
|
|
1463
|
+
/** Lucide icons this file renders. */
|
|
1464
|
+
const ICONS$3 = lucideIcons({
|
|
1465
|
+
File: lucide.File,
|
|
1466
|
+
ImagePlus: lucide.ImagePlus,
|
|
1467
|
+
Trash2: lucide.Trash2,
|
|
1468
|
+
Upload: lucide.Upload,
|
|
1469
|
+
X: lucide.X,
|
|
1470
|
+
});
|
|
1471
|
+
/**
|
|
1472
|
+
* MnFileInput Component
|
|
1473
|
+
*
|
|
1474
|
+
* A generic, accessible file input that implements Angular's ControlValueAccessor.
|
|
1475
|
+
* It styles selection to match the rest of the input family, shows image previews
|
|
1476
|
+
* (and a file icon + name for non-images), supports single or multiple selection,
|
|
1477
|
+
* several display layouts, and client-side `accept` / `maxSize` / `maxFiles` limits.
|
|
1478
|
+
*
|
|
1479
|
+
* Every display mode but `compact` is also a real drop target: dragging files
|
|
1480
|
+
* over it switches the area to a highlighted "release to drop" state, and
|
|
1481
|
+
* dropping runs the files through the same validation as the file picker.
|
|
1482
|
+
*
|
|
1483
|
+
* The form control value is the plain selection: `File | null` (single) or
|
|
1484
|
+
* `File[]` (multiple). An optional `currentUrl`/`currentUrls` renders an
|
|
1485
|
+
* already-saved image; removing it leaves the value untouched and emits `cleared`.
|
|
1486
|
+
*
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```html
|
|
1489
|
+
* <mn-lib-file-input
|
|
1490
|
+
* formControlName="image"
|
|
1491
|
+
* [props]="{ id: 'image', label: 'Cover', accept: 'image/*', displayMode: 'dropzone' }"
|
|
1492
|
+
* (cleared)="onRemoveExisting()">
|
|
1493
|
+
* </mn-lib-file-input>
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
class MnFileInput {
|
|
1497
|
+
/** Lucide icons the template renders. */
|
|
1498
|
+
icons = ICONS$3;
|
|
1499
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
1500
|
+
/** Configuration properties for the file input. */
|
|
1501
|
+
props;
|
|
1502
|
+
/** Emits whenever the selected file(s) change (in addition to the form control). */
|
|
1503
|
+
filesChange = new EventEmitter();
|
|
1504
|
+
/** Emits when the user removes an already-saved image (`currentUrl(s)`). */
|
|
1505
|
+
cleared = new EventEmitter();
|
|
1506
|
+
/** Resolved UI configuration for the file input. */
|
|
1507
|
+
uiConfig = {};
|
|
1508
|
+
/** Currently selected files (always an array internally). */
|
|
1509
|
+
files = signal([], ...(ngDevMode ? [{ debugName: "files" }] : []));
|
|
1510
|
+
/** True while files are dragged over the dropzone ("release to drop" state). */
|
|
1511
|
+
isDragging = signal(false, ...(ngDevMode ? [{ debugName: "isDragging" }] : []));
|
|
1512
|
+
/** Transient message for a rejected selection (accept/maxSize/maxFiles). */
|
|
1513
|
+
internalError = signal(null, ...(ngDevMode ? [{ debugName: "internalError" }] : []));
|
|
1514
|
+
configService = inject(MnConfigService);
|
|
1515
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
1516
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
1517
|
+
lang = inject(MnLanguageService);
|
|
1518
|
+
destroyRef = inject(DestroyRef);
|
|
1519
|
+
/** Object-URL previews aligned to {@link files}; null for non-image entries. */
|
|
1520
|
+
previewUrls = signal([], ...(ngDevMode ? [{ debugName: "previewUrls" }] : []));
|
|
1521
|
+
/** True once the user removed the single existing image. */
|
|
1522
|
+
currentCleared = signal(false, ...(ngDevMode ? [{ debugName: "currentCleared" }] : []));
|
|
1523
|
+
/** Indices of removed existing images (multiple mode). */
|
|
1524
|
+
removedExisting = signal(new Set(), ...(ngDevMode ? [{ debugName: "removedExisting" }] : []));
|
|
1525
|
+
/** Renderable entries: existing images (when nothing newer hides them) then new files. */
|
|
1526
|
+
displayItems = computed(() => {
|
|
1527
|
+
const items = [];
|
|
1528
|
+
if (this.props.multiple) {
|
|
1529
|
+
const urls = this.props.currentUrls ?? [];
|
|
1530
|
+
const removed = this.removedExisting();
|
|
1531
|
+
urls.forEach((url, i) => {
|
|
1532
|
+
if (!removed.has(i))
|
|
1533
|
+
items.push(this.existingItem(url, i));
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
else if (this.files().length === 0 && this.props.currentUrl && !this.currentCleared()) {
|
|
1537
|
+
items.push(this.existingItem(this.props.currentUrl, 0));
|
|
1538
|
+
}
|
|
1539
|
+
const previews = this.previewUrls();
|
|
1540
|
+
this.files().forEach((file, i) => {
|
|
1541
|
+
items.push({
|
|
1542
|
+
name: file.name,
|
|
1543
|
+
isImage: this.isImage(file),
|
|
1544
|
+
previewUrl: previews[i] ?? null,
|
|
1545
|
+
sizeLabel: this.humanFileSize(file.size),
|
|
1546
|
+
index: i,
|
|
1547
|
+
existing: false,
|
|
1548
|
+
});
|
|
1549
|
+
});
|
|
1550
|
+
return items;
|
|
1551
|
+
}, ...(ngDevMode ? [{ debugName: "displayItems" }] : []));
|
|
1552
|
+
/** Disabled state pushed by the forms API. */
|
|
1553
|
+
formDisabled = false;
|
|
1554
|
+
/**
|
|
1555
|
+
* Nesting depth of the current drag, so that moving across child elements of
|
|
1556
|
+
* the dropzone does not flicker {@link isDragging} off and on again.
|
|
1557
|
+
*/
|
|
1558
|
+
dragDepth = 0;
|
|
1559
|
+
/**
|
|
1560
|
+
* Built-in default error messages in English.
|
|
1561
|
+
* Used when `useBuiltInErrorMessages` is true (default); overridable per-field.
|
|
1562
|
+
*/
|
|
1563
|
+
builtInErrorMessages = {
|
|
1564
|
+
required: 'This field is required',
|
|
1565
|
+
accept: 'This file type is not allowed',
|
|
1566
|
+
maxSize: (args) => `File is too large (max ${args.max})`,
|
|
1567
|
+
maxFiles: (args) => `Too many files (max ${args.max})`,
|
|
1568
|
+
};
|
|
1569
|
+
/** Registers this component as the ControlValueAccessor for the injected control. */
|
|
1570
|
+
constructor() {
|
|
1571
|
+
if (this.ngControl)
|
|
1572
|
+
this.ngControl.valueAccessor = this;
|
|
1573
|
+
}
|
|
1574
|
+
/** The effective display mode. */
|
|
1575
|
+
get displayMode() {
|
|
1576
|
+
return this.props.displayMode ?? 'dropzone';
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Whether the current display mode acts as a drop target. `compact` is an
|
|
1580
|
+
* inline button sized for a form row, too small to aim a drag at.
|
|
1581
|
+
*/
|
|
1582
|
+
get supportsDrop() {
|
|
1583
|
+
return this.displayMode !== 'compact';
|
|
1584
|
+
}
|
|
1585
|
+
/** Whether the control is disabled (via props or the forms API). */
|
|
1586
|
+
get isDisabled() {
|
|
1587
|
+
return this.formDisabled || !!this.props.disabled;
|
|
1588
|
+
}
|
|
1589
|
+
/** Native `accept` attribute value, or null for no restriction when unset. */
|
|
1590
|
+
get acceptAttr() {
|
|
1591
|
+
return this.props.accept ?? null;
|
|
1592
|
+
}
|
|
1593
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
1594
|
+
/** Resolved id for the file input element. */
|
|
1595
|
+
get resolvedId() {
|
|
1596
|
+
return this.props.id;
|
|
1597
|
+
}
|
|
1598
|
+
/** Resolved name attribute for the file input element. */
|
|
1599
|
+
get resolvedName() {
|
|
1600
|
+
return this.props.name ?? null;
|
|
1601
|
+
}
|
|
1602
|
+
/** Tailwind-variant classes for the clickable control. */
|
|
1603
|
+
get controlClasses() {
|
|
1604
|
+
return mnFileInputVariants({
|
|
1605
|
+
size: this.props.size,
|
|
1606
|
+
borderRadius: this.props.borderRadius,
|
|
1607
|
+
shadow: this.props.shadow,
|
|
1608
|
+
fullWidth: this.props.fullWidth ?? (this.displayMode !== 'compact'),
|
|
1609
|
+
dropzone: this.displayMode === 'dropzone',
|
|
1610
|
+
dragging: this.isDragging(),
|
|
1611
|
+
disabled: this.isDisabled,
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
/** The attached form control, if any. */
|
|
1615
|
+
get control() {
|
|
1616
|
+
return this.ngControl?.control ?? null;
|
|
1617
|
+
}
|
|
1618
|
+
// ========== Selection handling ==========
|
|
1619
|
+
/** Whether to show control validation errors. */
|
|
1620
|
+
get showError() {
|
|
1621
|
+
const c = this.control;
|
|
1622
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
1623
|
+
}
|
|
1624
|
+
/** All control error messages (used when `showAllErrors` is true). */
|
|
1625
|
+
get errorMessages() {
|
|
1626
|
+
const errors = this.control?.errors;
|
|
1627
|
+
if (!errors)
|
|
1628
|
+
return [];
|
|
1629
|
+
return Object.keys(errors).map((key) => this.resolveControlError(key, errors));
|
|
1630
|
+
}
|
|
1631
|
+
/** Single control error message (priority-aware). */
|
|
1632
|
+
get errorMessage() {
|
|
1633
|
+
const errors = this.control?.errors;
|
|
1634
|
+
if (!errors)
|
|
1635
|
+
return null;
|
|
1636
|
+
return this.resolveControlError(this.pickErrorKey(errors), errors);
|
|
1637
|
+
}
|
|
1638
|
+
ngOnInit() {
|
|
1639
|
+
this.resolveConfig();
|
|
1640
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => this.resolveConfig());
|
|
1641
|
+
this.destroyRef.onDestroy(() => sub.unsubscribe());
|
|
1642
|
+
this.destroyRef.onDestroy(() => this.revokeAll());
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Writes a value from the form into the control.
|
|
1646
|
+
* @param val A `File`, an array of `File`, or null/undefined.
|
|
1647
|
+
*/
|
|
1648
|
+
writeValue(val) {
|
|
1649
|
+
const next = Array.isArray(val) ? val.filter((f) => f instanceof File)
|
|
1650
|
+
: val instanceof File ? [val]
|
|
1651
|
+
: [];
|
|
1652
|
+
this.setFiles(next);
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Registers the form's change callback.
|
|
1656
|
+
* @param fn Callback invoked with the new value.
|
|
1657
|
+
*/
|
|
1658
|
+
registerOnChange(fn) {
|
|
1659
|
+
this.onChange = fn;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Registers the form's touched callback.
|
|
1663
|
+
* @param fn Callback invoked when the control is touched.
|
|
1664
|
+
*/
|
|
1665
|
+
registerOnTouched(fn) {
|
|
1666
|
+
this.onTouched = fn;
|
|
1667
|
+
}
|
|
1668
|
+
// ========== Derived view state ==========
|
|
1669
|
+
/**
|
|
1670
|
+
* Sets the disabled state of the control.
|
|
1671
|
+
* @param isDisabled Whether the control should be disabled.
|
|
1672
|
+
*/
|
|
1673
|
+
setDisabledState(isDisabled) {
|
|
1674
|
+
this.formDisabled = isDisabled;
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Handles a file-picker change: validates the incoming files against the
|
|
1678
|
+
* configured limits and updates the selection.
|
|
1679
|
+
* @param event The native change event from the hidden file input.
|
|
1680
|
+
*/
|
|
1681
|
+
onFileSelected(event) {
|
|
1682
|
+
const input = event.target;
|
|
1683
|
+
const incoming = Array.from(input.files ?? []);
|
|
1684
|
+
input.value = '';
|
|
1685
|
+
if (incoming.length === 0)
|
|
1686
|
+
return;
|
|
1687
|
+
this.addFiles(incoming);
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Arms the "release to drop" state when a file drag enters the dropzone.
|
|
1691
|
+
* @param event The native dragenter event.
|
|
1692
|
+
*/
|
|
1693
|
+
onDragEnter(event) {
|
|
1694
|
+
if (!this.acceptsDrag(event))
|
|
1695
|
+
return;
|
|
1696
|
+
event.preventDefault();
|
|
1697
|
+
this.dragDepth++;
|
|
1698
|
+
this.isDragging.set(true);
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Keeps the drop target alive; without a prevented dragover the browser never
|
|
1702
|
+
* fires a drop event.
|
|
1703
|
+
* @param event The native dragover event.
|
|
1704
|
+
*/
|
|
1705
|
+
onDragOver(event) {
|
|
1706
|
+
if (!this.acceptsDrag(event))
|
|
1707
|
+
return;
|
|
1708
|
+
event.preventDefault();
|
|
1709
|
+
if (event.dataTransfer)
|
|
1710
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
1711
|
+
this.isDragging.set(true);
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Disarms the "release to drop" state once the drag has left the dropzone
|
|
1715
|
+
* entirely (and not merely crossed into one of its children).
|
|
1716
|
+
* @param event The native dragleave event.
|
|
1717
|
+
*/
|
|
1718
|
+
onDragLeave(event) {
|
|
1719
|
+
if (!this.isDragging())
|
|
1720
|
+
return;
|
|
1721
|
+
event.preventDefault();
|
|
1722
|
+
this.dragDepth = Math.max(0, this.dragDepth - 1);
|
|
1723
|
+
if (this.dragDepth === 0)
|
|
1724
|
+
this.isDragging.set(false);
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Accepts the dropped files through the same validation as the file picker.
|
|
1728
|
+
* @param event The native drop event.
|
|
1729
|
+
*/
|
|
1730
|
+
onDrop(event) {
|
|
1731
|
+
if (!this.acceptsDrag(event))
|
|
1732
|
+
return;
|
|
1733
|
+
event.preventDefault();
|
|
1734
|
+
this.resetDrag();
|
|
1735
|
+
const dropped = Array.from(event.dataTransfer?.files ?? []);
|
|
1736
|
+
if (dropped.length === 0)
|
|
1737
|
+
return;
|
|
1738
|
+
this.addFiles(dropped);
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Removes a newly-selected file by index.
|
|
1742
|
+
* @param index Index into the current selection.
|
|
1743
|
+
*/
|
|
1744
|
+
removeFile(index) {
|
|
1745
|
+
const next = this.files().filter((_, i) => i !== index);
|
|
1746
|
+
this.internalError.set(null);
|
|
1747
|
+
this.setFiles(next);
|
|
1748
|
+
this.emit();
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Removes an already-saved image and notifies the consumer via `cleared`.
|
|
1752
|
+
* @param index Index of the existing image (0 in single mode).
|
|
1753
|
+
*/
|
|
1754
|
+
removeExisting(index) {
|
|
1755
|
+
if (this.props.multiple) {
|
|
1756
|
+
const set = new Set(this.removedExisting());
|
|
1757
|
+
set.add(index);
|
|
1758
|
+
this.removedExisting.set(set);
|
|
1759
|
+
}
|
|
1760
|
+
else {
|
|
1761
|
+
this.currentCleared.set(true);
|
|
1762
|
+
}
|
|
1763
|
+
this.cleared.emit();
|
|
1764
|
+
this.onTouched();
|
|
1765
|
+
}
|
|
1766
|
+
/** Whether the attached control carries a `required` validator. */
|
|
1767
|
+
isRequired() {
|
|
1768
|
+
return this.control?.hasValidator(Validators.required) ?? false;
|
|
1769
|
+
}
|
|
1770
|
+
/** Stable track key for a display item across renders. */
|
|
1771
|
+
itemKey(item) {
|
|
1772
|
+
return `${item.existing ? 'e' : 'f'}-${item.index}`;
|
|
1773
|
+
}
|
|
1774
|
+
/** Whether a file should render as an image. */
|
|
1775
|
+
isImage(file) {
|
|
1776
|
+
return (file.type ?? '').startsWith('image/');
|
|
1777
|
+
}
|
|
1778
|
+
/** Callback to notify Angular forms of value changes. */
|
|
1779
|
+
onChange = () => {
|
|
1780
|
+
};
|
|
1781
|
+
// ========== Error handling (control validators) ==========
|
|
1782
|
+
/** Callback to notify Angular forms when the control is touched. */
|
|
1783
|
+
onTouched = () => {
|
|
1784
|
+
};
|
|
1785
|
+
/** Resolves UI strings from config, layering built-in defaults and prop overrides. */
|
|
1786
|
+
resolveConfig() {
|
|
1787
|
+
const instanceId = this.explicitInstanceId || `mn-file-input-${this.props.id}`;
|
|
1788
|
+
const resolved = this.configService.resolve('mn-file-input', this.sectionPath, instanceId);
|
|
1789
|
+
const builtIn = {
|
|
1790
|
+
dropzoneHint: 'Click to upload or drag and drop',
|
|
1791
|
+
dropActiveHint: 'Release to drop',
|
|
1792
|
+
replaceLabel: 'Replace',
|
|
1793
|
+
removeLabel: 'Remove',
|
|
1794
|
+
};
|
|
1795
|
+
this.uiConfig = { ...builtIn, ...resolved };
|
|
1796
|
+
if (this.props.label)
|
|
1797
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
1798
|
+
if (this.props.dropzoneHint)
|
|
1799
|
+
this.uiConfig = { ...this.uiConfig, dropzoneHint: this.props.dropzoneHint };
|
|
1800
|
+
if (this.props.dropActiveHint)
|
|
1801
|
+
this.uiConfig = { ...this.uiConfig, dropActiveHint: this.props.dropActiveHint };
|
|
1802
|
+
if (this.props.replaceLabel)
|
|
1803
|
+
this.uiConfig = { ...this.uiConfig, replaceLabel: this.props.replaceLabel };
|
|
1804
|
+
if (this.props.removeLabel)
|
|
1805
|
+
this.uiConfig = { ...this.uiConfig, removeLabel: this.props.removeLabel };
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Validates and merges newly-picked files into the current selection.
|
|
1809
|
+
* @param incoming The files chosen by the user.
|
|
1810
|
+
*/
|
|
1811
|
+
addFiles(incoming) {
|
|
1812
|
+
this.internalError.set(null);
|
|
1813
|
+
let errorKey = null;
|
|
1814
|
+
let errorArgs = {};
|
|
1815
|
+
let accepted = incoming.filter((f) => this.matchesAccept(f));
|
|
1816
|
+
if (accepted.length < incoming.length)
|
|
1817
|
+
errorKey = 'accept';
|
|
1818
|
+
if (this.props.maxSize != null) {
|
|
1819
|
+
const max = this.props.maxSize;
|
|
1820
|
+
const withinSize = accepted.filter((f) => f.size <= max);
|
|
1821
|
+
if (withinSize.length < accepted.length) {
|
|
1822
|
+
errorKey = 'maxSize';
|
|
1823
|
+
errorArgs = { max: this.humanFileSize(max) };
|
|
1824
|
+
}
|
|
1825
|
+
accepted = withinSize;
|
|
1826
|
+
}
|
|
1827
|
+
let next = this.props.multiple ? [...this.files(), ...accepted] : accepted.slice(-1);
|
|
1828
|
+
if (this.props.multiple && this.props.maxFiles != null && next.length > this.props.maxFiles) {
|
|
1829
|
+
next = next.slice(0, this.props.maxFiles);
|
|
1830
|
+
errorKey = 'maxFiles';
|
|
1831
|
+
errorArgs = { max: this.props.maxFiles };
|
|
1832
|
+
}
|
|
1833
|
+
if (errorKey)
|
|
1834
|
+
this.internalError.set(this.resolveMessage(errorKey, errorArgs));
|
|
1835
|
+
this.setFiles(next);
|
|
1836
|
+
this.emit();
|
|
1837
|
+
}
|
|
1838
|
+
/** Replaces the internal selection and rebuilds image previews. */
|
|
1839
|
+
setFiles(next) {
|
|
1840
|
+
this.revokeAll();
|
|
1841
|
+
this.files.set(next);
|
|
1842
|
+
this.previewUrls.set(next.map((f) => (this.isImage(f) ? URL.createObjectURL(f) : null)));
|
|
1843
|
+
}
|
|
1844
|
+
/** Emits the current value to the form and any listeners. */
|
|
1845
|
+
emit() {
|
|
1846
|
+
const value = this.props.multiple ? this.files() : (this.files()[0] ?? null);
|
|
1847
|
+
this.onChange(value);
|
|
1848
|
+
this.onTouched();
|
|
1849
|
+
this.filesChange.emit(value);
|
|
1850
|
+
}
|
|
1851
|
+
/** Revokes any outstanding object-URL previews to avoid leaks. */
|
|
1852
|
+
revokeAll() {
|
|
1853
|
+
for (const url of this.previewUrls()) {
|
|
1854
|
+
if (url)
|
|
1855
|
+
URL.revokeObjectURL(url);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
/** Builds a display item for an already-saved image. */
|
|
1859
|
+
existingItem(url, index) {
|
|
1860
|
+
return {
|
|
1861
|
+
name: this.fileNameFromUrl(url),
|
|
1862
|
+
isImage: true,
|
|
1863
|
+
previewUrl: url,
|
|
1864
|
+
sizeLabel: null,
|
|
1865
|
+
index,
|
|
1866
|
+
existing: true,
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
/** Picks which control error key to display. */
|
|
1870
|
+
pickErrorKey(errors) {
|
|
1871
|
+
if (this.props.errorPriority) {
|
|
1872
|
+
for (const key of this.props.errorPriority) {
|
|
1873
|
+
if (errors[key] !== undefined)
|
|
1874
|
+
return key;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
return Object.keys(errors)[0];
|
|
1878
|
+
}
|
|
1879
|
+
// ========== Helpers ==========
|
|
1880
|
+
/** Resolves a control error key to a message, interpolating its args. */
|
|
1881
|
+
resolveControlError(key, errors) {
|
|
1882
|
+
return this.resolveMessage(key, errors[key]);
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Resolves a message for an error key using the same precedence as the other
|
|
1886
|
+
* inputs: custom props > config > built-in > fallback > default.
|
|
1887
|
+
*/
|
|
1888
|
+
resolveMessage(key, args) {
|
|
1889
|
+
const customMsg = this.props.errorMessages?.[key];
|
|
1890
|
+
const configMsg = this.uiConfig.errorMessages?.[key];
|
|
1891
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
1892
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[key] : undefined;
|
|
1893
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
1894
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
1895
|
+
if (typeof msgDef === 'function') {
|
|
1896
|
+
return msgDef(args ?? {}, {});
|
|
1897
|
+
}
|
|
1898
|
+
if (args && typeof args === 'object') {
|
|
1899
|
+
return msgDef.replace(/\{\{(\w+)}}/g, (_match, token) => {
|
|
1900
|
+
const value = args[token];
|
|
1901
|
+
return value !== undefined ? String(value) : `{{${token}}}`;
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
return msgDef;
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Whether a drag event should be treated as a file drop on this control.
|
|
1908
|
+
* Ignores disabled controls, modes without a drop target, and drags that
|
|
1909
|
+
* carry something other than files (selected text, a link, …) so the page
|
|
1910
|
+
* keeps its default behaviour.
|
|
1911
|
+
*/
|
|
1912
|
+
acceptsDrag(event) {
|
|
1913
|
+
if (this.isDisabled || !this.supportsDrop)
|
|
1914
|
+
return false;
|
|
1915
|
+
const types = event.dataTransfer?.types;
|
|
1916
|
+
return !types || Array.from(types).includes('Files');
|
|
1917
|
+
}
|
|
1918
|
+
/** Clears the drag state and its nesting counter. */
|
|
1919
|
+
resetDrag() {
|
|
1920
|
+
this.dragDepth = 0;
|
|
1921
|
+
this.isDragging.set(false);
|
|
1922
|
+
}
|
|
1923
|
+
/** Checks a file against the configured `accept` filter (extensions and MIME globs). */
|
|
1924
|
+
matchesAccept(file) {
|
|
1925
|
+
const accept = this.props.accept;
|
|
1926
|
+
if (!accept)
|
|
1927
|
+
return true;
|
|
1928
|
+
const tokens = accept.split(',').map((t) => t.trim().toLowerCase()).filter(Boolean);
|
|
1929
|
+
if (tokens.length === 0)
|
|
1930
|
+
return true;
|
|
1931
|
+
const name = file.name.toLowerCase();
|
|
1932
|
+
const type = (file.type ?? '').toLowerCase();
|
|
1933
|
+
return tokens.some((token) => {
|
|
1934
|
+
if (token.startsWith('.'))
|
|
1935
|
+
return name.endsWith(token);
|
|
1936
|
+
if (token.endsWith('/*'))
|
|
1937
|
+
return type.startsWith(token.slice(0, -1));
|
|
1938
|
+
return type === token;
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
/** Formats a byte count as a human-readable size. */
|
|
1942
|
+
humanFileSize(bytes) {
|
|
1943
|
+
if (bytes < 1024)
|
|
1944
|
+
return `${bytes} B`;
|
|
1945
|
+
if (bytes < 1024 * 1024)
|
|
1946
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
1947
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
1948
|
+
}
|
|
1949
|
+
/** Derives a display name from a URL (last path segment). */
|
|
1950
|
+
fileNameFromUrl(url) {
|
|
1951
|
+
const clean = url.split('?')[0].split('#')[0];
|
|
1952
|
+
const segment = clean.substring(clean.lastIndexOf('/') + 1);
|
|
1953
|
+
return segment || 'image';
|
|
1954
|
+
}
|
|
1955
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnFileInput, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1956
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnFileInput, isStandalone: true, selector: "mn-lib-file-input", inputs: { props: "props" }, outputs: { filesChange: "filesChange", cleared: "cleared" }, ngImport: i0, template: "<!--\n Drag handling sits on the wrapper so a drop anywhere inside the control counts.\n onDragEnter/onDragLeave balance out as the drag crosses children, and\n acceptsDrag() ignores the modes that have no drop target.\n-->\n<div\n (dragenter)=\"onDragEnter($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (dragover)=\"onDragOver($event)\"\n (drop)=\"onDrop($event)\"\n [class.w-full]=\"props.fullWidth !== false && displayMode !== 'compact'\"\n class=\"flex flex-col\">\n <!-- Label -->\n @if (uiConfig.label) {\n <label [attr.for]=\"resolvedId\" class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\">\n <p>{{ uiConfig.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Hidden native file input shared by every trigger -->\n <input\n #fileInput\n (change)=\"onFileSelected($event)\"\n [accept]=\"acceptAttr\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || null\"\n [attr.multiple]=\"props.multiple || null\"\n [attr.name]=\"resolvedName\"\n [disabled]=\"isDisabled\"\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n class=\"hidden\"\n type=\"file\"\n />\n\n @switch (displayMode) {\n <!-- Compact: inline button + filename chips -->\n @case ('compact') {\n <div class=\"flex flex-wrap items-center gap-2\">\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n [ngClass]=\"controlClasses\"\n class=\"inline-flex items-center gap-2 cursor-pointer hover:bg-base-200\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.Upload\" [size]=\"18\"></svg>\n <span class=\"text-sm\">{{ uiConfig.replaceLabel }}</span>\n </button>\n @for (item of displayItems(); track itemKey(item)) {\n <span class=\"inline-flex items-center gap-1 text-sm text-base-content/70\">\n @if (item.isImage && item.previewUrl) {\n <img [src]=\"item.previewUrl\" alt=\"\" class=\"h-6 w-6 rounded object-cover\"/>\n } @else {\n <svg [lucideIcon]=\"icons.File\" [size]=\"16\" class=\"text-base-content/50\"></svg>\n }\n <span class=\"max-w-40 truncate\">{{ item.name }}</span>\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"text-base-content/50 hover:text-error cursor-pointer\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.X\" [size]=\"14\"></svg>\n </button>\n </span>\n }\n </div>\n }\n\n <!-- List: compact rows of file icon + name + size -->\n @case ('list') {\n <div class=\"relative flex flex-col\">\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n [ngClass]=\"controlClasses\"\n class=\"flex flex-row items-center justify-center gap-2 cursor-pointer hover:bg-base-200\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.Upload\" [size]=\"18\"></svg>\n <span class=\"text-sm\">{{ uiConfig.replaceLabel }}</span>\n </button>\n @if (displayItems().length > 0) {\n <div class=\"mt-2 flex flex-col gap-1\">\n @for (item of displayItems(); track itemKey(item)) {\n <div class=\"flex items-center gap-2 rounded-lg bg-base-200 px-3 py-1.5 text-sm\">\n <svg [lucideIcon]=\"icons.File\" [size]=\"16\" class=\"text-base-content/50\"></svg>\n <span class=\"flex-1 truncate text-base-content\">{{ item.name }}</span>\n @if (item.sizeLabel) {\n <span class=\"text-base-content/50\">{{ item.sizeLabel }}</span>\n }\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"text-base-content/50 hover:text-error cursor-pointer\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.X\" [size]=\"16\"></svg>\n </button>\n </div>\n }\n </div>\n }\n @if (isDragging()) {\n <ng-container [ngTemplateOutlet]=\"dropOverlay\"></ng-container>\n }\n </div>\n }\n\n <!-- Thumbnail: grid of tiles with overlay remove + add tile -->\n @case ('thumbnail') {\n <div class=\"relative flex flex-wrap gap-3\">\n @for (item of displayItems(); track itemKey(item)) {\n <div class=\"relative h-24 w-24 overflow-hidden rounded-xl border border-base-300 bg-base-100\">\n @if (item.isImage && item.previewUrl) {\n <img [src]=\"item.previewUrl\" alt=\"\" class=\"h-full w-full object-cover\"/>\n } @else {\n <div class=\"flex h-full w-full flex-col items-center justify-center gap-1 p-1 text-center\">\n <svg [lucideIcon]=\"icons.File\" [size]=\"22\" class=\"text-base-content/50\"></svg>\n <span class=\"w-full truncate text-xs text-base-content/60\">{{ item.name }}</span>\n </div>\n }\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"inline-flex h-6 w-6 items-center justify-center rounded-full cursor-pointer transition-colors absolute top-1 right-1 border-none bg-black/60 text-white hover:bg-black/80\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.X\" [size]=\"14\"></svg>\n </button>\n </div>\n }\n @if (props.multiple || displayItems().length === 0) {\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n class=\"flex h-24 w-24 flex-col items-center justify-center gap-1 rounded-xl border-2 border-dashed border-base-300 text-base-content/50 hover:border-primary cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.ImagePlus\" [size]=\"22\"></svg>\n </button>\n }\n @if (isDragging()) {\n <ng-container [ngTemplateOutlet]=\"dropOverlay\"></ng-container>\n }\n </div>\n }\n\n <!-- Dropzone (default): large dashed area + preview rows -->\n @default {\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n [ngClass]=\"controlClasses\"\n type=\"button\">\n <!-- Inert so a drag crossing the icon/hint never reads as leaving the zone -->\n <span aria-live=\"polite\" class=\"pointer-events-none flex flex-col items-center gap-2\">\n @if (isDragging()) {\n <svg [size]=\"28\" class=\"animate-bounce text-primary\" [lucideIcon]=\"icons.Upload\"></svg>\n <span class=\"text-sm font-medium text-primary\">{{ uiConfig.dropActiveHint }}</span>\n } @else {\n <svg [size]=\"28\" class=\"text-base-content/40\" [lucideIcon]=\"icons.ImagePlus\"></svg>\n <span class=\"text-sm text-base-content/60\">{{ uiConfig.dropzoneHint }}</span>\n }\n </span>\n </button>\n @if (displayItems().length > 0) {\n <div class=\"mt-2 flex flex-col gap-2\">\n @for (item of displayItems(); track itemKey(item)) {\n <div class=\"flex items-center gap-3 rounded-lg bg-base-200 p-2\">\n @if (item.isImage && item.previewUrl) {\n <img [src]=\"item.previewUrl\" alt=\"\" class=\"h-12 w-12 rounded-md object-cover\"/>\n } @else {\n <svg [lucideIcon]=\"icons.File\" [size]=\"24\" class=\"text-base-content/50\"></svg>\n }\n <span class=\"flex-1 truncate text-sm text-base-content\">{{ item.name }}</span>\n @if (item.sizeLabel) {\n <span class=\"text-sm text-base-content/50\">{{ item.sizeLabel }}</span>\n }\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"inline-flex h-8 w-8 items-center justify-center rounded-full cursor-pointer transition-colors text-error hover:bg-error/10\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.Trash2\" [size]=\"16\"></svg>\n </button>\n </div>\n }\n </div>\n }\n }\n }\n\n <!-- Selection-limit error (accept / maxSize / maxFiles) -->\n @if (internalError(); as msg) {\n <mn-error-message [errorMessage]=\"msg\" [id]=\"resolvedId + '-selection'\"></mn-error-message>\n }\n\n <!-- Control validation errors -->\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n</div>\n\n<!--\n \"Release to drop\" cover for the modes that render their own layout instead of a\n dropzone. Absolutely positioned so arming it never shifts the layout, and inert\n so the drag keeps reaching the elements underneath.\n-->\n<ng-template #dropOverlay>\n <div\n aria-live=\"polite\"\n class=\"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-primary bg-base-100/90 text-center\">\n <svg [size]=\"24\" class=\"animate-bounce text-primary\" [lucideIcon]=\"icons.Upload\"></svg>\n <span class=\"px-2 text-sm font-medium text-primary\">{{ uiConfig.dropActiveHint }}</span>\n </div>\n</ng-template>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }] });
|
|
1957
|
+
}
|
|
1958
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnFileInput, decorators: [{
|
|
1959
|
+
type: Component,
|
|
1960
|
+
args: [{ selector: 'mn-lib-file-input', standalone: true, imports: [CommonModule, NgClass, MnErrorMessage, LucideDynamicIcon], template: "<!--\n Drag handling sits on the wrapper so a drop anywhere inside the control counts.\n onDragEnter/onDragLeave balance out as the drag crosses children, and\n acceptsDrag() ignores the modes that have no drop target.\n-->\n<div\n (dragenter)=\"onDragEnter($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (dragover)=\"onDragOver($event)\"\n (drop)=\"onDrop($event)\"\n [class.w-full]=\"props.fullWidth !== false && displayMode !== 'compact'\"\n class=\"flex flex-col\">\n <!-- Label -->\n @if (uiConfig.label) {\n <label [attr.for]=\"resolvedId\" class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\">\n <p>{{ uiConfig.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Hidden native file input shared by every trigger -->\n <input\n #fileInput\n (change)=\"onFileSelected($event)\"\n [accept]=\"acceptAttr\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || null\"\n [attr.multiple]=\"props.multiple || null\"\n [attr.name]=\"resolvedName\"\n [disabled]=\"isDisabled\"\n [id]=\"resolvedId\"\n [attr.aria-required]=\"isRequired() || null\"\n class=\"hidden\"\n type=\"file\"\n />\n\n @switch (displayMode) {\n <!-- Compact: inline button + filename chips -->\n @case ('compact') {\n <div class=\"flex flex-wrap items-center gap-2\">\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n [ngClass]=\"controlClasses\"\n class=\"inline-flex items-center gap-2 cursor-pointer hover:bg-base-200\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.Upload\" [size]=\"18\"></svg>\n <span class=\"text-sm\">{{ uiConfig.replaceLabel }}</span>\n </button>\n @for (item of displayItems(); track itemKey(item)) {\n <span class=\"inline-flex items-center gap-1 text-sm text-base-content/70\">\n @if (item.isImage && item.previewUrl) {\n <img [src]=\"item.previewUrl\" alt=\"\" class=\"h-6 w-6 rounded object-cover\"/>\n } @else {\n <svg [lucideIcon]=\"icons.File\" [size]=\"16\" class=\"text-base-content/50\"></svg>\n }\n <span class=\"max-w-40 truncate\">{{ item.name }}</span>\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"text-base-content/50 hover:text-error cursor-pointer\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.X\" [size]=\"14\"></svg>\n </button>\n </span>\n }\n </div>\n }\n\n <!-- List: compact rows of file icon + name + size -->\n @case ('list') {\n <div class=\"relative flex flex-col\">\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n [ngClass]=\"controlClasses\"\n class=\"flex flex-row items-center justify-center gap-2 cursor-pointer hover:bg-base-200\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.Upload\" [size]=\"18\"></svg>\n <span class=\"text-sm\">{{ uiConfig.replaceLabel }}</span>\n </button>\n @if (displayItems().length > 0) {\n <div class=\"mt-2 flex flex-col gap-1\">\n @for (item of displayItems(); track itemKey(item)) {\n <div class=\"flex items-center gap-2 rounded-lg bg-base-200 px-3 py-1.5 text-sm\">\n <svg [lucideIcon]=\"icons.File\" [size]=\"16\" class=\"text-base-content/50\"></svg>\n <span class=\"flex-1 truncate text-base-content\">{{ item.name }}</span>\n @if (item.sizeLabel) {\n <span class=\"text-base-content/50\">{{ item.sizeLabel }}</span>\n }\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"text-base-content/50 hover:text-error cursor-pointer\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.X\" [size]=\"16\"></svg>\n </button>\n </div>\n }\n </div>\n }\n @if (isDragging()) {\n <ng-container [ngTemplateOutlet]=\"dropOverlay\"></ng-container>\n }\n </div>\n }\n\n <!-- Thumbnail: grid of tiles with overlay remove + add tile -->\n @case ('thumbnail') {\n <div class=\"relative flex flex-wrap gap-3\">\n @for (item of displayItems(); track itemKey(item)) {\n <div class=\"relative h-24 w-24 overflow-hidden rounded-xl border border-base-300 bg-base-100\">\n @if (item.isImage && item.previewUrl) {\n <img [src]=\"item.previewUrl\" alt=\"\" class=\"h-full w-full object-cover\"/>\n } @else {\n <div class=\"flex h-full w-full flex-col items-center justify-center gap-1 p-1 text-center\">\n <svg [lucideIcon]=\"icons.File\" [size]=\"22\" class=\"text-base-content/50\"></svg>\n <span class=\"w-full truncate text-xs text-base-content/60\">{{ item.name }}</span>\n </div>\n }\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"inline-flex h-6 w-6 items-center justify-center rounded-full cursor-pointer transition-colors absolute top-1 right-1 border-none bg-black/60 text-white hover:bg-black/80\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.X\" [size]=\"14\"></svg>\n </button>\n </div>\n }\n @if (props.multiple || displayItems().length === 0) {\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n class=\"flex h-24 w-24 flex-col items-center justify-center gap-1 rounded-xl border-2 border-dashed border-base-300 text-base-content/50 hover:border-primary cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.ImagePlus\" [size]=\"22\"></svg>\n </button>\n }\n @if (isDragging()) {\n <ng-container [ngTemplateOutlet]=\"dropOverlay\"></ng-container>\n }\n </div>\n }\n\n <!-- Dropzone (default): large dashed area + preview rows -->\n @default {\n <button\n (click)=\"fileInput.click()\"\n [disabled]=\"isDisabled\"\n [ngClass]=\"controlClasses\"\n type=\"button\">\n <!-- Inert so a drag crossing the icon/hint never reads as leaving the zone -->\n <span aria-live=\"polite\" class=\"pointer-events-none flex flex-col items-center gap-2\">\n @if (isDragging()) {\n <svg [size]=\"28\" class=\"animate-bounce text-primary\" [lucideIcon]=\"icons.Upload\"></svg>\n <span class=\"text-sm font-medium text-primary\">{{ uiConfig.dropActiveHint }}</span>\n } @else {\n <svg [size]=\"28\" class=\"text-base-content/40\" [lucideIcon]=\"icons.ImagePlus\"></svg>\n <span class=\"text-sm text-base-content/60\">{{ uiConfig.dropzoneHint }}</span>\n }\n </span>\n </button>\n @if (displayItems().length > 0) {\n <div class=\"mt-2 flex flex-col gap-2\">\n @for (item of displayItems(); track itemKey(item)) {\n <div class=\"flex items-center gap-3 rounded-lg bg-base-200 p-2\">\n @if (item.isImage && item.previewUrl) {\n <img [src]=\"item.previewUrl\" alt=\"\" class=\"h-12 w-12 rounded-md object-cover\"/>\n } @else {\n <svg [lucideIcon]=\"icons.File\" [size]=\"24\" class=\"text-base-content/50\"></svg>\n }\n <span class=\"flex-1 truncate text-sm text-base-content\">{{ item.name }}</span>\n @if (item.sizeLabel) {\n <span class=\"text-sm text-base-content/50\">{{ item.sizeLabel }}</span>\n }\n <button\n (click)=\"item.existing ? removeExisting(item.index) : removeFile(item.index)\"\n [attr.aria-label]=\"uiConfig.removeLabel\"\n class=\"inline-flex h-8 w-8 items-center justify-center rounded-full cursor-pointer transition-colors text-error hover:bg-error/10\"\n type=\"button\">\n <svg [lucideIcon]=\"icons.Trash2\" [size]=\"16\"></svg>\n </button>\n </div>\n }\n </div>\n }\n }\n }\n\n <!-- Selection-limit error (accept / maxSize / maxFiles) -->\n @if (internalError(); as msg) {\n <mn-error-message [errorMessage]=\"msg\" [id]=\"resolvedId + '-selection'\"></mn-error-message>\n }\n\n <!-- Control validation errors -->\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n</div>\n\n<!--\n \"Release to drop\" cover for the modes that render their own layout instead of a\n dropzone. Absolutely positioned so arming it never shifts the layout, and inert\n so the drag keeps reaching the elements underneath.\n-->\n<ng-template #dropOverlay>\n <div\n aria-live=\"polite\"\n class=\"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-primary bg-base-100/90 text-center\">\n <svg [size]=\"24\" class=\"animate-bounce text-primary\" [lucideIcon]=\"icons.Upload\"></svg>\n <span class=\"px-2 text-sm font-medium text-primary\">{{ uiConfig.dropActiveHint }}</span>\n </div>\n</ng-template>\n" }]
|
|
1961
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
1962
|
+
type: Input,
|
|
1963
|
+
args: [{ required: true }]
|
|
1964
|
+
}], filesChange: [{
|
|
1965
|
+
type: Output
|
|
1966
|
+
}], cleared: [{
|
|
1967
|
+
type: Output
|
|
1968
|
+
}] } });
|
|
1969
|
+
|
|
1970
|
+
/** Breathing room kept between the panel and the viewport edge, in pixels. */
|
|
1971
|
+
const PANEL_VIEWPORT_MARGIN_PX = 8;
|
|
1972
|
+
/**
|
|
1973
|
+
* The least room below the trigger before the panel is flipped above it, in pixels: roughly
|
|
1974
|
+
* four rows, so a picker that still fits its usual few options never flips for no reason.
|
|
1975
|
+
*/
|
|
1976
|
+
const PANEL_FLIP_THRESHOLD_PX = 160;
|
|
1977
|
+
/**
|
|
1978
|
+
* Chooses the side of the trigger with room for the panel.
|
|
1979
|
+
*
|
|
1980
|
+
* Below by default. Above only when the space below is under {@link PANEL_FLIP_THRESHOLD_PX}
|
|
1981
|
+
* and the space above is larger: flipping is the exception, because a list that opens upward
|
|
1982
|
+
* reads backwards from what the trigger's chevron promised.
|
|
1983
|
+
* @param trigger The trigger's viewport rectangle.
|
|
1984
|
+
* @param viewportHeight The viewport's inner height.
|
|
1985
|
+
* @param gap Distance between trigger and panel, in pixels.
|
|
1986
|
+
* @param panelMaxHeight The panel's own height cap in pixels, so the available room only
|
|
1987
|
+
* becomes the cap when it is the smaller of the two.
|
|
1988
|
+
* @returns The styles to bind on the panel.
|
|
1989
|
+
*/
|
|
1990
|
+
function anchoredPanelPlacement(trigger, viewportHeight, gap, panelMaxHeight) {
|
|
1991
|
+
const below = viewportHeight - trigger.bottom - gap - PANEL_VIEWPORT_MARGIN_PX;
|
|
1992
|
+
const above = trigger.top - gap - PANEL_VIEWPORT_MARGIN_PX;
|
|
1993
|
+
const openAbove = below < PANEL_FLIP_THRESHOLD_PX && above > below;
|
|
1994
|
+
const room = Math.max(openAbove ? above : below, 0);
|
|
1995
|
+
return {
|
|
1996
|
+
top: openAbove ? 'auto' : `${trigger.bottom + gap}px`,
|
|
1997
|
+
bottom: openAbove ? `${viewportHeight - trigger.top + gap}px` : 'auto',
|
|
1998
|
+
maxHeight: room < panelMaxHeight ? `${room}px` : null,
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Keyboard navigation shared by mn-select and mn-multi-select. Both follow the WAI-ARIA combobox
|
|
2004
|
+
* pattern: focus stays on the trigger (or the search box) and `aria-activedescendant` names the
|
|
2005
|
+
* option the arrow keys are on, so the options themselves are never Tab stops.
|
|
2006
|
+
*/
|
|
2007
|
+
/**
|
|
2008
|
+
* The index of the next option that can be chosen, stepping from `from` in one direction without
|
|
2009
|
+
* wrapping. From no active option (-1), a forward step lands on the first enabled option and a
|
|
2010
|
+
* backward step on the last, which is also how Home and End are answered.
|
|
2011
|
+
* @param options - The options as rendered, in order.
|
|
2012
|
+
* @param from - The current active index, or -1 for none.
|
|
2013
|
+
* @param step - 1 to move down the list, -1 to move up.
|
|
2014
|
+
* @param isEnabled - Whether an option can be highlighted; disabled rows are skipped.
|
|
2015
|
+
* @returns The new index; `from` when nothing enabled lies that way, or -1 when `from` is out of range.
|
|
2016
|
+
*/
|
|
2017
|
+
function stepEnabledIndex(options, from, step, isEnabled) {
|
|
2018
|
+
const valid = from >= 0 && from < options.length;
|
|
2019
|
+
let index = valid ? from : step === 1 ? -1 : options.length;
|
|
2020
|
+
for (index += step; index >= 0 && index < options.length; index += step) {
|
|
2021
|
+
if (isEnabled(options[index]))
|
|
2022
|
+
return index;
|
|
2023
|
+
}
|
|
2024
|
+
return valid ? from : -1;
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Scrolls the nearest scrollable ancestor just far enough to show an option. Written out rather than
|
|
2028
|
+
* `scrollIntoView` because that also scrolls the page, and a page scroll closes an anchored panel.
|
|
2029
|
+
* @param option - The option element, or null when it is not rendered.
|
|
2030
|
+
*/
|
|
2031
|
+
function scrollOptionIntoView(option) {
|
|
2032
|
+
if (!option)
|
|
2033
|
+
return;
|
|
2034
|
+
let scroller = option.parentElement;
|
|
2035
|
+
while (scroller && scroller !== document.body && scroller.scrollHeight <= scroller.clientHeight) {
|
|
2036
|
+
scroller = scroller.parentElement;
|
|
2037
|
+
}
|
|
2038
|
+
if (!scroller || scroller === document.body)
|
|
2039
|
+
return;
|
|
2040
|
+
const box = scroller.getBoundingClientRect();
|
|
2041
|
+
const row = option.getBoundingClientRect();
|
|
2042
|
+
if (row.top < box.top) {
|
|
2043
|
+
scroller.scrollTop -= box.top - row.top;
|
|
2044
|
+
}
|
|
2045
|
+
else if (row.bottom > box.bottom) {
|
|
2046
|
+
scroller.scrollTop += row.bottom - box.bottom;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
const mnSelectVariants = tv({
|
|
2051
|
+
base: 'bg-base-100 border-1 border-base-300 text-base-content text-sm cursor-pointer hover:bg-base-200 transition-colors duration-300',
|
|
2052
|
+
variants: {
|
|
2053
|
+
shadow: {
|
|
2054
|
+
true: 'shadow-lg',
|
|
2055
|
+
},
|
|
2056
|
+
size: {
|
|
2057
|
+
sm: 'p-2',
|
|
2058
|
+
md: 'p-3',
|
|
2059
|
+
lg: 'p-4',
|
|
2060
|
+
},
|
|
2061
|
+
borderRadius: {
|
|
2062
|
+
none: 'rounded-none',
|
|
2063
|
+
xs: 'rounded-xs',
|
|
2064
|
+
sm: 'rounded-sm',
|
|
2065
|
+
md: 'rounded-md',
|
|
2066
|
+
lg: 'rounded-lg',
|
|
2067
|
+
xl: 'rounded-xl',
|
|
2068
|
+
two_xl: 'rounded-2xl',
|
|
2069
|
+
three_xl: 'rounded-3xl',
|
|
2070
|
+
four_xl: 'rounded-4xl',
|
|
2071
|
+
},
|
|
2072
|
+
fullWidth: {
|
|
2073
|
+
true: 'w-full',
|
|
2074
|
+
},
|
|
2075
|
+
},
|
|
2076
|
+
defaultVariants: {
|
|
2077
|
+
size: 'md',
|
|
2078
|
+
borderRadius: 'md',
|
|
2079
|
+
},
|
|
2080
|
+
});
|
|
2081
|
+
|
|
2082
|
+
/** Lucide icons this file renders. */
|
|
2083
|
+
const ICONS$2 = lucideIcons({ Check: lucide.Check, ChevronDown: lucide.ChevronDown });
|
|
2084
|
+
const MN_SELECT_CONFIG = new InjectionToken('MN_SELECT_CONFIG');
|
|
2085
|
+
/** The keys that open a closed select from its trigger. */
|
|
2086
|
+
const OPEN_KEYS = ['ArrowDown', 'ArrowUp', 'Enter', ' '];
|
|
2087
|
+
/**
|
|
2088
|
+
* Whether the keyboard may highlight an option.
|
|
2089
|
+
* @param option - The option.
|
|
2090
|
+
* @returns False for a disabled option.
|
|
2091
|
+
*/
|
|
2092
|
+
function isChoosable(option) {
|
|
2093
|
+
return !option.disabled;
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Takes a key for the select: no default action (no scroll, no form submit) and no bubbling to a
|
|
2097
|
+
* surrounding modal's own Enter or Escape handling.
|
|
2098
|
+
* @param event - The keydown to claim.
|
|
2099
|
+
*/
|
|
2100
|
+
function claim(event) {
|
|
2101
|
+
event.preventDefault();
|
|
2102
|
+
event.stopPropagation();
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* A single-value picker. The trigger opens a `role="listbox"` of {@link MnSelectOption}s;
|
|
2106
|
+
* choosing one sets the value and closes — this is the value-picker twin of the ⋯
|
|
2107
|
+
* command menu mn-dropdown, so it *is* a ControlValueAccessor.
|
|
2108
|
+
*
|
|
2109
|
+
* Presentation mirrors mn-multi-select: one custom field trigger at every size, an
|
|
2110
|
+
* anchored popover on desktop and the shared {@link MnBottomSheet} on mobile (< 640px) —
|
|
2111
|
+
* the same sheet mn-dropdown itself wraps. Both the popover and the sheet host are
|
|
2112
|
+
* portalled to `document.body` so their `position: fixed` anchors to the viewport rather
|
|
2113
|
+
* than any transformed/filtered ancestor (a table cell, a card) — the same root-cause fix
|
|
2114
|
+
* the multi-select applies.
|
|
2115
|
+
*/
|
|
2116
|
+
class MnSelect {
|
|
2117
|
+
/** Lucide icons the template renders. */
|
|
2118
|
+
icons = ICONS$2;
|
|
2119
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
2120
|
+
props;
|
|
2121
|
+
/** Currently selected value */
|
|
2122
|
+
selectedValue = null;
|
|
2123
|
+
isOpen = false;
|
|
2124
|
+
isDisabled = false;
|
|
2125
|
+
searchTerm = '';
|
|
2126
|
+
/**
|
|
2127
|
+
* Position in `filteredOptions` of the option the keyboard is on, or -1 for none. Reset when the
|
|
2128
|
+
* list it indexes changes (a search) or goes away (close), so it never points at a stale row.
|
|
2129
|
+
*/
|
|
2130
|
+
activeIndex = -1;
|
|
2131
|
+
uiConfig = {};
|
|
2132
|
+
configService = inject(MnConfigService);
|
|
2133
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
2134
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
2135
|
+
elRef = inject(ElementRef);
|
|
2136
|
+
lang = inject(MnLanguageService);
|
|
2137
|
+
destroyRef = inject(DestroyRef);
|
|
2138
|
+
renderer = inject(Renderer2);
|
|
2139
|
+
cdr = inject(ChangeDetectorRef);
|
|
2140
|
+
injector = inject(Injector);
|
|
2141
|
+
/** Lucide data for the trailing check shown on the selected row. */
|
|
2142
|
+
checkIcon = ICONS$2.Check;
|
|
2143
|
+
/** Reference to the trigger element for positioning the dropdown. */
|
|
2144
|
+
triggerRef;
|
|
2145
|
+
/** Layout classes for the anchored popover panel. The mobile sheet is rendered by
|
|
2146
|
+
* mn-bottom-sheet instead, so it no longer needs a branch here. */
|
|
2147
|
+
panelClasses = 'fixed z-9999 w-max bg-base-100 border border-base-300 rounded-md shadow-lg max-h-60 overflow-auto';
|
|
2148
|
+
/** The panel's own height cap in pixels: the `max-h-60` above, restated for the placement maths. */
|
|
2149
|
+
static PANEL_MAX_HEIGHT_PX = 240;
|
|
2150
|
+
/** Space kept between a widened panel and the viewport's right edge. */
|
|
2151
|
+
static PANEL_EDGE_GAP_PX = 8;
|
|
2152
|
+
/** Layout classes for the invisible click shield rendered under the anchored panel.
|
|
2153
|
+
* One step below the panel's z-index so the panel itself stays clickable, and above
|
|
2154
|
+
* any modal/drawer chrome (which tops out well under 9998). */
|
|
2155
|
+
shieldClasses = 'fixed inset-0 z-9998';
|
|
2156
|
+
/** Option count at which the search input auto-enables when `searchable` is unset. */
|
|
2157
|
+
static DEFAULT_SEARCH_THRESHOLD = 8;
|
|
2158
|
+
/** Tailwind's `sm` breakpoint — below this the panel renders as a bottom sheet.
|
|
2159
|
+
* Kept in step with the same constant in mn-bottom-sheet / mn-multi-select. */
|
|
2160
|
+
static SHEET_MAX_WIDTH = 639.98;
|
|
2161
|
+
/** The anchored popover panel currently moved into `document.body`, if any. */
|
|
2162
|
+
movedPanel = null;
|
|
2163
|
+
/** The click shield currently moved into `document.body`, if any. */
|
|
2164
|
+
movedShield = null;
|
|
2165
|
+
/** The bottom-sheet host, for outside-click tests. The sheet owns its own placement. */
|
|
2166
|
+
sheetHost = null;
|
|
2167
|
+
/** Whether the viewport is currently narrow enough for the sheet layout. */
|
|
2168
|
+
isNarrowViewport = false;
|
|
2169
|
+
/** Live breakpoint match, so rotating the device re-evaluates the layout. */
|
|
2170
|
+
sheetMedia = null;
|
|
2171
|
+
/** The listener registered on `sheetMedia`, retained for teardown. */
|
|
2172
|
+
sheetMediaListener = null;
|
|
2173
|
+
/** `document.body`'s inline `overflow` before the sheet locked it, restored on close. */
|
|
2174
|
+
previousBodyOverflow = null;
|
|
2175
|
+
/**
|
|
2176
|
+
* The sheet's height (px) captured the moment it opened, before any search. Re-applied
|
|
2177
|
+
* as a `min-height` floor so filtering the option list shorter cannot shrink the sheet
|
|
2178
|
+
* mid-type. Null while anchored or closed, so the popover and desktop path are untouched.
|
|
2179
|
+
*/
|
|
2180
|
+
sheetFloorPx = null;
|
|
2181
|
+
/**
|
|
2182
|
+
* Watches the trigger while the panel is open. The panel lives in `document.body`, so it
|
|
2183
|
+
* survives its own trigger being hidden by an ancestor — a wizard step or a tab switched
|
|
2184
|
+
* away with `display: none`. When the trigger stops being visible the panel goes with it.
|
|
2185
|
+
*/
|
|
2186
|
+
visibilityObserver = null;
|
|
2187
|
+
/**
|
|
2188
|
+
* Capture-phase scroll listener installed while open. `window:scroll` only fires for the
|
|
2189
|
+
* document scroller, so scrolling an inner container (a modal body, a scrollable card)
|
|
2190
|
+
* would otherwise leave the portalled panel floating at its stale coordinates.
|
|
2191
|
+
*/
|
|
2192
|
+
scrollCapture = null;
|
|
2193
|
+
/** Dropdown position calculated from the trigger's bounding rect. */
|
|
2194
|
+
/** Inline placement of the anchored panel; `maxHeight` only binds when the viewport is the tighter cap. */
|
|
2195
|
+
dropdownStyle = {
|
|
2196
|
+
top: '0px',
|
|
2197
|
+
bottom: 'auto',
|
|
2198
|
+
left: '0px',
|
|
2199
|
+
minWidth: '0px',
|
|
2200
|
+
maxWidth: 'none',
|
|
2201
|
+
maxHeight: null,
|
|
2202
|
+
};
|
|
2203
|
+
onChange = () => {
|
|
2204
|
+
};
|
|
2205
|
+
onTouched = () => {
|
|
2206
|
+
};
|
|
2207
|
+
builtInErrorMessages = {
|
|
2208
|
+
required: 'Please select an option',
|
|
2209
|
+
};
|
|
2210
|
+
constructor() {
|
|
2211
|
+
if (this.ngControl)
|
|
2212
|
+
this.ngControl.valueAccessor = this;
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* The dropdown panel element, queried while it is rendered by the `@if` block. The setter
|
|
2216
|
+
* relocates the panel to `document.body` so that its `position: fixed` coordinates resolve
|
|
2217
|
+
* against the viewport rather than any transformed/filtered ancestor (which would otherwise
|
|
2218
|
+
* become the containing block and push the panel to the middle of the screen — also broken
|
|
2219
|
+
* on iOS). Cleanup is handled when the query clears on close/destroy.
|
|
2220
|
+
*/
|
|
2221
|
+
set dropdownRef(ref) {
|
|
2222
|
+
this.movedPanel = this.portal(ref?.nativeElement ?? null, this.movedPanel);
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* The click shield sitting under the anchored panel, portalled alongside it for the same
|
|
2226
|
+
* reason: `position: fixed` must resolve against the viewport, not a transformed ancestor.
|
|
2227
|
+
*/
|
|
2228
|
+
set shieldRef(ref) {
|
|
2229
|
+
this.movedShield = this.portal(ref?.nativeElement ?? null, this.movedShield);
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* The bottom-sheet host, kept as a reference for outside-click tests. The sheet relocates
|
|
2233
|
+
* itself to `document.body`, so nothing is moved here. On open its container height is
|
|
2234
|
+
* captured as the sheet's `min-height` floor.
|
|
2235
|
+
*/
|
|
2236
|
+
set sheetRef(ref) {
|
|
2237
|
+
const el = ref?.nativeElement ?? null;
|
|
2238
|
+
this.sheetHost = el;
|
|
2239
|
+
if (el) {
|
|
2240
|
+
this.captureSheetFloor(el);
|
|
2241
|
+
}
|
|
2242
|
+
else {
|
|
2243
|
+
this.sheetFloorPx = null;
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
get control() {
|
|
2247
|
+
return this.ngControl?.control ?? null;
|
|
2248
|
+
}
|
|
2249
|
+
get selectedOption() {
|
|
2250
|
+
return this.props.options.find(o => o.value === this.selectedValue);
|
|
2251
|
+
}
|
|
2252
|
+
/** The label shown in the trigger: the selected option, else the placeholder. */
|
|
2253
|
+
get displayText() {
|
|
2254
|
+
return this.selectedOption?.label ?? this.placeholderLabel;
|
|
2255
|
+
}
|
|
2256
|
+
/** Trigger text shown while no option is selected. */
|
|
2257
|
+
get placeholderLabel() {
|
|
2258
|
+
return this.resolveLabel(this.props.placeholder, 'mnSelect.placeholder', 'Select...', this.uiConfig.placeholder);
|
|
2259
|
+
}
|
|
2260
|
+
/** Placeholder and accessible name of the dropdown's search input. */
|
|
2261
|
+
get searchPlaceholderLabel() {
|
|
2262
|
+
return this.resolveLabel(this.props.searchPlaceholder, 'mnSelect.search', 'Search...', this.uiConfig.searchPlaceholder);
|
|
2263
|
+
}
|
|
2264
|
+
/** Empty text shown when the search filters every option away. */
|
|
2265
|
+
get noOptionsLabel() {
|
|
2266
|
+
return this.resolveLabel(undefined, 'mnSelect.noOptions', 'No options found', this.uiConfig.noOptionsFound);
|
|
2267
|
+
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Resolves one of the component's own labels, preferring what the caller gave it
|
|
2270
|
+
* and falling back through the config layer, a conventional translation key and
|
|
2271
|
+
* finally a readable English default.
|
|
2272
|
+
*
|
|
2273
|
+
* Mirrors `MnCollectionBase.resolveLabel` and its twin in `MnMultiSelect`. Without
|
|
2274
|
+
* the key step a consumer could only translate these by repeating the same literal
|
|
2275
|
+
* at every call site, and the search box in particular auto-enables on option
|
|
2276
|
+
* count — it appears without anyone asking for it, so it must be translatable
|
|
2277
|
+
* without anyone asking either.
|
|
2278
|
+
*
|
|
2279
|
+
* @param explicit The label the caller passed through `props`, if any.
|
|
2280
|
+
* @param key The conventional translation key to try next.
|
|
2281
|
+
* @param fallback The English text used when neither resolves.
|
|
2282
|
+
* @param configured The value the config layer resolved, if any.
|
|
2283
|
+
* @returns The resolved label.
|
|
2284
|
+
*/
|
|
2285
|
+
resolveLabel(explicit, key, fallback, configured) {
|
|
2286
|
+
return explicit ?? configured ?? this.lang.translateIfPresent(key) ?? fallback;
|
|
2287
|
+
}
|
|
2288
|
+
get showError() {
|
|
2289
|
+
const c = this.control;
|
|
2290
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
2291
|
+
}
|
|
2292
|
+
get errorMessages() {
|
|
2293
|
+
const errors = this.control?.errors;
|
|
2294
|
+
if (!errors)
|
|
2295
|
+
return [];
|
|
2296
|
+
return Object.keys(errors).map(key => this.resolveErrorMessageForKey(key, errors));
|
|
2297
|
+
}
|
|
2298
|
+
get errorMessage() {
|
|
2299
|
+
const errors = this.control?.errors;
|
|
2300
|
+
if (!errors)
|
|
2301
|
+
return null;
|
|
2302
|
+
const errorKey = this.pickErrorKey(errors);
|
|
2303
|
+
return this.resolveErrorMessageForKey(errorKey, errors);
|
|
2304
|
+
}
|
|
2305
|
+
get resolvedId() {
|
|
2306
|
+
return this.props.id;
|
|
2307
|
+
}
|
|
2308
|
+
get resolvedName() {
|
|
2309
|
+
return this.props?.name ?? null;
|
|
2310
|
+
}
|
|
2311
|
+
get triggerClasses() {
|
|
2312
|
+
return mnSelectVariants({
|
|
2313
|
+
size: this.props.size,
|
|
2314
|
+
borderRadius: this.props.borderRadius,
|
|
2315
|
+
shadow: this.props.shadow,
|
|
2316
|
+
fullWidth: this.props.fullWidth,
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
/** Whether the panel should currently render as a bottom sheet. */
|
|
2320
|
+
get isSheet() {
|
|
2321
|
+
return this.props.mobileSheet !== false && this.isNarrowViewport;
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Whether the search input is shown: the explicit `searchable` prop when set, otherwise
|
|
2325
|
+
* auto-enabled once the option count reaches the threshold.
|
|
2326
|
+
*/
|
|
2327
|
+
get isSearchable() {
|
|
2328
|
+
if (this.props.searchable !== undefined)
|
|
2329
|
+
return this.props.searchable;
|
|
2330
|
+
const threshold = this.props.searchThreshold ?? MnSelect.DEFAULT_SEARCH_THRESHOLD;
|
|
2331
|
+
return this.props.options.length >= threshold;
|
|
2332
|
+
}
|
|
2333
|
+
get filteredOptions() {
|
|
2334
|
+
if (!this.searchTerm)
|
|
2335
|
+
return this.props.options;
|
|
2336
|
+
const lower = this.searchTerm.toLowerCase();
|
|
2337
|
+
return this.props.options.filter(o => o.label.toLowerCase().includes(lower));
|
|
2338
|
+
}
|
|
2339
|
+
// ========== Lifecycle ==========
|
|
2340
|
+
ngOnInit() {
|
|
2341
|
+
this.resolveConfig();
|
|
2342
|
+
this.startWatchingViewport();
|
|
2343
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
2344
|
+
this.resolveConfig();
|
|
2345
|
+
});
|
|
2346
|
+
this.destroyRef.onDestroy(() => {
|
|
2347
|
+
sub.unsubscribe();
|
|
2348
|
+
this.stopWatchingTrigger();
|
|
2349
|
+
this.stopWatchingViewport();
|
|
2350
|
+
this.unlockBodyScroll();
|
|
2351
|
+
// Guarantee the portalled elements never outlive the component.
|
|
2352
|
+
this.movedPanel = this.portal(null, this.movedPanel);
|
|
2353
|
+
this.movedShield = this.portal(null, this.movedShield);
|
|
2354
|
+
this.sheetHost = null;
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
2358
|
+
writeValue(val) {
|
|
2359
|
+
// Treat empty string as null so the placeholder is shown and the control stays properly invalid.
|
|
2360
|
+
this.selectedValue = (val === '' || val == null) ? null : val;
|
|
2361
|
+
}
|
|
2362
|
+
registerOnChange(fn) {
|
|
2363
|
+
this.onChange = fn;
|
|
2364
|
+
}
|
|
2365
|
+
registerOnTouched(fn) {
|
|
2366
|
+
this.onTouched = fn;
|
|
2367
|
+
}
|
|
2368
|
+
setDisabledState(isDisabled) {
|
|
2369
|
+
this.isDisabled = isDisabled;
|
|
2370
|
+
}
|
|
2371
|
+
// ========== Dropdown Logic ==========
|
|
2372
|
+
toggle() {
|
|
2373
|
+
if (this.isDisabled)
|
|
2374
|
+
return;
|
|
2375
|
+
if (this.isOpen) {
|
|
2376
|
+
this.close();
|
|
2377
|
+
return;
|
|
2378
|
+
}
|
|
2379
|
+
this.isOpen = true;
|
|
2380
|
+
if (this.isSheet) {
|
|
2381
|
+
// A sheet is anchored to the viewport, so it needs no trigger tracking — only a
|
|
2382
|
+
// scroll lock so the page behind it stays put while the list is scrolled.
|
|
2383
|
+
this.lockBodyScroll();
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
this.updateDropdownPosition();
|
|
2387
|
+
this.startWatchingTrigger();
|
|
2388
|
+
}
|
|
2389
|
+
/** Selects an option, notifies the form and closes — a single choice ends the interaction. */
|
|
2390
|
+
selectOption(option) {
|
|
2391
|
+
if (option.disabled)
|
|
2392
|
+
return;
|
|
2393
|
+
this.selectedValue = option.value;
|
|
2394
|
+
this.onChange(this.selectedValue);
|
|
2395
|
+
this.close();
|
|
2396
|
+
}
|
|
2397
|
+
isSelected(option) {
|
|
2398
|
+
return this.selectedValue === option.value;
|
|
2399
|
+
}
|
|
2400
|
+
/** Filters the options; the first match is highlighted so Enter picks it, none once the box is cleared. */
|
|
2401
|
+
onSearch(term) {
|
|
2402
|
+
this.searchTerm = term ?? '';
|
|
2403
|
+
this.activeIndex = this.searchTerm ? stepEnabledIndex(this.filteredOptions, -1, 1, isChoosable) : -1;
|
|
2404
|
+
}
|
|
2405
|
+
/** Id of the keyboard-highlighted option, for `aria-activedescendant`; null when none is. */
|
|
2406
|
+
get activeOptionId() {
|
|
2407
|
+
const inRange = this.activeIndex >= 0 && this.activeIndex < this.filteredOptions.length;
|
|
2408
|
+
return this.isOpen && inRange ? this.optionId(this.activeIndex) : null;
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* The DOM id of the option rendered at a position in `filteredOptions`.
|
|
2412
|
+
* @param index - The option's position.
|
|
2413
|
+
* @returns The id, unique per select.
|
|
2414
|
+
*/
|
|
2415
|
+
optionId(index) {
|
|
2416
|
+
return `${this.resolvedId}-option-${index}`;
|
|
2417
|
+
}
|
|
2418
|
+
/**
|
|
2419
|
+
* Keyboard handling for the trigger and the search box, the WAI-ARIA combobox pattern. While
|
|
2420
|
+
* closed, ArrowDown, ArrowUp, Enter and Space open the list with an option highlighted. While
|
|
2421
|
+
* open, the arrows move the highlight past disabled options without wrapping, Home and End jump
|
|
2422
|
+
* to the ends, Enter (and Space outside the search box) chooses the highlighted option and returns focus to the trigger, Escape closes and Tab closes and lets focus move on. Enter and Space
|
|
2423
|
+
* stop here, so they can never submit a surrounding form or close a surrounding modal.
|
|
2424
|
+
* @param event - The keydown.
|
|
2425
|
+
* @param fromSearch - True when it came from the search box, where Space, Home and End edit text.
|
|
2426
|
+
*/
|
|
2427
|
+
onKeydown(event, fromSearch = false) {
|
|
2428
|
+
if (this.isDisabled)
|
|
2429
|
+
return;
|
|
2430
|
+
// Only keys pressed on the trigger itself; nothing inside it is focusable today, but stay safe.
|
|
2431
|
+
if (!fromSearch && event.target !== event.currentTarget)
|
|
2432
|
+
return;
|
|
2433
|
+
if (!this.isOpen) {
|
|
2434
|
+
if (fromSearch || !OPEN_KEYS.includes(event.key))
|
|
2435
|
+
return;
|
|
2436
|
+
claim(event);
|
|
2437
|
+
this.toggle();
|
|
2438
|
+
const selected = this.filteredOptions.findIndex(o => this.isSelected(o) && isChoosable(o));
|
|
2439
|
+
this.activeIndex = selected >= 0
|
|
2440
|
+
? selected
|
|
2441
|
+
: stepEnabledIndex(this.filteredOptions, -1, event.key === 'ArrowUp' ? -1 : 1, isChoosable);
|
|
2442
|
+
this.revealActiveOption();
|
|
2443
|
+
return;
|
|
2444
|
+
}
|
|
2445
|
+
switch (event.key) {
|
|
2446
|
+
case 'ArrowDown':
|
|
2447
|
+
case 'ArrowUp':
|
|
2448
|
+
claim(event);
|
|
2449
|
+
this.moveActive(this.activeIndex, event.key === 'ArrowDown' ? 1 : -1);
|
|
2450
|
+
return;
|
|
2451
|
+
case 'Home':
|
|
2452
|
+
case 'End':
|
|
2453
|
+
if (fromSearch)
|
|
2454
|
+
return;
|
|
2455
|
+
claim(event);
|
|
2456
|
+
this.moveActive(-1, event.key === 'Home' ? 1 : -1);
|
|
2457
|
+
return;
|
|
2458
|
+
case ' ':
|
|
2459
|
+
if (fromSearch)
|
|
2460
|
+
return;
|
|
2461
|
+
this.chooseActive(event);
|
|
2462
|
+
return;
|
|
2463
|
+
case 'Enter':
|
|
2464
|
+
this.chooseActive(event);
|
|
2465
|
+
return;
|
|
2466
|
+
case 'Escape':
|
|
2467
|
+
claim(event);
|
|
2468
|
+
this.close();
|
|
2469
|
+
this.focusTrigger();
|
|
2470
|
+
return;
|
|
2471
|
+
case 'Tab':
|
|
2472
|
+
// Focus moves on from the trigger, so the search box's Tab order position never matters.
|
|
2473
|
+
this.close();
|
|
2474
|
+
this.focusTrigger();
|
|
2475
|
+
return;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
/**
|
|
2479
|
+
* Moves the highlight one enabled option from `from` and scrolls it into view.
|
|
2480
|
+
* @param from - Where to step from; -1 to start at an end.
|
|
2481
|
+
* @param step - 1 for down, -1 for up.
|
|
2482
|
+
*/
|
|
2483
|
+
moveActive(from, step) {
|
|
2484
|
+
this.activeIndex = stepEnabledIndex(this.filteredOptions, from, step, isChoosable);
|
|
2485
|
+
this.revealActiveOption();
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Chooses the highlighted option (or just closes when none is) and hands focus back to the trigger,
|
|
2489
|
+
* because the search box that may hold it is removed with the panel.
|
|
2490
|
+
* @param event - The Enter or Space keydown, claimed so a form around the select is not submitted.
|
|
2491
|
+
*/
|
|
2492
|
+
chooseActive(event) {
|
|
2493
|
+
claim(event);
|
|
2494
|
+
const option = this.filteredOptions[this.activeIndex];
|
|
2495
|
+
if (option) {
|
|
2496
|
+
this.selectOption(option);
|
|
2497
|
+
}
|
|
2498
|
+
else {
|
|
2499
|
+
this.close();
|
|
2500
|
+
}
|
|
2501
|
+
this.focusTrigger();
|
|
2502
|
+
}
|
|
2503
|
+
/** Scrolls the highlighted option into view once the render that paints its ring has run. */
|
|
2504
|
+
revealActiveOption() {
|
|
2505
|
+
afterNextRender(() => {
|
|
2506
|
+
const id = this.activeOptionId;
|
|
2507
|
+
scrollOptionIntoView(id ? document.getElementById(id) : null);
|
|
2508
|
+
}, { injector: this.injector });
|
|
2509
|
+
}
|
|
2510
|
+
/** Puts focus back on the trigger. */
|
|
2511
|
+
focusTrigger() {
|
|
2512
|
+
this.triggerRef?.nativeElement.focus();
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* The single close path. Every trigger (outside click, Escape, scroll, resize, the trigger
|
|
2516
|
+
* being hidden, a choice) funnels through here so the open-only listeners are always torn
|
|
2517
|
+
* down with the panel and never leak.
|
|
2518
|
+
*/
|
|
2519
|
+
close() {
|
|
2520
|
+
if (!this.isOpen)
|
|
2521
|
+
return;
|
|
2522
|
+
this.isOpen = false;
|
|
2523
|
+
this.searchTerm = '';
|
|
2524
|
+
this.activeIndex = -1;
|
|
2525
|
+
this.stopWatchingTrigger();
|
|
2526
|
+
this.unlockBodyScroll();
|
|
2527
|
+
}
|
|
2528
|
+
handleBlur() {
|
|
2529
|
+
this.onTouched();
|
|
2530
|
+
}
|
|
2531
|
+
/**
|
|
2532
|
+
* Dismisses the anchored panel from a shield click, and stops the event there.
|
|
2533
|
+
*
|
|
2534
|
+
* Swallowing it is the point: the shield spans the viewport, so the click would otherwise
|
|
2535
|
+
* land on whatever the panel was floating over. Inside a modal that is the modal's own
|
|
2536
|
+
* backdrop, and "close the dropdown" would double as "throw away the modal". A first click
|
|
2537
|
+
* that only dismisses the overlay is also how native selects and menus behave.
|
|
2538
|
+
*/
|
|
2539
|
+
onShieldClick(event) {
|
|
2540
|
+
event.stopPropagation();
|
|
2541
|
+
event.preventDefault();
|
|
2542
|
+
this.close();
|
|
2543
|
+
}
|
|
2544
|
+
onDocumentClick(event) {
|
|
2545
|
+
const target = event.target;
|
|
2546
|
+
// The panel lives at the body root once open, so it is not a descendant of the host
|
|
2547
|
+
// element — treat clicks inside the portalled panel as "inside" too.
|
|
2548
|
+
const insideHost = !!target && this.elRef.nativeElement.contains(target);
|
|
2549
|
+
const insidePanel = !!target && !!this.movedPanel && this.movedPanel.contains(target);
|
|
2550
|
+
// In sheet mode the backdrop tap is handled by mn-bottom-sheet's own (dismiss); the
|
|
2551
|
+
// sheet host counts as "inside" here so this listener never double-fires the close.
|
|
2552
|
+
const insideSheet = !!target && !!this.sheetHost && this.sheetHost.contains(target);
|
|
2553
|
+
if (!insideHost && !insidePanel && !insideSheet) {
|
|
2554
|
+
this.close();
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
/** Closes the dropdown on Escape for keyboard accessibility. */
|
|
2558
|
+
onEscape() {
|
|
2559
|
+
this.close();
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Closes the dropdown when the page or a scrollable parent is scrolled.
|
|
2563
|
+
*
|
|
2564
|
+
* Skipped for a sheet: it is anchored to the viewport, not to the trigger, so it has no
|
|
2565
|
+
* stale position to escape. Crucially, opening the soft keyboard fires a `resize` on
|
|
2566
|
+
* Android — closing on that would dismiss the sheet the instant search is focused. A
|
|
2567
|
+
* genuine layout switch is handled by the `matchMedia` listener instead.
|
|
2568
|
+
*/
|
|
2569
|
+
onWindowScrollOrResize() {
|
|
2570
|
+
if (this.isSheet)
|
|
2571
|
+
return;
|
|
2572
|
+
this.close();
|
|
2573
|
+
}
|
|
2574
|
+
isRequired() {
|
|
2575
|
+
if (!this.control)
|
|
2576
|
+
return false;
|
|
2577
|
+
return this.control.hasValidator(Validators.required);
|
|
2578
|
+
}
|
|
2579
|
+
// ========== Viewport / breakpoint watching ==========
|
|
2580
|
+
/**
|
|
2581
|
+
* Tracks the sheet breakpoint through `matchMedia` rather than reading `innerWidth` once,
|
|
2582
|
+
* so rotating the device switches layout instead of leaving a panel positioned for the
|
|
2583
|
+
* previous orientation. An open panel is closed on the switch — its anchored coordinates
|
|
2584
|
+
* and its sheet layout are not interchangeable.
|
|
2585
|
+
*/
|
|
2586
|
+
startWatchingViewport() {
|
|
2587
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
2588
|
+
return;
|
|
2589
|
+
this.sheetMedia = window.matchMedia(`(max-width: ${MnSelect.SHEET_MAX_WIDTH}px)`);
|
|
2590
|
+
this.isNarrowViewport = this.sheetMedia.matches;
|
|
2591
|
+
this.sheetMediaListener = (event) => {
|
|
2592
|
+
this.isNarrowViewport = event.matches;
|
|
2593
|
+
this.close();
|
|
2594
|
+
// The listener fires outside Angular, so a zoneless app needs an explicit nudge.
|
|
2595
|
+
this.cdr.markForCheck();
|
|
2596
|
+
};
|
|
2597
|
+
this.sheetMedia.addEventListener('change', this.sheetMediaListener);
|
|
2598
|
+
}
|
|
2599
|
+
/** Tears down the breakpoint listener. Idempotent. */
|
|
2600
|
+
stopWatchingViewport() {
|
|
2601
|
+
if (this.sheetMedia && this.sheetMediaListener) {
|
|
2602
|
+
this.sheetMedia.removeEventListener('change', this.sheetMediaListener);
|
|
2603
|
+
}
|
|
2604
|
+
this.sheetMedia = null;
|
|
2605
|
+
this.sheetMediaListener = null;
|
|
2606
|
+
}
|
|
2607
|
+
// ========== Body scroll lock (sheet only) ==========
|
|
2608
|
+
/**
|
|
2609
|
+
* Freezes the page behind an open sheet. The previous inline value is captured and restored
|
|
2610
|
+
* verbatim so a surrounding modal that set its own lock is left intact.
|
|
2611
|
+
*/
|
|
2612
|
+
lockBodyScroll() {
|
|
2613
|
+
if (this.previousBodyOverflow !== null)
|
|
2614
|
+
return;
|
|
2615
|
+
this.previousBodyOverflow = document.body.style.overflow;
|
|
2616
|
+
this.renderer.setStyle(document.body, 'overflow', 'hidden');
|
|
2617
|
+
}
|
|
2618
|
+
/** Restores the pre-lock `overflow`. Idempotent. */
|
|
2619
|
+
unlockBodyScroll() {
|
|
2620
|
+
if (this.previousBodyOverflow === null)
|
|
2621
|
+
return;
|
|
2622
|
+
if (this.previousBodyOverflow) {
|
|
2623
|
+
this.renderer.setStyle(document.body, 'overflow', this.previousBodyOverflow);
|
|
2624
|
+
}
|
|
2625
|
+
else {
|
|
2626
|
+
this.renderer.removeStyle(document.body, 'overflow');
|
|
2627
|
+
}
|
|
2628
|
+
this.previousBodyOverflow = null;
|
|
2629
|
+
}
|
|
2630
|
+
// ========== Positioning ==========
|
|
2631
|
+
/**
|
|
2632
|
+
* Calculates the fixed position for the dropdown based on the trigger element: below it
|
|
2633
|
+
* while the viewport has room, above it otherwise, never past the viewport's edge.
|
|
2634
|
+
* The panel is never narrower than the trigger but grows to its widest option, so a compact
|
|
2635
|
+
* trigger (the collection page-size picker) cannot squeeze the selected row's check mark
|
|
2636
|
+
* over its label. It stops at the viewport's right edge, where long labels truncate.
|
|
2637
|
+
*/
|
|
2638
|
+
updateDropdownPosition() {
|
|
2639
|
+
if (!this.triggerRef)
|
|
2640
|
+
return;
|
|
2641
|
+
const rect = this.triggerRef.nativeElement.getBoundingClientRect();
|
|
2642
|
+
const roomToRightEdge = window.innerWidth - rect.left - MnSelect.PANEL_EDGE_GAP_PX;
|
|
2643
|
+
this.dropdownStyle = {
|
|
2644
|
+
...anchoredPanelPlacement(rect, window.innerHeight, 0, MnSelect.PANEL_MAX_HEIGHT_PX),
|
|
2645
|
+
left: `${rect.left}px`,
|
|
2646
|
+
minWidth: `${rect.width}px`,
|
|
2647
|
+
maxWidth: `${Math.max(rect.width, roomToRightEdge)}px`,
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* Starts the open-only watchers: an `IntersectionObserver` on the trigger (closes the panel
|
|
2652
|
+
* as soon as the trigger stops being rendered/visible) and a capture-phase `scroll` listener
|
|
2653
|
+
* (closes it when any ancestor scroller moves under it). Scrolls that originate inside the
|
|
2654
|
+
* panel's own option list are ignored.
|
|
2655
|
+
*/
|
|
2656
|
+
startWatchingTrigger() {
|
|
2657
|
+
this.stopWatchingTrigger();
|
|
2658
|
+
const trigger = this.triggerRef?.nativeElement;
|
|
2659
|
+
if (trigger && typeof IntersectionObserver !== 'undefined') {
|
|
2660
|
+
this.visibilityObserver = new IntersectionObserver(entries => {
|
|
2661
|
+
if (!entries.some(entry => !entry.isIntersecting))
|
|
2662
|
+
return;
|
|
2663
|
+
this.close();
|
|
2664
|
+
// The observer fires outside Angular, so a zoneless app needs an explicit nudge.
|
|
2665
|
+
this.cdr.markForCheck();
|
|
2666
|
+
});
|
|
2667
|
+
this.visibilityObserver.observe(trigger);
|
|
2668
|
+
}
|
|
2669
|
+
this.scrollCapture = (event) => {
|
|
2670
|
+
const target = event.target;
|
|
2671
|
+
if (target && this.movedPanel && (this.movedPanel === target || this.movedPanel.contains(target))) {
|
|
2672
|
+
return;
|
|
2673
|
+
}
|
|
2674
|
+
this.close();
|
|
2675
|
+
this.cdr.markForCheck();
|
|
2676
|
+
};
|
|
2677
|
+
document.addEventListener('scroll', this.scrollCapture, true);
|
|
2678
|
+
}
|
|
2679
|
+
/** Tears down the watchers installed by `startWatchingTrigger`. Idempotent. */
|
|
2680
|
+
stopWatchingTrigger() {
|
|
2681
|
+
this.visibilityObserver?.disconnect();
|
|
2682
|
+
this.visibilityObserver = null;
|
|
2683
|
+
if (this.scrollCapture) {
|
|
2684
|
+
document.removeEventListener('scroll', this.scrollCapture, true);
|
|
2685
|
+
this.scrollCapture = null;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
// ========== Sheet height floor ==========
|
|
2689
|
+
/**
|
|
2690
|
+
* Records the sheet's opened height as its `min-height` floor. Measured on the next frame
|
|
2691
|
+
* so the read reflects the fully-rendered, unfiltered list (the search box is empty on
|
|
2692
|
+
* open) and never forces a reflow mid change-detection. The floor equals the content height
|
|
2693
|
+
* at that instant, so applying it triggers no resize — it only stops a later, shorter
|
|
2694
|
+
* filtered list from pulling the sheet down.
|
|
2695
|
+
*
|
|
2696
|
+
* `hostEl` is the portalled mn-bottom-sheet host (`display: contents`), so the height is
|
|
2697
|
+
* read from its `.mn-sheet-container` child rather than the host itself.
|
|
2698
|
+
*/
|
|
2699
|
+
captureSheetFloor(hostEl) {
|
|
2700
|
+
const measure = () => {
|
|
2701
|
+
const container = hostEl.querySelector('.mn-sheet-container');
|
|
2702
|
+
return container?.offsetHeight ?? hostEl.offsetHeight;
|
|
2703
|
+
};
|
|
2704
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
2705
|
+
this.sheetFloorPx = measure();
|
|
2706
|
+
return;
|
|
2707
|
+
}
|
|
2708
|
+
requestAnimationFrame(() => {
|
|
2709
|
+
// The sheet may have closed before the frame ran; don't strand a stale floor.
|
|
2710
|
+
if (!this.isOpen || this.sheetHost !== hostEl)
|
|
2711
|
+
return;
|
|
2712
|
+
this.sheetFloorPx = measure();
|
|
2713
|
+
this.cdr.markForCheck();
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
// ========== Portal helper (see mn-multi-select for the full rationale) ==========
|
|
2717
|
+
/**
|
|
2718
|
+
* Move an overlay element to `document.body` when it appears, and detach it when the query
|
|
2719
|
+
* clears. Appending to the body root makes the element immune to ancestor
|
|
2720
|
+
* `transform`/`filter`/`will-change`, so `position: fixed` anchors to the viewport — without
|
|
2721
|
+
* this the panel lands mid-screen (and breaks outright on iOS).
|
|
2722
|
+
*
|
|
2723
|
+
* Returns the element now portalled, so the caller can store it. Idempotent and safe to
|
|
2724
|
+
* call with `null`.
|
|
2725
|
+
*/
|
|
2726
|
+
portal(el, current) {
|
|
2727
|
+
if (el) {
|
|
2728
|
+
if (current === el)
|
|
2729
|
+
return current;
|
|
2730
|
+
this.renderer.appendChild(document.body, el);
|
|
2731
|
+
return el;
|
|
2732
|
+
}
|
|
2733
|
+
if (current) {
|
|
2734
|
+
// Angular's view teardown may already have removed it; only detach if still attached.
|
|
2735
|
+
const parent = current.parentNode;
|
|
2736
|
+
if (parent) {
|
|
2737
|
+
this.renderer.removeChild(parent, current);
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
return null;
|
|
2741
|
+
}
|
|
2742
|
+
// ========== Config / Error Handling ==========
|
|
2743
|
+
resolveConfig() {
|
|
2744
|
+
const instanceId = this.explicitInstanceId || `mn-select-${this.props.id}`;
|
|
2745
|
+
this.uiConfig = this.configService.resolve('mn-select', this.sectionPath, instanceId);
|
|
2746
|
+
if (this.props.label) {
|
|
2747
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
2748
|
+
}
|
|
2749
|
+
if (this.props.placeholder) {
|
|
2750
|
+
this.uiConfig = { ...this.uiConfig, placeholder: this.props.placeholder };
|
|
2751
|
+
}
|
|
2752
|
+
if (this.props.ariaLabel) {
|
|
2753
|
+
this.uiConfig = { ...this.uiConfig, ariaLabel: this.props.ariaLabel };
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
pickErrorKey(errors) {
|
|
2757
|
+
if (this.props.errorPriority) {
|
|
2758
|
+
for (const key of this.props.errorPriority) {
|
|
2759
|
+
if (errors[key] !== undefined) {
|
|
2760
|
+
return key;
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
return Object.keys(errors)[0];
|
|
2765
|
+
}
|
|
2766
|
+
resolveErrorMessageForKey(errorKey, errors) {
|
|
2767
|
+
const errorArgs = errors[errorKey];
|
|
2768
|
+
const customMsg = this.props.errorMessages?.[errorKey];
|
|
2769
|
+
const configMsg = this.uiConfig.errorMessages?.[errorKey];
|
|
2770
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
2771
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[errorKey] : undefined;
|
|
2772
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
2773
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
2774
|
+
if (typeof msgDef === 'function') {
|
|
2775
|
+
return msgDef(errorArgs, errors);
|
|
2776
|
+
}
|
|
2777
|
+
if (errorArgs && typeof errorArgs === 'object') {
|
|
2778
|
+
return msgDef.replace(/{{(\w+)}}/g, (_, key) => errorArgs[key] ?? _);
|
|
2779
|
+
}
|
|
2780
|
+
return msgDef;
|
|
2781
|
+
}
|
|
2782
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnSelect, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2783
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnSelect, isStandalone: true, selector: "mn-lib-select", inputs: { props: "props" }, host: { listeners: { "document:click": "onDocumentClick($event)", "document:keydown.escape": "onEscape()", "window:scroll": "onWindowScrollOrResize()", "window:resize": "onWindowScrollOrResize()" }, properties: { "style.display": "props?.fullWidth ? 'block' : null", "style.width": "props?.fullWidth ? '100%' : null" } }, viewQueries: [{ propertyName: "triggerRef", first: true, predicate: ["trigger"], descendants: true }, { propertyName: "dropdownRef", first: true, predicate: ["dropdown"], descendants: true }, { propertyName: "shieldRef", first: true, predicate: ["shield"], descendants: true }, { propertyName: "sheetRef", first: true, predicate: ["sheet"], descendants: true, read: ElementRef }], ngImport: i0, template: "<div [class.is-fullwidth]=\"props.fullWidth\" class=\"flex flex-col h-full\">\n @if (uiConfig.label || props.label) {\n <label [attr.for]=\"resolvedId\" class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Trigger -->\n <div\n #trigger\n (blur)=\"handleBlur()\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n [attr.aria-activedescendant]=\"activeOptionId\"\n [attr.aria-controls]=\"isOpen ? resolvedId + '-listbox' : null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [attr.aria-disabled]=\"isDisabled || null\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || props.label || null\"\n [class.cursor-not-allowed]=\"isDisabled\"\n [class.opacity-60]=\"isDisabled\"\n [id]=\"resolvedId\"\n [ngClass]=\"triggerClasses\"\n [tabindex]=\"isDisabled ? -1 : 0\"\n aria-haspopup=\"listbox\"\n class=\"relative\"\n role=\"combobox\"\n [attr.aria-required]=\"isRequired() || null\"\n >\n <!-- `pr-6` reserves the gutter the caret is absolutely positioned in (right-2 + w-4),\n so the value can never render underneath it. `min-w-0` lets the label shrink below\n its content width, which is what makes truncation possible. -->\n <div class=\"flex flex-row items-center min-h-6 min-w-0 pr-6\">\n <span\n [attr.title]=\"selectedOption?.label\"\n [ngClass]=\"selectedOption ? 'text-base-content' : 'text-base-content/50'\"\n class=\"truncate\"\n >{{ displayText }}</span>\n </div>\n <div class=\"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none\">\n <svg [size]=\"16\" class=\"text-base-content/50\" [lucideIcon]=\"icons.ChevronDown\"></svg>\n </div>\n </div>\n\n <!-- Dropdown -->\n @if (isOpen) {\n @if (isSheet) {\n <!-- On mobile the panel is presented as a shared bottom sheet: the sheet chrome\n (backdrop, grabber, swipe/flick-to-dismiss, slide animation) lives in\n mn-bottom-sheet; this component only projects the field's content into it. The\n sheet host is portalled to document.body (see the `sheet` ViewChild) so its\n `position: fixed` anchors to the viewport, not a transformed ancestor. -->\n <mn-bottom-sheet\n #sheet\n (dismiss)=\"close()\"\n [ariaLabel]=\"uiConfig.ariaLabel || uiConfig.label || props.label || uiConfig.placeholder || props.placeholder\"\n [maxHeightVh]=\"80\"\n [minHeightPx]=\"sheetFloorPx\"\n >\n <div\n [id]=\"resolvedId + '-listbox'\"\n class=\"flex flex-col flex-1 min-h-0 overflow-hidden\"\n role=\"listbox\"\n >\n <!-- The sheet covers its own trigger, so it carries a header to name the field; the\n way out is the grabber (swipe-to-dismiss) and a backdrop tap. -->\n <div class=\"px-4 pt-1 pb-2 shrink-0\">\n <p class=\"text-base font-medium text-base-content truncate\">\n {{ uiConfig.label || props.label || uiConfig.placeholder || props.placeholder || '' }}\n </p>\n </div>\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n </mn-bottom-sheet>\n } @else {\n <!-- A transparent full-viewport shield behind the panel, so \"click anywhere to dismiss\"\n is literally true. It also *consumes* that click: without it the click reaches\n whatever sits underneath \u2014 inside a modal that is the modal's own backdrop, so\n dismissing the dropdown would tear down the whole modal with it. Portalled to\n document.body for the same reason the panel is. It is aria-hidden and unfocusable:\n the keyboard equivalent of this click is Escape. -->\n <div\n #shield\n (click)=\"onShieldClick($event)\"\n [id]=\"resolvedId + '-shield'\"\n [ngClass]=\"shieldClasses\"\n aria-hidden=\"true\"\n ></div>\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n #dropdown\n (click)=\"$event.stopPropagation()\"\n [id]=\"resolvedId + '-listbox'\"\n [ngClass]=\"panelClasses\"\n [style.left]=\"dropdownStyle.left\"\n [style.top]=\"dropdownStyle.top\"\n [style.bottom]=\"dropdownStyle.bottom\"\n [style.max-height]=\"dropdownStyle.maxHeight\"\n [style.min-width]=\"dropdownStyle.minWidth\"\n [style.max-width]=\"dropdownStyle.maxWidth\"\n role=\"listbox\"\n >\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n }\n }\n\n <!-- The search box + option list, shared verbatim by the sheet and the anchored popover.\n `isSheet` only tunes spacing/sizing and which element scrolls: in sheet mode the list\n is the flex scroller; anchored, the popover itself scrolls. -->\n <ng-template #panelBody>\n @if (isSearchable) {\n <!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"$event.stopPropagation()\"\n (keydown)=\"onKeydown($event, true)\"\n [ngClass]=\"isSheet ? 'px-4 py-2' : 'p-2'\"\n class=\"border-b border-base-300 shrink-0\"\n >\n <mn-lib-input-field\n (ngModelChange)=\"onSearch($event)\"\n [ngModelOptions]=\"{ standalone: true }\"\n [ngModel]=\"searchTerm\"\n [props]=\"{\n id: resolvedId + '-search',\n type: 'search',\n placeholder: searchPlaceholderLabel,\n ariaLabel: searchPlaceholderLabel,\n ariaActiveDescendant: activeOptionId,\n fullWidth: true,\n size: 'sm',\n autoFocus: !isSheet\n }\"\n ></mn-lib-input-field>\n </div>\n }\n <div [ngClass]=\"isSheet ? 'flex-1 overflow-auto overscroll-contain' : ''\">\n @for (opt of filteredOptions; track opt.value) {\n <!-- Options are not Tab stops: the keyboard reaches them with the arrow keys while focus\n stays on the trigger or the search box, and `aria-activedescendant` names the one it\n is on. The ring marks that option, since it never receives real focus. -->\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"selectOption(opt); $event.stopPropagation()\"\n [attr.aria-disabled]=\"opt.disabled || null\"\n [attr.aria-selected]=\"isSelected(opt)\"\n [class.opacity-50]=\"opt.disabled\"\n [class.pointer-events-none]=\"opt.disabled\"\n [id]=\"optionId($index)\"\n [ngClass]=\"[isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm', isSelected(opt) ? 'bg-primary/10 font-medium' : '', $index === activeIndex ? 'ring-2 ring-inset ring-primary' : '']\"\n class=\"flex items-center gap-x-2.5 cursor-pointer text-base-content hover:bg-base-200 transition-colors\"\n role=\"option\"\n >\n <span class=\"truncate min-w-0\">{{ opt.label }}</span>\n <!-- The current choice's marker. Decorative: the state is conveyed to assistive\n tech by `aria-selected` on the row. -->\n @if (isSelected(opt)) {\n <svg\n [lucideIcon]=\"checkIcon\"\n [size]=\"isSheet ? 18 : 16\"\n aria-hidden=\"true\"\n class=\"ml-auto shrink-0 text-primary\"\n ></svg>\n }\n </div>\n }\n @if (filteredOptions.length === 0) {\n <div [ngClass]=\"isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm'\" class=\"text-base-content/50\">\n {{ noOptionsLabel }}\n </div>\n }\n </div>\n </ng-template>\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1 mt-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }, { kind: "component", type: MnInputField, selector: "mn-lib-input-field", inputs: ["props"] }, { kind: "component", type: MnBottomSheet, selector: "mn-bottom-sheet", inputs: ["showBackdrop", "showGrabber", "dismissible", "minHeightPx", "maxHeightVh", "containerClass", "ariaLabel", "ariaLabelledby", "growWithKeyboard", "dismissGuard"], outputs: ["dismiss"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }] });
|
|
2784
|
+
}
|
|
2785
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnSelect, decorators: [{
|
|
2786
|
+
type: Component,
|
|
2787
|
+
args: [{ selector: 'mn-lib-select', standalone: true, imports: [NgClass, NgTemplateOutlet, FormsModule, MnErrorMessage, MnInputField, MnBottomSheet, LucideDynamicIcon], host: {
|
|
2788
|
+
// Without an explicit host width the inline host collapses to its content size, so
|
|
2789
|
+
// the trigger's `w-full` (width:100%) resolves against a content-sized box and fails
|
|
2790
|
+
// to fill the parent. Give the host a real width when fullWidth is requested.
|
|
2791
|
+
'[style.display]': "props?.fullWidth ? 'block' : null",
|
|
2792
|
+
'[style.width]': "props?.fullWidth ? '100%' : null",
|
|
2793
|
+
}, template: "<div [class.is-fullwidth]=\"props.fullWidth\" class=\"flex flex-col h-full\">\n @if (uiConfig.label || props.label) {\n <label [attr.for]=\"resolvedId\" class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Trigger -->\n <div\n #trigger\n (blur)=\"handleBlur()\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n [attr.aria-activedescendant]=\"activeOptionId\"\n [attr.aria-controls]=\"isOpen ? resolvedId + '-listbox' : null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [attr.aria-disabled]=\"isDisabled || null\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || props.label || null\"\n [class.cursor-not-allowed]=\"isDisabled\"\n [class.opacity-60]=\"isDisabled\"\n [id]=\"resolvedId\"\n [ngClass]=\"triggerClasses\"\n [tabindex]=\"isDisabled ? -1 : 0\"\n aria-haspopup=\"listbox\"\n class=\"relative\"\n role=\"combobox\"\n [attr.aria-required]=\"isRequired() || null\"\n >\n <!-- `pr-6` reserves the gutter the caret is absolutely positioned in (right-2 + w-4),\n so the value can never render underneath it. `min-w-0` lets the label shrink below\n its content width, which is what makes truncation possible. -->\n <div class=\"flex flex-row items-center min-h-6 min-w-0 pr-6\">\n <span\n [attr.title]=\"selectedOption?.label\"\n [ngClass]=\"selectedOption ? 'text-base-content' : 'text-base-content/50'\"\n class=\"truncate\"\n >{{ displayText }}</span>\n </div>\n <div class=\"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none\">\n <svg [size]=\"16\" class=\"text-base-content/50\" [lucideIcon]=\"icons.ChevronDown\"></svg>\n </div>\n </div>\n\n <!-- Dropdown -->\n @if (isOpen) {\n @if (isSheet) {\n <!-- On mobile the panel is presented as a shared bottom sheet: the sheet chrome\n (backdrop, grabber, swipe/flick-to-dismiss, slide animation) lives in\n mn-bottom-sheet; this component only projects the field's content into it. The\n sheet host is portalled to document.body (see the `sheet` ViewChild) so its\n `position: fixed` anchors to the viewport, not a transformed ancestor. -->\n <mn-bottom-sheet\n #sheet\n (dismiss)=\"close()\"\n [ariaLabel]=\"uiConfig.ariaLabel || uiConfig.label || props.label || uiConfig.placeholder || props.placeholder\"\n [maxHeightVh]=\"80\"\n [minHeightPx]=\"sheetFloorPx\"\n >\n <div\n [id]=\"resolvedId + '-listbox'\"\n class=\"flex flex-col flex-1 min-h-0 overflow-hidden\"\n role=\"listbox\"\n >\n <!-- The sheet covers its own trigger, so it carries a header to name the field; the\n way out is the grabber (swipe-to-dismiss) and a backdrop tap. -->\n <div class=\"px-4 pt-1 pb-2 shrink-0\">\n <p class=\"text-base font-medium text-base-content truncate\">\n {{ uiConfig.label || props.label || uiConfig.placeholder || props.placeholder || '' }}\n </p>\n </div>\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n </mn-bottom-sheet>\n } @else {\n <!-- A transparent full-viewport shield behind the panel, so \"click anywhere to dismiss\"\n is literally true. It also *consumes* that click: without it the click reaches\n whatever sits underneath \u2014 inside a modal that is the modal's own backdrop, so\n dismissing the dropdown would tear down the whole modal with it. Portalled to\n document.body for the same reason the panel is. It is aria-hidden and unfocusable:\n the keyboard equivalent of this click is Escape. -->\n <div\n #shield\n (click)=\"onShieldClick($event)\"\n [id]=\"resolvedId + '-shield'\"\n [ngClass]=\"shieldClasses\"\n aria-hidden=\"true\"\n ></div>\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n #dropdown\n (click)=\"$event.stopPropagation()\"\n [id]=\"resolvedId + '-listbox'\"\n [ngClass]=\"panelClasses\"\n [style.left]=\"dropdownStyle.left\"\n [style.top]=\"dropdownStyle.top\"\n [style.bottom]=\"dropdownStyle.bottom\"\n [style.max-height]=\"dropdownStyle.maxHeight\"\n [style.min-width]=\"dropdownStyle.minWidth\"\n [style.max-width]=\"dropdownStyle.maxWidth\"\n role=\"listbox\"\n >\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n }\n }\n\n <!-- The search box + option list, shared verbatim by the sheet and the anchored popover.\n `isSheet` only tunes spacing/sizing and which element scrolls: in sheet mode the list\n is the flex scroller; anchored, the popover itself scrolls. -->\n <ng-template #panelBody>\n @if (isSearchable) {\n <!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"$event.stopPropagation()\"\n (keydown)=\"onKeydown($event, true)\"\n [ngClass]=\"isSheet ? 'px-4 py-2' : 'p-2'\"\n class=\"border-b border-base-300 shrink-0\"\n >\n <mn-lib-input-field\n (ngModelChange)=\"onSearch($event)\"\n [ngModelOptions]=\"{ standalone: true }\"\n [ngModel]=\"searchTerm\"\n [props]=\"{\n id: resolvedId + '-search',\n type: 'search',\n placeholder: searchPlaceholderLabel,\n ariaLabel: searchPlaceholderLabel,\n ariaActiveDescendant: activeOptionId,\n fullWidth: true,\n size: 'sm',\n autoFocus: !isSheet\n }\"\n ></mn-lib-input-field>\n </div>\n }\n <div [ngClass]=\"isSheet ? 'flex-1 overflow-auto overscroll-contain' : ''\">\n @for (opt of filteredOptions; track opt.value) {\n <!-- Options are not Tab stops: the keyboard reaches them with the arrow keys while focus\n stays on the trigger or the search box, and `aria-activedescendant` names the one it\n is on. The ring marks that option, since it never receives real focus. -->\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"selectOption(opt); $event.stopPropagation()\"\n [attr.aria-disabled]=\"opt.disabled || null\"\n [attr.aria-selected]=\"isSelected(opt)\"\n [class.opacity-50]=\"opt.disabled\"\n [class.pointer-events-none]=\"opt.disabled\"\n [id]=\"optionId($index)\"\n [ngClass]=\"[isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm', isSelected(opt) ? 'bg-primary/10 font-medium' : '', $index === activeIndex ? 'ring-2 ring-inset ring-primary' : '']\"\n class=\"flex items-center gap-x-2.5 cursor-pointer text-base-content hover:bg-base-200 transition-colors\"\n role=\"option\"\n >\n <span class=\"truncate min-w-0\">{{ opt.label }}</span>\n <!-- The current choice's marker. Decorative: the state is conveyed to assistive\n tech by `aria-selected` on the row. -->\n @if (isSelected(opt)) {\n <svg\n [lucideIcon]=\"checkIcon\"\n [size]=\"isSheet ? 18 : 16\"\n aria-hidden=\"true\"\n class=\"ml-auto shrink-0 text-primary\"\n ></svg>\n }\n </div>\n }\n @if (filteredOptions.length === 0) {\n <div [ngClass]=\"isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm'\" class=\"text-base-content/50\">\n {{ noOptionsLabel }}\n </div>\n }\n </div>\n </ng-template>\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1 mt-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n" }]
|
|
2794
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
2795
|
+
type: Input,
|
|
2796
|
+
args: [{ required: true }]
|
|
2797
|
+
}], triggerRef: [{
|
|
2798
|
+
type: ViewChild,
|
|
2799
|
+
args: ['trigger', { static: false }]
|
|
2800
|
+
}], dropdownRef: [{
|
|
2801
|
+
type: ViewChild,
|
|
2802
|
+
args: ['dropdown', { static: false }]
|
|
2803
|
+
}], shieldRef: [{
|
|
2804
|
+
type: ViewChild,
|
|
2805
|
+
args: ['shield', { static: false }]
|
|
2806
|
+
}], sheetRef: [{
|
|
2807
|
+
type: ViewChild,
|
|
2808
|
+
args: ['sheet', { static: false, read: ElementRef }]
|
|
2809
|
+
}], onDocumentClick: [{
|
|
2810
|
+
type: HostListener,
|
|
2811
|
+
args: ['document:click', ['$event']]
|
|
2812
|
+
}], onEscape: [{
|
|
2813
|
+
type: HostListener,
|
|
2814
|
+
args: ['document:keydown.escape']
|
|
2815
|
+
}], onWindowScrollOrResize: [{
|
|
2816
|
+
type: HostListener,
|
|
2817
|
+
args: ['window:scroll', []]
|
|
2818
|
+
}, {
|
|
2819
|
+
type: HostListener,
|
|
2820
|
+
args: ['window:resize', []]
|
|
2821
|
+
}] } });
|
|
2822
|
+
|
|
2823
|
+
const mnMultiSelectVariants = tv({
|
|
2824
|
+
base: 'bg-base-100 border-1 border-base-300 text-base-content text-sm cursor-pointer',
|
|
2825
|
+
variants: {
|
|
2826
|
+
shadow: {
|
|
2827
|
+
true: 'shadow-lg',
|
|
2828
|
+
},
|
|
2829
|
+
size: {
|
|
2830
|
+
sm: 'p-2',
|
|
2831
|
+
md: 'p-3',
|
|
2832
|
+
lg: 'p-4',
|
|
2833
|
+
},
|
|
2834
|
+
borderRadius: {
|
|
2835
|
+
none: 'rounded-none',
|
|
2836
|
+
xs: 'rounded-xs',
|
|
2837
|
+
sm: 'rounded-sm',
|
|
2838
|
+
md: 'rounded-md',
|
|
2839
|
+
lg: 'rounded-lg',
|
|
2840
|
+
xl: 'rounded-xl',
|
|
2841
|
+
two_xl: 'rounded-2xl',
|
|
2842
|
+
three_xl: 'rounded-3xl',
|
|
2843
|
+
four_xl: 'rounded-4xl',
|
|
2844
|
+
},
|
|
2845
|
+
fullWidth: {
|
|
2846
|
+
true: 'w-full',
|
|
2847
|
+
},
|
|
2848
|
+
},
|
|
2849
|
+
defaultVariants: {
|
|
2850
|
+
size: 'md',
|
|
2851
|
+
borderRadius: 'md',
|
|
2852
|
+
},
|
|
2853
|
+
});
|
|
2854
|
+
|
|
2855
|
+
/** Lucide icons this file renders. */
|
|
2856
|
+
const ICONS$1 = lucideIcons({ ChevronDown: lucide.ChevronDown, X: lucide.X });
|
|
2857
|
+
const MN_MULTI_SELECT_CONFIG = new InjectionToken('MN_MULTI_SELECT_CONFIG');
|
|
2858
|
+
class MnMultiSelect {
|
|
2859
|
+
/** Lucide icons the template renders. */
|
|
2860
|
+
icons = ICONS$1;
|
|
2861
|
+
ngControl = inject(NgControl, { optional: true, self: true });
|
|
2862
|
+
uiConfig = {};
|
|
2863
|
+
props;
|
|
2864
|
+
configService = inject(MnConfigService);
|
|
2865
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
2866
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
2867
|
+
elRef = inject(ElementRef);
|
|
2868
|
+
lang = inject(MnLanguageService);
|
|
2869
|
+
destroyRef = inject(DestroyRef);
|
|
2870
|
+
renderer = inject(Renderer2);
|
|
2871
|
+
cdr = inject(ChangeDetectorRef);
|
|
2872
|
+
/** Injector for the after-render scroll of the highlighted option. */
|
|
2873
|
+
injector = inject(Injector);
|
|
2874
|
+
/** Reference to the trigger element for positioning the dropdown */
|
|
2875
|
+
triggerRef;
|
|
2876
|
+
/** Layout classes for the anchored popover panel. The mobile sheet is rendered by
|
|
2877
|
+
* mn-bottom-sheet instead, so it no longer needs a branch here. */
|
|
2878
|
+
panelClasses = 'fixed z-9999 bg-base-100 border border-base-300 rounded-md shadow-lg max-h-60 overflow-auto';
|
|
2879
|
+
/** The panel's own height cap in pixels: the `max-h-60` above, restated for the placement maths. */
|
|
2880
|
+
static PANEL_MAX_HEIGHT_PX = 240;
|
|
2881
|
+
/** Layout classes for the invisible click shield rendered under the anchored panel.
|
|
2882
|
+
* One step below the panel's z-index so the panel itself stays clickable, and above
|
|
2883
|
+
* any modal/drawer chrome (which tops out well under 9998). */
|
|
2884
|
+
shieldClasses = 'fixed inset-0 z-9998';
|
|
2885
|
+
/** The anchored popover panel currently moved into `document.body`, if any. */
|
|
2886
|
+
movedPanel = null;
|
|
2887
|
+
/** The click shield currently moved into `document.body`, if any. */
|
|
2888
|
+
movedShield = null;
|
|
2889
|
+
/** Option count at which the search input auto-enables when `searchable` is unset. */
|
|
2890
|
+
static DEFAULT_SEARCH_THRESHOLD = 8;
|
|
2891
|
+
/** Tailwind's `sm` breakpoint — below this the panel renders as a bottom sheet.
|
|
2892
|
+
* Kept in step with the same constant in `MnModalShellComponent`. */
|
|
2893
|
+
static SHEET_MAX_WIDTH = 639.98;
|
|
2894
|
+
/** Whether the viewport is currently narrow enough for the sheet layout. */
|
|
2895
|
+
isNarrowViewport = false;
|
|
2896
|
+
/** Live breakpoint match, so rotating the device re-evaluates the layout. */
|
|
2897
|
+
sheetMedia = null;
|
|
2898
|
+
/** The listener registered on `sheetMedia`, retained for teardown. */
|
|
2899
|
+
sheetMediaListener = null;
|
|
2900
|
+
/** `document.body`'s inline `overflow` before the sheet locked it, restored on close. */
|
|
2901
|
+
previousBodyOverflow = null;
|
|
2902
|
+
/**
|
|
2903
|
+
* The sheet's height (px) captured the moment it opened, before any search. Re-applied
|
|
2904
|
+
* as a `min-height` floor so filtering the option list shorter cannot shrink the sheet
|
|
2905
|
+
* mid-type. Null while anchored or closed, so the popover and desktop path are untouched.
|
|
2906
|
+
*/
|
|
2907
|
+
sheetFloorPx = null;
|
|
2908
|
+
/**
|
|
2909
|
+
* Watches the trigger while the panel is open. The panel lives in `document.body`,
|
|
2910
|
+
* so it survives its own trigger being hidden by an ancestor — e.g. a wizard step
|
|
2911
|
+
* or a tab that is switched away with `display: none` instead of being destroyed.
|
|
2912
|
+
* When the trigger stops being visible the panel must go with it.
|
|
2913
|
+
*/
|
|
2914
|
+
visibilityObserver = null;
|
|
2915
|
+
/**
|
|
2916
|
+
* Capture-phase scroll listener installed while open. `window:scroll` only fires for
|
|
2917
|
+
* the document scroller, so scrolling an inner container (a modal body, a scrollable
|
|
2918
|
+
* card) used to leave the portalled panel floating at its stale coordinates.
|
|
2919
|
+
*/
|
|
2920
|
+
scrollCapture = null;
|
|
2921
|
+
/** The bottom-sheet host, for outside-click tests. The sheet owns its own placement. */
|
|
2922
|
+
sheetHost = null;
|
|
2923
|
+
/**
|
|
2924
|
+
* The dropdown panel element, queried while it is rendered by the `@if` block.
|
|
2925
|
+
* The setter relocates the panel to `document.body` so that its `position: fixed`
|
|
2926
|
+
* coordinates resolve against the viewport rather than any transformed/filtered
|
|
2927
|
+
* ancestor (which would otherwise become the containing block and push the panel
|
|
2928
|
+
* to the middle of the screen — the root cause of the mis-positioning bug, also
|
|
2929
|
+
* broken on iOS). Cleanup is handled when the query clears on close/destroy.
|
|
2930
|
+
*/
|
|
2931
|
+
set dropdownRef(ref) {
|
|
2932
|
+
this.movedPanel = this.portal(ref?.nativeElement ?? null, this.movedPanel);
|
|
2933
|
+
}
|
|
2934
|
+
/**
|
|
2935
|
+
* The click shield sitting under the anchored panel, portalled alongside it for the same
|
|
2936
|
+
* reason: `position: fixed` must resolve against the viewport, not a transformed ancestor.
|
|
2937
|
+
*/
|
|
2938
|
+
set shieldRef(ref) {
|
|
2939
|
+
this.movedShield = this.portal(ref?.nativeElement ?? null, this.movedShield);
|
|
2940
|
+
}
|
|
2941
|
+
/** Currently selected values */
|
|
2942
|
+
selectedValues = [];
|
|
2943
|
+
isOpen = false;
|
|
2944
|
+
isDisabled = false;
|
|
2945
|
+
searchTerm = '';
|
|
2946
|
+
/**
|
|
2947
|
+
* Position in `filteredOptions` of the option the keyboard is on, or -1 for none. Reset when the
|
|
2948
|
+
* list it indexes changes (a search) or goes away (close), so it never points at a stale row.
|
|
2949
|
+
*/
|
|
2950
|
+
activeIndex = -1;
|
|
2951
|
+
/** Dropdown position calculated from trigger bounding rect */
|
|
2952
|
+
/** Inline placement of the anchored panel; `maxHeight` only binds when the viewport is the tighter cap. */
|
|
2953
|
+
dropdownStyle = {
|
|
2954
|
+
top: '0px',
|
|
2955
|
+
bottom: 'auto',
|
|
2956
|
+
left: '0px',
|
|
2957
|
+
width: '0px',
|
|
2958
|
+
maxHeight: null,
|
|
2959
|
+
};
|
|
2960
|
+
onChange = () => {
|
|
2961
|
+
};
|
|
2962
|
+
onTouched = () => { };
|
|
2963
|
+
builtInErrorMessages = {
|
|
2964
|
+
required: 'At least one option must be selected',
|
|
2965
|
+
};
|
|
2966
|
+
constructor() {
|
|
2967
|
+
if (this.ngControl)
|
|
2968
|
+
this.ngControl.valueAccessor = this;
|
|
2969
|
+
}
|
|
2970
|
+
/**
|
|
2971
|
+
* The bottom-sheet host, kept as a reference for outside-click tests. The sheet
|
|
2972
|
+
* relocates itself to `document.body`, so nothing is moved here. On open its
|
|
2973
|
+
* container height is captured as the sheet's `min-height` floor.
|
|
2974
|
+
*/
|
|
2975
|
+
set sheetRef(ref) {
|
|
2976
|
+
const el = ref?.nativeElement ?? null;
|
|
2977
|
+
this.sheetHost = el;
|
|
2978
|
+
if (el) {
|
|
2979
|
+
this.captureSheetFloor(el);
|
|
2980
|
+
}
|
|
2981
|
+
else {
|
|
2982
|
+
this.sheetFloorPx = null;
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
/**
|
|
2986
|
+
* Tracks the sheet breakpoint through `matchMedia` rather than reading `innerWidth`
|
|
2987
|
+
* once, so rotating the device switches layout instead of leaving a panel positioned
|
|
2988
|
+
* for the previous orientation. An open panel is closed on the switch — its anchored
|
|
2989
|
+
* coordinates and its sheet layout are not interchangeable.
|
|
2990
|
+
*/
|
|
2991
|
+
startWatchingViewport() {
|
|
2992
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
2993
|
+
return;
|
|
2994
|
+
this.sheetMedia = window.matchMedia(`(max-width: ${MnMultiSelect.SHEET_MAX_WIDTH}px)`);
|
|
2995
|
+
this.isNarrowViewport = this.sheetMedia.matches;
|
|
2996
|
+
this.sheetMediaListener = (event) => {
|
|
2997
|
+
this.isNarrowViewport = event.matches;
|
|
2998
|
+
this.close();
|
|
2999
|
+
// The listener fires outside Angular, so a zoneless app needs an explicit nudge.
|
|
3000
|
+
this.cdr.markForCheck();
|
|
3001
|
+
};
|
|
3002
|
+
this.sheetMedia.addEventListener('change', this.sheetMediaListener);
|
|
3003
|
+
}
|
|
3004
|
+
/** Tears down the breakpoint listener. Idempotent. */
|
|
3005
|
+
stopWatchingViewport() {
|
|
3006
|
+
if (this.sheetMedia && this.sheetMediaListener) {
|
|
3007
|
+
this.sheetMedia.removeEventListener('change', this.sheetMediaListener);
|
|
3008
|
+
}
|
|
3009
|
+
this.sheetMedia = null;
|
|
3010
|
+
this.sheetMediaListener = null;
|
|
3011
|
+
}
|
|
3012
|
+
ngOnInit() {
|
|
3013
|
+
this.resolveConfig();
|
|
3014
|
+
this.startWatchingViewport();
|
|
3015
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
3016
|
+
this.resolveConfig();
|
|
3017
|
+
});
|
|
3018
|
+
this.destroyRef.onDestroy(() => {
|
|
3019
|
+
sub.unsubscribe();
|
|
3020
|
+
this.stopWatchingTrigger();
|
|
3021
|
+
this.stopWatchingViewport();
|
|
3022
|
+
this.unlockBodyScroll();
|
|
3023
|
+
// Guarantee the portalled elements never outlive the component.
|
|
3024
|
+
this.movedPanel = this.portal(null, this.movedPanel);
|
|
3025
|
+
this.movedShield = this.portal(null, this.movedShield);
|
|
3026
|
+
this.sheetHost = null;
|
|
3027
|
+
});
|
|
3028
|
+
}
|
|
3029
|
+
resolveConfig() {
|
|
3030
|
+
const instanceId = this.explicitInstanceId || `mn-multi-select-${this.props.id}`;
|
|
3031
|
+
this.uiConfig = this.configService.resolve('mn-multi-select', this.sectionPath, instanceId);
|
|
3032
|
+
if (this.props.label) {
|
|
3033
|
+
this.uiConfig = { ...this.uiConfig, label: this.props.label };
|
|
3034
|
+
}
|
|
3035
|
+
if (this.props.placeholder) {
|
|
3036
|
+
this.uiConfig = { ...this.uiConfig, placeholder: this.props.placeholder };
|
|
3037
|
+
}
|
|
3038
|
+
if (this.props.ariaLabel) {
|
|
3039
|
+
this.uiConfig = { ...this.uiConfig, ariaLabel: this.props.ariaLabel };
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
// ========== ControlValueAccessor Implementation ==========
|
|
3043
|
+
writeValue(val) {
|
|
3044
|
+
this.selectedValues = Array.isArray(val) ? val : [];
|
|
3045
|
+
}
|
|
3046
|
+
registerOnChange(fn) {
|
|
3047
|
+
this.onChange = fn;
|
|
3048
|
+
}
|
|
3049
|
+
registerOnTouched(fn) {
|
|
3050
|
+
this.onTouched = fn;
|
|
3051
|
+
}
|
|
3052
|
+
setDisabledState(isDisabled) {
|
|
3053
|
+
this.isDisabled = isDisabled;
|
|
3054
|
+
}
|
|
3055
|
+
// ========== Dropdown Logic ==========
|
|
3056
|
+
toggle() {
|
|
3057
|
+
if (this.isDisabled)
|
|
3058
|
+
return;
|
|
3059
|
+
if (this.isOpen) {
|
|
3060
|
+
this.close();
|
|
3061
|
+
return;
|
|
3062
|
+
}
|
|
3063
|
+
this.isOpen = true;
|
|
3064
|
+
if (this.isSheet) {
|
|
3065
|
+
// A sheet is anchored to the viewport, so it needs no trigger tracking — only a
|
|
3066
|
+
// scroll lock so the page behind it stays put while the list is scrolled.
|
|
3067
|
+
this.lockBodyScroll();
|
|
3068
|
+
return;
|
|
3069
|
+
}
|
|
3070
|
+
this.updateDropdownPosition();
|
|
3071
|
+
this.startWatchingTrigger();
|
|
3072
|
+
}
|
|
3073
|
+
/** Whether the panel should currently render as a bottom sheet. */
|
|
3074
|
+
get isSheet() {
|
|
3075
|
+
return this.props.mobileSheet !== false && this.isNarrowViewport;
|
|
3076
|
+
}
|
|
3077
|
+
/**
|
|
3078
|
+
* Whether the search input is shown: the explicit `searchable` prop when set,
|
|
3079
|
+
* otherwise auto-enabled once the option count reaches the threshold.
|
|
3080
|
+
*/
|
|
3081
|
+
get isSearchable() {
|
|
3082
|
+
if (this.props.searchable !== undefined)
|
|
3083
|
+
return this.props.searchable;
|
|
3084
|
+
const threshold = this.props.searchThreshold ?? MnMultiSelect.DEFAULT_SEARCH_THRESHOLD;
|
|
3085
|
+
return this.props.options.length >= threshold;
|
|
3086
|
+
}
|
|
3087
|
+
/**
|
|
3088
|
+
* Dismisses the anchored panel from a shield click, and stops the event there.
|
|
3089
|
+
*
|
|
3090
|
+
* Swallowing it is the point: the shield spans the viewport, so the click would otherwise
|
|
3091
|
+
* land on whatever the panel was floating over. Inside a modal that is the modal's own
|
|
3092
|
+
* backdrop, and "close the dropdown" would double as "throw away the modal". A first click
|
|
3093
|
+
* that only dismisses the overlay is also how native selects and menus behave.
|
|
3094
|
+
*/
|
|
3095
|
+
onShieldClick(event) {
|
|
3096
|
+
event.stopPropagation();
|
|
3097
|
+
event.preventDefault();
|
|
3098
|
+
this.close();
|
|
3099
|
+
}
|
|
3100
|
+
onDocumentClick(event) {
|
|
3101
|
+
const target = event.target;
|
|
3102
|
+
// The panel lives at the body root once open, so it is not a descendant of the
|
|
3103
|
+
// host element — treat clicks inside the portalled panel as "inside" too.
|
|
3104
|
+
const insideHost = !!target && this.elRef.nativeElement.contains(target);
|
|
3105
|
+
const insidePanel = !!target && !!this.movedPanel && this.movedPanel.contains(target);
|
|
3106
|
+
// In sheet mode the backdrop tap is handled by mn-bottom-sheet's own (dismiss); the
|
|
3107
|
+
// sheet host counts as "inside" here so this listener never double-fires the close.
|
|
3108
|
+
const insideSheet = !!target && !!this.sheetHost && this.sheetHost.contains(target);
|
|
3109
|
+
if (!insideHost && !insidePanel && !insideSheet) {
|
|
3110
|
+
this.close();
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Records the sheet's opened height as its `min-height` floor. Measured on the next
|
|
3115
|
+
* frame so the read reflects the fully-rendered, unfiltered list (the search box is
|
|
3116
|
+
* empty on open) and never forces a reflow mid change-detection. The floor equals the
|
|
3117
|
+
* content height at that instant, so applying it triggers no resize — it only stops a
|
|
3118
|
+
* later, shorter filtered list from pulling the sheet down.
|
|
3119
|
+
*
|
|
3120
|
+
* `hostEl` is the portalled mn-bottom-sheet host (`display: contents`), so the height
|
|
3121
|
+
* is read from its `.mn-sheet-container` child rather than the host itself.
|
|
3122
|
+
*/
|
|
3123
|
+
captureSheetFloor(hostEl) {
|
|
3124
|
+
const measure = () => {
|
|
3125
|
+
const container = hostEl.querySelector('.mn-sheet-container');
|
|
3126
|
+
return container?.offsetHeight ?? hostEl.offsetHeight;
|
|
3127
|
+
};
|
|
3128
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
3129
|
+
this.sheetFloorPx = measure();
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
3132
|
+
requestAnimationFrame(() => {
|
|
3133
|
+
// The sheet may have closed before the frame ran; don't strand a stale floor.
|
|
3134
|
+
if (!this.isOpen || this.sheetHost !== hostEl)
|
|
3135
|
+
return;
|
|
3136
|
+
this.sheetFloorPx = measure();
|
|
3137
|
+
this.cdr.markForCheck();
|
|
3138
|
+
});
|
|
3139
|
+
}
|
|
3140
|
+
/** Closes the dropdown on Escape for keyboard accessibility. */
|
|
3141
|
+
onEscape() {
|
|
3142
|
+
this.close();
|
|
3143
|
+
}
|
|
3144
|
+
/**
|
|
3145
|
+
* Closes the dropdown when the page or a scrollable parent is scrolled.
|
|
3146
|
+
*
|
|
3147
|
+
* Skipped for a sheet: it is anchored to the viewport, not to the trigger, so it has
|
|
3148
|
+
* no stale position to escape. Crucially, opening the soft keyboard fires a `resize`
|
|
3149
|
+
* on Android — closing on that would dismiss the sheet the instant search is focused.
|
|
3150
|
+
* A genuine layout switch is handled by the `matchMedia` listener instead.
|
|
3151
|
+
*/
|
|
3152
|
+
onWindowScrollOrResize() {
|
|
3153
|
+
if (this.isSheet)
|
|
3154
|
+
return;
|
|
3155
|
+
this.close();
|
|
3156
|
+
}
|
|
3157
|
+
/**
|
|
3158
|
+
* The single close path. Every trigger (outside click, Escape, scroll, resize, the
|
|
3159
|
+
* trigger being hidden) funnels through here so the open-only listeners are always
|
|
3160
|
+
* torn down with the panel and never leak.
|
|
3161
|
+
*/
|
|
3162
|
+
close() {
|
|
3163
|
+
if (!this.isOpen)
|
|
3164
|
+
return;
|
|
3165
|
+
this.isOpen = false;
|
|
3166
|
+
this.searchTerm = '';
|
|
3167
|
+
this.activeIndex = -1;
|
|
3168
|
+
this.stopWatchingTrigger();
|
|
3169
|
+
this.unlockBodyScroll();
|
|
3170
|
+
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Freezes the page behind an open sheet. The previous inline value is captured and
|
|
3173
|
+
* restored verbatim so a surrounding modal that set its own lock is left intact.
|
|
3174
|
+
*/
|
|
3175
|
+
lockBodyScroll() {
|
|
3176
|
+
if (this.previousBodyOverflow !== null)
|
|
3177
|
+
return;
|
|
3178
|
+
this.previousBodyOverflow = document.body.style.overflow;
|
|
3179
|
+
this.renderer.setStyle(document.body, 'overflow', 'hidden');
|
|
3180
|
+
}
|
|
3181
|
+
/** Restores the pre-lock `overflow`. Idempotent. */
|
|
3182
|
+
unlockBodyScroll() {
|
|
3183
|
+
if (this.previousBodyOverflow === null)
|
|
3184
|
+
return;
|
|
3185
|
+
if (this.previousBodyOverflow) {
|
|
3186
|
+
this.renderer.setStyle(document.body, 'overflow', this.previousBodyOverflow);
|
|
3187
|
+
}
|
|
3188
|
+
else {
|
|
3189
|
+
this.renderer.removeStyle(document.body, 'overflow');
|
|
3190
|
+
}
|
|
3191
|
+
this.previousBodyOverflow = null;
|
|
3192
|
+
}
|
|
3193
|
+
/**
|
|
3194
|
+
* Calculates the fixed position for the dropdown based on the trigger element: below it
|
|
3195
|
+
* while the viewport has room, above it otherwise, never past the viewport's edge.
|
|
3196
|
+
*/
|
|
3197
|
+
updateDropdownPosition() {
|
|
3198
|
+
if (!this.triggerRef)
|
|
3199
|
+
return;
|
|
3200
|
+
const rect = this.triggerRef.nativeElement.getBoundingClientRect();
|
|
3201
|
+
this.dropdownStyle = {
|
|
3202
|
+
...anchoredPanelPlacement(rect, window.innerHeight, 0, MnMultiSelect.PANEL_MAX_HEIGHT_PX),
|
|
3203
|
+
left: `${rect.left}px`,
|
|
3204
|
+
width: `${rect.width}px`,
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Starts the open-only watchers: an `IntersectionObserver` on the trigger (closes the
|
|
3209
|
+
* panel as soon as the trigger stops being rendered/visible) and a capture-phase
|
|
3210
|
+
* `scroll` listener (closes it when any ancestor scroller moves under it). Scrolls
|
|
3211
|
+
* that originate inside the panel's own option list are ignored.
|
|
3212
|
+
*/
|
|
3213
|
+
startWatchingTrigger() {
|
|
3214
|
+
this.stopWatchingTrigger();
|
|
3215
|
+
const trigger = this.triggerRef?.nativeElement;
|
|
3216
|
+
if (trigger && typeof IntersectionObserver !== 'undefined') {
|
|
3217
|
+
this.visibilityObserver = new IntersectionObserver(entries => {
|
|
3218
|
+
if (!entries.some(entry => !entry.isIntersecting))
|
|
3219
|
+
return;
|
|
3220
|
+
this.close();
|
|
3221
|
+
// The observer fires outside Angular, so a zoneless app needs an explicit nudge.
|
|
3222
|
+
this.cdr.markForCheck();
|
|
3223
|
+
});
|
|
3224
|
+
this.visibilityObserver.observe(trigger);
|
|
3225
|
+
}
|
|
3226
|
+
this.scrollCapture = (event) => {
|
|
3227
|
+
const target = event.target;
|
|
3228
|
+
if (target && this.movedPanel && (this.movedPanel === target || this.movedPanel.contains(target))) {
|
|
3229
|
+
return;
|
|
3230
|
+
}
|
|
3231
|
+
this.close();
|
|
3232
|
+
this.cdr.markForCheck();
|
|
3233
|
+
};
|
|
3234
|
+
document.addEventListener('scroll', this.scrollCapture, true);
|
|
3235
|
+
}
|
|
3236
|
+
/**
|
|
3237
|
+
* Move an overlay element to `document.body` when it appears, and detach it when the
|
|
3238
|
+
* query clears. Appending to the body root makes the element immune to ancestor
|
|
3239
|
+
* `transform`/`filter`/`will-change`, so `position: fixed` anchors to the viewport —
|
|
3240
|
+
* without this the panel lands mid-screen (and breaks outright on iOS).
|
|
3241
|
+
*
|
|
3242
|
+
* Returns the element now portalled, so the caller can store it. Idempotent and safe
|
|
3243
|
+
* to call with `null`.
|
|
3244
|
+
*/
|
|
3245
|
+
portal(el, current) {
|
|
3246
|
+
if (el) {
|
|
3247
|
+
if (current === el)
|
|
3248
|
+
return current;
|
|
3249
|
+
this.renderer.appendChild(document.body, el);
|
|
3250
|
+
return el;
|
|
3251
|
+
}
|
|
3252
|
+
if (current) {
|
|
3253
|
+
// Angular's view teardown may already have removed it; only detach if still attached.
|
|
3254
|
+
const parent = current.parentNode;
|
|
3255
|
+
if (parent) {
|
|
3256
|
+
this.renderer.removeChild(parent, current);
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
return null;
|
|
3260
|
+
}
|
|
3261
|
+
/** Tears down the watchers installed by `startWatchingTrigger`. Idempotent. */
|
|
3262
|
+
stopWatchingTrigger() {
|
|
3263
|
+
this.visibilityObserver?.disconnect();
|
|
3264
|
+
this.visibilityObserver = null;
|
|
3265
|
+
if (this.scrollCapture) {
|
|
3266
|
+
document.removeEventListener('scroll', this.scrollCapture, true);
|
|
3267
|
+
this.scrollCapture = null;
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
toggleOption(option) {
|
|
3271
|
+
if (option.disabled)
|
|
3272
|
+
return;
|
|
3273
|
+
const index = this.selectedValues.indexOf(option.value);
|
|
3274
|
+
if (index > -1) {
|
|
3275
|
+
this.selectedValues = this.selectedValues.filter(v => v !== option.value);
|
|
3276
|
+
}
|
|
3277
|
+
else {
|
|
3278
|
+
if (this.props.maxSelections && this.selectedValues.length >= this.props.maxSelections) {
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
this.selectedValues = [...this.selectedValues, option.value];
|
|
3282
|
+
}
|
|
3283
|
+
this.onChange(this.selectedValues);
|
|
3284
|
+
}
|
|
3285
|
+
removeOption(option, event) {
|
|
3286
|
+
event.stopPropagation();
|
|
3287
|
+
this.selectedValues = this.selectedValues.filter(v => v !== option.value);
|
|
3288
|
+
this.onChange(this.selectedValues);
|
|
3289
|
+
}
|
|
3290
|
+
isSelected(option) {
|
|
3291
|
+
return this.selectedValues.includes(option.value);
|
|
3292
|
+
}
|
|
3293
|
+
isMaxReached(option) {
|
|
3294
|
+
if (!this.props.maxSelections)
|
|
3295
|
+
return false;
|
|
3296
|
+
return this.selectedValues.length >= this.props.maxSelections && !this.isSelected(option);
|
|
3297
|
+
}
|
|
3298
|
+
/** Filters the options; the first match is highlighted so Enter toggles it, none once the box is cleared. */
|
|
3299
|
+
onSearch(term) {
|
|
3300
|
+
this.searchTerm = term;
|
|
3301
|
+
this.activeIndex = this.searchTerm ? stepEnabledIndex(this.filteredOptions, -1, 1, this.isChoosable) : -1;
|
|
3302
|
+
}
|
|
3303
|
+
/**
|
|
3304
|
+
* Whether the keyboard may highlight an option: not disabled, and not blocked by `maxSelections`.
|
|
3305
|
+
* An arrow function so it can be handed to `stepEnabledIndex` as it is.
|
|
3306
|
+
*/
|
|
3307
|
+
isChoosable = (option) => !option.disabled && !this.isMaxReached(option);
|
|
3308
|
+
/** Id of the keyboard-highlighted option, for `aria-activedescendant`; null when none is. */
|
|
3309
|
+
get activeOptionId() {
|
|
3310
|
+
const inRange = this.activeIndex >= 0 && this.activeIndex < this.filteredOptions.length;
|
|
3311
|
+
return this.isOpen && inRange ? this.optionId(this.activeIndex) : null;
|
|
3312
|
+
}
|
|
3313
|
+
/**
|
|
3314
|
+
* The DOM id of the option rendered at a position in `filteredOptions`.
|
|
3315
|
+
* @param index - The option's position.
|
|
3316
|
+
* @returns The id, unique per multi-select.
|
|
3317
|
+
*/
|
|
3318
|
+
optionId(index) {
|
|
3319
|
+
return `${this.resolvedId}-option-${index}`;
|
|
3320
|
+
}
|
|
3321
|
+
/**
|
|
3322
|
+
* Keyboard handling for the trigger and the search box, the WAI-ARIA combobox pattern. While
|
|
3323
|
+
* closed, ArrowDown, ArrowUp, Enter and Space open the list with an option highlighted. While
|
|
3324
|
+
* open, the arrows move the highlight past disabled options without wrapping, Home and End jump
|
|
3325
|
+
* to the ends, Enter (and Space outside the search box) toggles the highlighted option and keeps the list open for the next one, Escape closes and Tab closes and lets focus move on. Enter and Space
|
|
3326
|
+
* stop here, so they can never submit a surrounding form or close a surrounding modal.
|
|
3327
|
+
* @param event - The keydown.
|
|
3328
|
+
* @param fromSearch - True when it came from the search box, where Space, Home and End edit text.
|
|
3329
|
+
*/
|
|
3330
|
+
onKeydown(event, fromSearch = false) {
|
|
3331
|
+
if (this.isDisabled)
|
|
3332
|
+
return;
|
|
3333
|
+
// Keys on a chip's remove button bubble up through the trigger; they are that button's own.
|
|
3334
|
+
if (!fromSearch && event.target !== event.currentTarget)
|
|
3335
|
+
return;
|
|
3336
|
+
if (!this.isOpen) {
|
|
3337
|
+
if (fromSearch || !['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key))
|
|
3338
|
+
return;
|
|
3339
|
+
this.claim(event);
|
|
3340
|
+
this.toggle();
|
|
3341
|
+
this.moveActive(-1, event.key === 'ArrowUp' ? -1 : 1);
|
|
3342
|
+
return;
|
|
3343
|
+
}
|
|
3344
|
+
switch (event.key) {
|
|
3345
|
+
case 'ArrowDown':
|
|
3346
|
+
case 'ArrowUp':
|
|
3347
|
+
this.claim(event);
|
|
3348
|
+
this.moveActive(this.activeIndex, event.key === 'ArrowDown' ? 1 : -1);
|
|
3349
|
+
return;
|
|
3350
|
+
case 'Home':
|
|
3351
|
+
case 'End':
|
|
3352
|
+
if (fromSearch)
|
|
3353
|
+
return;
|
|
3354
|
+
this.claim(event);
|
|
3355
|
+
this.moveActive(-1, event.key === 'Home' ? 1 : -1);
|
|
3356
|
+
return;
|
|
3357
|
+
case ' ':
|
|
3358
|
+
if (fromSearch)
|
|
3359
|
+
return;
|
|
3360
|
+
this.toggleActive(event);
|
|
3361
|
+
return;
|
|
3362
|
+
case 'Enter':
|
|
3363
|
+
this.toggleActive(event);
|
|
3364
|
+
return;
|
|
3365
|
+
case 'Escape':
|
|
3366
|
+
this.claim(event);
|
|
3367
|
+
this.close();
|
|
3368
|
+
this.focusTrigger();
|
|
3369
|
+
return;
|
|
3370
|
+
case 'Tab':
|
|
3371
|
+
// Focus moves on from the trigger, so the search box's Tab order position never matters.
|
|
3372
|
+
this.close();
|
|
3373
|
+
this.focusTrigger();
|
|
3374
|
+
return;
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
/**
|
|
3378
|
+
* Moves the highlight one enabled option from `from` and scrolls it into view.
|
|
3379
|
+
* @param from - Where to step from; -1 to start at an end.
|
|
3380
|
+
* @param step - 1 for down, -1 for up.
|
|
3381
|
+
*/
|
|
3382
|
+
moveActive(from, step) {
|
|
3383
|
+
this.activeIndex = stepEnabledIndex(this.filteredOptions, from, step, this.isChoosable);
|
|
3384
|
+
this.revealActiveOption();
|
|
3385
|
+
}
|
|
3386
|
+
/**
|
|
3387
|
+
* Toggles the highlighted option. The list stays open, as it does for a click, so several options
|
|
3388
|
+
* can be picked in a row.
|
|
3389
|
+
* @param event - The Enter or Space keydown, claimed so a form around the field is not submitted.
|
|
3390
|
+
*/
|
|
3391
|
+
toggleActive(event) {
|
|
3392
|
+
this.claim(event);
|
|
3393
|
+
const option = this.filteredOptions[this.activeIndex];
|
|
3394
|
+
if (option && this.isChoosable(option)) {
|
|
3395
|
+
this.toggleOption(option);
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Takes a key for the field: no default action (no scroll, no form submit) and no bubbling to a
|
|
3400
|
+
* surrounding modal's own Enter or Escape handling.
|
|
3401
|
+
* @param event - The keydown to claim.
|
|
3402
|
+
*/
|
|
3403
|
+
claim(event) {
|
|
3404
|
+
event.preventDefault();
|
|
3405
|
+
event.stopPropagation();
|
|
3406
|
+
}
|
|
3407
|
+
/** Scrolls the highlighted option into view once the render that paints its ring has run. */
|
|
3408
|
+
revealActiveOption() {
|
|
3409
|
+
afterNextRender(() => {
|
|
3410
|
+
const id = this.activeOptionId;
|
|
3411
|
+
scrollOptionIntoView(id ? document.getElementById(id) : null);
|
|
3412
|
+
}, { injector: this.injector });
|
|
3413
|
+
}
|
|
3414
|
+
/** Puts focus back on the trigger. */
|
|
3415
|
+
focusTrigger() {
|
|
3416
|
+
this.triggerRef?.nativeElement.focus();
|
|
3417
|
+
}
|
|
3418
|
+
get filteredOptions() {
|
|
3419
|
+
if (!this.searchTerm)
|
|
3420
|
+
return this.props.options;
|
|
3421
|
+
const lower = this.searchTerm.toLowerCase();
|
|
3422
|
+
return this.props.options.filter(o => o.label.toLowerCase().includes(lower));
|
|
3423
|
+
}
|
|
3424
|
+
get selectedOptions() {
|
|
3425
|
+
return this.props.options.filter(o => this.selectedValues.includes(o.value));
|
|
3426
|
+
}
|
|
3427
|
+
// ========== Collapse Summary ==========
|
|
3428
|
+
/**
|
|
3429
|
+
* Whether the collapse-to-summary feature is opted into. Active when any of
|
|
3430
|
+
* `collapsePlaceholder`, `collapseThreshold` or `allSelectedPlaceholder` is
|
|
3431
|
+
* supplied; existing usages with none of them are unaffected.
|
|
3432
|
+
*/
|
|
3433
|
+
get collapseEnabled() {
|
|
3434
|
+
return (this.props.collapsePlaceholder !== undefined ||
|
|
3435
|
+
this.props.collapseThreshold !== undefined ||
|
|
3436
|
+
this.props.allSelectedPlaceholder !== undefined);
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* Whether every available option is currently selected. False for an empty select, where
|
|
3440
|
+
* "all of them" would be a claim about nothing.
|
|
3441
|
+
*/
|
|
3442
|
+
get allSelected() {
|
|
3443
|
+
return this.props.options.length > 0 && this.selectedOptions.length === this.props.options.length;
|
|
3444
|
+
}
|
|
3445
|
+
/**
|
|
3446
|
+
* The threshold above which the trigger collapses. Defaults to 5 when collapsing
|
|
3447
|
+
* is enabled via `collapsePlaceholder` alone (no explicit `collapseThreshold`).
|
|
3448
|
+
*/
|
|
3449
|
+
get effectiveCollapseThreshold() {
|
|
3450
|
+
return this.props.collapseThreshold ?? 5;
|
|
3451
|
+
}
|
|
3452
|
+
/**
|
|
3453
|
+
* Whether the trigger should currently render a summary instead of the individual
|
|
3454
|
+
* chips: when the number of selected options exceeds the effective threshold, or
|
|
3455
|
+
* when every option is selected and a summary for that case was supplied.
|
|
3456
|
+
*/
|
|
3457
|
+
get isCollapsed() {
|
|
3458
|
+
if (!this.collapseEnabled)
|
|
3459
|
+
return false;
|
|
3460
|
+
// "Everything is selected" is worth saying at any count, so it collapses on its own rather
|
|
3461
|
+
// than waiting for the threshold a small option list would never reach.
|
|
3462
|
+
if (this.allSelected && this.props.allSelectedPlaceholder !== undefined)
|
|
3463
|
+
return true;
|
|
3464
|
+
return this.selectedOptions.length > this.effectiveCollapseThreshold;
|
|
3465
|
+
}
|
|
3466
|
+
/**
|
|
3467
|
+
* The summary text shown while collapsed, with the `{count}` token replaced by
|
|
3468
|
+
* the number of selected options. `allSelectedPlaceholder` wins while everything
|
|
3469
|
+
* is selected, then `collapsePlaceholder`, then `"{count} selected"`.
|
|
3470
|
+
*/
|
|
3471
|
+
get collapseSummaryText() {
|
|
3472
|
+
const allSelectedTemplate = this.allSelected ? this.props.allSelectedPlaceholder : undefined;
|
|
3473
|
+
const template = allSelectedTemplate ??
|
|
3474
|
+
this.props.collapsePlaceholder ??
|
|
3475
|
+
this.resolveLabel(undefined, 'mnMultiSelect.selectedCount', '{count} selected');
|
|
3476
|
+
return template.replace(/\{count}/g, String(this.selectedOptions.length));
|
|
3477
|
+
}
|
|
3478
|
+
/** Trigger text shown while nothing is selected. */
|
|
3479
|
+
get placeholderLabel() {
|
|
3480
|
+
return this.resolveLabel(this.props.placeholder, 'mnMultiSelect.placeholder', 'Select...', this.uiConfig.placeholder);
|
|
3481
|
+
}
|
|
3482
|
+
/**
|
|
3483
|
+
* Placeholder and accessible name of the dropdown's search input.
|
|
3484
|
+
*
|
|
3485
|
+
* Search auto-enables at `searchThreshold` options, so this box appears without any
|
|
3486
|
+
* call site opting in — which is exactly why it must be translatable without one.
|
|
3487
|
+
*/
|
|
3488
|
+
get searchPlaceholderLabel() {
|
|
3489
|
+
return this.resolveLabel(this.props.searchPlaceholder, 'mnMultiSelect.search', 'Search...', this.uiConfig.searchPlaceholder);
|
|
3490
|
+
}
|
|
3491
|
+
/** Empty text shown when the search filters every option away. */
|
|
3492
|
+
get noOptionsLabel() {
|
|
3493
|
+
return this.resolveLabel(undefined, 'mnMultiSelect.noOptions', 'No options found', this.uiConfig.noOptionsFound);
|
|
3494
|
+
}
|
|
3495
|
+
/**
|
|
3496
|
+
* Resolves one of the component's own labels, preferring what the caller gave it
|
|
3497
|
+
* and falling back through the config layer, a conventional translation key and
|
|
3498
|
+
* finally a readable English default.
|
|
3499
|
+
*
|
|
3500
|
+
* Mirrors `MnCollectionBase.resolveLabel`. Every string this component puts on
|
|
3501
|
+
* screen that is not caller data goes through here: without the key step a
|
|
3502
|
+
* consumer could only translate these by repeating the same literal at every call
|
|
3503
|
+
* site, which is how "Search..." ends up in English on an otherwise Dutch page.
|
|
3504
|
+
*
|
|
3505
|
+
* @param explicit The label the caller passed through `props`, if any.
|
|
3506
|
+
* @param key The conventional translation key to try next.
|
|
3507
|
+
* @param fallback The English text used when neither resolves.
|
|
3508
|
+
* @param configured The value the config layer resolved, if any.
|
|
3509
|
+
* @returns The resolved label.
|
|
3510
|
+
*/
|
|
3511
|
+
resolveLabel(explicit, key, fallback, configured) {
|
|
3512
|
+
return explicit ?? configured ?? this.lang.translateIfPresent(key) ?? fallback;
|
|
3513
|
+
}
|
|
3514
|
+
handleBlur() {
|
|
3515
|
+
this.onTouched();
|
|
3516
|
+
}
|
|
3517
|
+
// ========== Error Handling ==========
|
|
3518
|
+
get control() {
|
|
3519
|
+
return this.ngControl?.control ?? null;
|
|
3520
|
+
}
|
|
3521
|
+
get showError() {
|
|
3522
|
+
const c = this.control;
|
|
3523
|
+
return !!c && c.invalid && (c.touched || c.dirty);
|
|
3524
|
+
}
|
|
3525
|
+
pickErrorKey(errors) {
|
|
3526
|
+
if (this.props.errorPriority) {
|
|
3527
|
+
for (const key of this.props.errorPriority) {
|
|
3528
|
+
if (errors[key] !== undefined) {
|
|
3529
|
+
return key;
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
return Object.keys(errors)[0];
|
|
3534
|
+
}
|
|
3535
|
+
isRequired() {
|
|
3536
|
+
if (!this.control)
|
|
3537
|
+
return false;
|
|
3538
|
+
return this.control.hasValidator(Validators.required);
|
|
3539
|
+
}
|
|
3540
|
+
resolveErrorMessageForKey(errorKey, errors) {
|
|
3541
|
+
const errorArgs = errors[errorKey];
|
|
3542
|
+
const customMsg = this.props.errorMessages?.[errorKey];
|
|
3543
|
+
const configMsg = this.uiConfig.errorMessages?.[errorKey];
|
|
3544
|
+
const useBuiltIn = this.props.useBuiltInErrorMessages !== false;
|
|
3545
|
+
const builtInMsg = useBuiltIn ? this.builtInErrorMessages[errorKey] : undefined;
|
|
3546
|
+
const fallbackMsg = this.props.defaultErrorMessage;
|
|
3547
|
+
const msgDef = customMsg ?? configMsg ?? builtInMsg ?? fallbackMsg ?? 'Invalid input';
|
|
3548
|
+
if (typeof msgDef === 'function') {
|
|
3549
|
+
return msgDef(errorArgs, errors);
|
|
3550
|
+
}
|
|
3551
|
+
// Interpolate {{placeholder}} tokens with validation error args
|
|
3552
|
+
if (errorArgs && typeof errorArgs === 'object') {
|
|
3553
|
+
return msgDef.replace(/\{\{(\w+)}}/g, (_, key) => errorArgs[key] ?? _);
|
|
3554
|
+
}
|
|
3555
|
+
return msgDef;
|
|
3556
|
+
}
|
|
3557
|
+
get errorMessages() {
|
|
3558
|
+
const errors = this.control?.errors;
|
|
3559
|
+
if (!errors)
|
|
3560
|
+
return [];
|
|
3561
|
+
return Object.keys(errors).map(key => this.resolveErrorMessageForKey(key, errors));
|
|
3562
|
+
}
|
|
3563
|
+
get errorMessage() {
|
|
3564
|
+
const errors = this.control?.errors;
|
|
3565
|
+
if (!errors)
|
|
3566
|
+
return null;
|
|
3567
|
+
const errorKey = this.pickErrorKey(errors);
|
|
3568
|
+
return this.resolveErrorMessageForKey(errorKey, errors);
|
|
3569
|
+
}
|
|
3570
|
+
// ========== Resolved Properties ==========
|
|
3571
|
+
get resolvedId() {
|
|
3572
|
+
return this.props.id;
|
|
3573
|
+
}
|
|
3574
|
+
get resolvedName() {
|
|
3575
|
+
return this.props?.name ?? null;
|
|
3576
|
+
}
|
|
3577
|
+
get triggerClasses() {
|
|
3578
|
+
return mnMultiSelectVariants({
|
|
3579
|
+
size: this.props.size,
|
|
3580
|
+
borderRadius: this.props.borderRadius,
|
|
3581
|
+
shadow: this.props.shadow,
|
|
3582
|
+
fullWidth: this.props.fullWidth,
|
|
3583
|
+
});
|
|
3584
|
+
}
|
|
3585
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnMultiSelect, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3586
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnMultiSelect, isStandalone: true, selector: "mn-lib-multi-select", inputs: { props: "props" }, host: { listeners: { "document:click": "onDocumentClick($event)", "document:keydown.escape": "onEscape()", "window:scroll": "onWindowScrollOrResize()", "window:resize": "onWindowScrollOrResize()" } }, viewQueries: [{ propertyName: "triggerRef", first: true, predicate: ["trigger"], descendants: true }, { propertyName: "dropdownRef", first: true, predicate: ["dropdown"], descendants: true }, { propertyName: "shieldRef", first: true, predicate: ["shield"], descendants: true }, { propertyName: "sheetRef", first: true, predicate: ["sheet"], descendants: true, read: ElementRef }], ngImport: i0, template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n @if (uiConfig.label || props.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Trigger -->\n <div\n #trigger\n [id]=\"resolvedId\"\n [ngClass]=\"triggerClasses\"\n class=\"relative\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || props.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-controls]=\"isOpen ? resolvedId + '-listbox' : null\"\n role=\"combobox\"\n [attr.aria-required]=\"isRequired() || null\"\n tabindex=\"0\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n [attr.aria-activedescendant]=\"activeOptionId\"\n (blur)=\"handleBlur()\"\n >\n <!-- `pr-6` reserves the gutter the caret is absolutely positioned in (right-2 +\n w-4), so a value can never render underneath it. `min-w-0` lets the chips\n shrink below their content width, which is what makes truncation possible. -->\n <div class=\"flex flex-row items-center gap-x-2 flex-wrap min-h-6 min-w-0 pr-6\">\n @if (selectedOptions.length === 0) {\n <span class=\"text-base-content/50\">{{ placeholderLabel }}</span>\n } @else if (isCollapsed) {\n <span\n class=\"inline-flex items-center max-w-full truncate bg-base-200 border border-accent text-base-content text-xs px-2 py-0.5 rounded-md\">\n {{ collapseSummaryText }}\n </span>\n } @else {\n @for (opt of selectedOptions; track opt.value) {\n <!-- Only the \u00D7 removes. The chip body deliberately carries no handler, so a click\n anywhere on it bubbles to the trigger and just opens/closes the panel \u2014 clicking\n the trigger to dismiss the dropdown must never silently delete a selection. -->\n <span\n class=\"inline-flex items-center gap-x-1 max-w-full min-w-0 bg-base-200 border border-accent text-base-content text-xs pl-2 py-0.5 rounded-md\">\n <span [attr.title]=\"opt.label\" class=\"truncate\">{{ opt.label }}</span>\n <button\n mnButton\n [data]=\"{ size: 'sm', variant: 'text', color: 'secondary', hover: false }\"\n type=\"button\"\n class=\"text-base-content/50 cursor-pointer shrink-0\"\n (click)=\"removeOption(opt, $event)\"\n [attr.aria-label]=\"'Remove ' + opt.label\"\n ><svg [lucideIcon]=\"icons.X\" [size]=\"18\"></svg></button>\n </span>\n }\n }\n </div>\n <div class=\"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none\">\n <svg [size]=\"16\" class=\"text-base-content/50\" [lucideIcon]=\"icons.ChevronDown\"></svg>\n </div>\n </div>\n\n <!-- Dropdown -->\n @if (isOpen) {\n @if (isSheet) {\n <!-- On mobile the panel is presented as a shared bottom sheet: the sheet chrome\n (backdrop, grabber, swipe/flick-to-dismiss, slide animation) lives in\n mn-bottom-sheet; this component only projects the field's content into it.\n The sheet host is portalled to document.body (see the `sheet` ViewChild) so\n its `position: fixed` anchors to the viewport, not a transformed ancestor. -->\n <mn-bottom-sheet\n #sheet\n (dismiss)=\"close()\"\n [ariaLabel]=\"uiConfig.ariaLabel || uiConfig.label || props.label || uiConfig.placeholder || props.placeholder\"\n [maxHeightVh]=\"80\"\n [minHeightPx]=\"sheetFloorPx\"\n >\n <div\n [id]=\"resolvedId + '-listbox'\"\n aria-multiselectable=\"true\"\n class=\"flex flex-col flex-1 min-h-0 overflow-hidden\"\n role=\"listbox\"\n >\n <!-- The sheet covers its own trigger, so it carries a header to name the field; the\n way out is the grabber (swipe-to-dismiss) and a backdrop tap. -->\n <div class=\"px-4 pt-1 pb-2 shrink-0\">\n <p class=\"text-base font-medium text-base-content truncate\">\n {{ uiConfig.label || props.label || uiConfig.placeholder || props.placeholder || '' }}\n </p>\n </div>\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n </mn-bottom-sheet>\n } @else {\n <!-- A transparent full-viewport shield behind the panel, so \"click anywhere to\n dismiss\" is literally true. It also *consumes* that click: without it the click\n reaches whatever sits underneath \u2014 inside a modal that is the modal's own\n backdrop, so dismissing the dropdown would tear down the whole modal with it.\n Portalled to document.body for the same reason the panel is. It is aria-hidden\n and unfocusable: the keyboard equivalent of this click is Escape. -->\n <div\n #shield\n (click)=\"onShieldClick($event)\"\n [id]=\"resolvedId + '-shield'\"\n [ngClass]=\"shieldClasses\"\n aria-hidden=\"true\"\n ></div>\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n #dropdown\n (click)=\"$event.stopPropagation()\"\n [id]=\"resolvedId + '-listbox'\"\n [ngClass]=\"panelClasses\"\n [style.left]=\"dropdownStyle.left\"\n [style.top]=\"dropdownStyle.top\"\n [style.bottom]=\"dropdownStyle.bottom\"\n [style.max-height]=\"dropdownStyle.maxHeight\"\n [style.width]=\"dropdownStyle.width\"\n aria-multiselectable=\"true\"\n role=\"listbox\"\n >\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n }\n }\n\n <!-- The search box + option list, shared verbatim by the sheet and the anchored\n popover. `isSheet` only tunes spacing/sizing and which element scrolls: in sheet\n mode the list is the flex scroller; anchored, the popover itself scrolls. -->\n <ng-template #panelBody>\n @if (isSearchable) {\n <!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"$event.stopPropagation()\"\n (keydown)=\"onKeydown($event, true)\"\n [ngClass]=\"isSheet ? 'px-4 py-2' : 'p-2'\"\n class=\"border-b border-base-300 shrink-0\"\n >\n <mn-lib-input-field\n (ngModelChange)=\"onSearch($event)\"\n [ngModelOptions]=\"{ standalone: true }\"\n [ngModel]=\"searchTerm\"\n [props]=\"{\n id: resolvedId + '-search',\n type: 'search',\n placeholder: searchPlaceholderLabel,\n ariaLabel: searchPlaceholderLabel,\n ariaActiveDescendant: activeOptionId,\n fullWidth: true,\n size: 'sm'\n }\"\n ></mn-lib-input-field>\n </div>\n }\n <div [ngClass]=\"isSheet ? 'flex-1 overflow-auto overscroll-contain' : ''\">\n @for (opt of filteredOptions; track opt.value) {\n <!-- Options are not Tab stops: the keyboard reaches them with the arrow keys while focus\n stays on the trigger or the search box, and `aria-activedescendant` names the one it\n is on. The ring marks that option, since it never receives real focus. -->\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"toggleOption(opt); $event.stopPropagation()\"\n [attr.aria-disabled]=\"opt.disabled || isMaxReached(opt) || null\"\n [attr.aria-selected]=\"isSelected(opt)\"\n [class.opacity-50]=\"opt.disabled || isMaxReached(opt)\"\n [class.pointer-events-none]=\"opt.disabled || isMaxReached(opt)\"\n [id]=\"optionId($index)\"\n [ngClass]=\"[isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm', $index === activeIndex ? 'ring-2 ring-inset ring-primary' : '']\"\n class=\"flex items-center gap-x-2 cursor-pointer text-base-content hover:bg-base-200\"\n role=\"option\"\n >\n <input\n [checked]=\"isSelected(opt)\"\n [disabled]=\"opt.disabled || isMaxReached(opt)\"\n class=\"w-4 h-4 accent-primary pointer-events-none shrink-0\"\n tabindex=\"-1\"\n type=\"checkbox\"\n />\n <span>{{ opt.label }}</span>\n </div>\n }\n @if (filteredOptions.length === 0) {\n <div [ngClass]=\"isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm'\" class=\"text-base-content/50\">\n {{ noOptionsLabel }}\n </div>\n }\n </div>\n </ng-template>\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1 mt-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n", styles: [""], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: MnErrorMessage, selector: "mn-error-message", inputs: ["errorMessage", "id"] }, { kind: "component", type: MnButton, selector: "button[mnButton], a[mnButton]", inputs: ["data"] }, { kind: "component", type: MnInputField, selector: "mn-lib-input-field", inputs: ["props"] }, { kind: "component", type: MnBottomSheet, selector: "mn-bottom-sheet", inputs: ["showBackdrop", "showGrabber", "dismissible", "minHeightPx", "maxHeightVh", "containerClass", "ariaLabel", "ariaLabelledby", "growWithKeyboard", "dismissGuard"], outputs: ["dismiss"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }] });
|
|
3587
|
+
}
|
|
3588
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnMultiSelect, decorators: [{
|
|
3589
|
+
type: Component,
|
|
3590
|
+
args: [{ selector: 'mn-lib-multi-select', standalone: true, imports: [NgClass, NgTemplateOutlet, FormsModule, MnErrorMessage, MnButton, MnInputField, MnBottomSheet, LucideDynamicIcon], template: "<div class=\"flex flex-col h-full\" [class.is-fullwidth]=\"props.fullWidth\">\n @if (uiConfig.label || props.label) {\n <label class=\"pl-2 pb-1 flex flex-row gap-x-0.5! text-base!\" [attr.for]=\"resolvedId\">\n <p>{{ uiConfig.label || props.label }}</p>\n @if (isRequired()) {\n <span class=\"text-error\" aria-hidden=\"true\">*</span>\n }\n </label>\n }\n\n <!-- Trigger -->\n <div\n #trigger\n [id]=\"resolvedId\"\n [ngClass]=\"triggerClasses\"\n class=\"relative\"\n [attr.aria-label]=\"uiConfig.ariaLabel || uiConfig.label || props.label || null\"\n [attr.aria-invalid]=\"showError || null\"\n [attr.aria-describedby]=\"showError ? resolvedId + '-error' : null\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-controls]=\"isOpen ? resolvedId + '-listbox' : null\"\n role=\"combobox\"\n [attr.aria-required]=\"isRequired() || null\"\n tabindex=\"0\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n [attr.aria-activedescendant]=\"activeOptionId\"\n (blur)=\"handleBlur()\"\n >\n <!-- `pr-6` reserves the gutter the caret is absolutely positioned in (right-2 +\n w-4), so a value can never render underneath it. `min-w-0` lets the chips\n shrink below their content width, which is what makes truncation possible. -->\n <div class=\"flex flex-row items-center gap-x-2 flex-wrap min-h-6 min-w-0 pr-6\">\n @if (selectedOptions.length === 0) {\n <span class=\"text-base-content/50\">{{ placeholderLabel }}</span>\n } @else if (isCollapsed) {\n <span\n class=\"inline-flex items-center max-w-full truncate bg-base-200 border border-accent text-base-content text-xs px-2 py-0.5 rounded-md\">\n {{ collapseSummaryText }}\n </span>\n } @else {\n @for (opt of selectedOptions; track opt.value) {\n <!-- Only the \u00D7 removes. The chip body deliberately carries no handler, so a click\n anywhere on it bubbles to the trigger and just opens/closes the panel \u2014 clicking\n the trigger to dismiss the dropdown must never silently delete a selection. -->\n <span\n class=\"inline-flex items-center gap-x-1 max-w-full min-w-0 bg-base-200 border border-accent text-base-content text-xs pl-2 py-0.5 rounded-md\">\n <span [attr.title]=\"opt.label\" class=\"truncate\">{{ opt.label }}</span>\n <button\n mnButton\n [data]=\"{ size: 'sm', variant: 'text', color: 'secondary', hover: false }\"\n type=\"button\"\n class=\"text-base-content/50 cursor-pointer shrink-0\"\n (click)=\"removeOption(opt, $event)\"\n [attr.aria-label]=\"'Remove ' + opt.label\"\n ><svg [lucideIcon]=\"icons.X\" [size]=\"18\"></svg></button>\n </span>\n }\n }\n </div>\n <div class=\"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none\">\n <svg [size]=\"16\" class=\"text-base-content/50\" [lucideIcon]=\"icons.ChevronDown\"></svg>\n </div>\n </div>\n\n <!-- Dropdown -->\n @if (isOpen) {\n @if (isSheet) {\n <!-- On mobile the panel is presented as a shared bottom sheet: the sheet chrome\n (backdrop, grabber, swipe/flick-to-dismiss, slide animation) lives in\n mn-bottom-sheet; this component only projects the field's content into it.\n The sheet host is portalled to document.body (see the `sheet` ViewChild) so\n its `position: fixed` anchors to the viewport, not a transformed ancestor. -->\n <mn-bottom-sheet\n #sheet\n (dismiss)=\"close()\"\n [ariaLabel]=\"uiConfig.ariaLabel || uiConfig.label || props.label || uiConfig.placeholder || props.placeholder\"\n [maxHeightVh]=\"80\"\n [minHeightPx]=\"sheetFloorPx\"\n >\n <div\n [id]=\"resolvedId + '-listbox'\"\n aria-multiselectable=\"true\"\n class=\"flex flex-col flex-1 min-h-0 overflow-hidden\"\n role=\"listbox\"\n >\n <!-- The sheet covers its own trigger, so it carries a header to name the field; the\n way out is the grabber (swipe-to-dismiss) and a backdrop tap. -->\n <div class=\"px-4 pt-1 pb-2 shrink-0\">\n <p class=\"text-base font-medium text-base-content truncate\">\n {{ uiConfig.label || props.label || uiConfig.placeholder || props.placeholder || '' }}\n </p>\n </div>\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n </mn-bottom-sheet>\n } @else {\n <!-- A transparent full-viewport shield behind the panel, so \"click anywhere to\n dismiss\" is literally true. It also *consumes* that click: without it the click\n reaches whatever sits underneath \u2014 inside a modal that is the modal's own\n backdrop, so dismissing the dropdown would tear down the whole modal with it.\n Portalled to document.body for the same reason the panel is. It is aria-hidden\n and unfocusable: the keyboard equivalent of this click is Escape. -->\n <div\n #shield\n (click)=\"onShieldClick($event)\"\n [id]=\"resolvedId + '-shield'\"\n [ngClass]=\"shieldClasses\"\n aria-hidden=\"true\"\n ></div>\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n #dropdown\n (click)=\"$event.stopPropagation()\"\n [id]=\"resolvedId + '-listbox'\"\n [ngClass]=\"panelClasses\"\n [style.left]=\"dropdownStyle.left\"\n [style.top]=\"dropdownStyle.top\"\n [style.bottom]=\"dropdownStyle.bottom\"\n [style.max-height]=\"dropdownStyle.maxHeight\"\n [style.width]=\"dropdownStyle.width\"\n aria-multiselectable=\"true\"\n role=\"listbox\"\n >\n <ng-container [ngTemplateOutlet]=\"panelBody\"></ng-container>\n </div>\n }\n }\n\n <!-- The search box + option list, shared verbatim by the sheet and the anchored\n popover. `isSheet` only tunes spacing/sizing and which element scrolls: in sheet\n mode the list is the flex scroller; anchored, the popover itself scrolls. -->\n <ng-template #panelBody>\n @if (isSearchable) {\n <!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"$event.stopPropagation()\"\n (keydown)=\"onKeydown($event, true)\"\n [ngClass]=\"isSheet ? 'px-4 py-2' : 'p-2'\"\n class=\"border-b border-base-300 shrink-0\"\n >\n <mn-lib-input-field\n (ngModelChange)=\"onSearch($event)\"\n [ngModelOptions]=\"{ standalone: true }\"\n [ngModel]=\"searchTerm\"\n [props]=\"{\n id: resolvedId + '-search',\n type: 'search',\n placeholder: searchPlaceholderLabel,\n ariaLabel: searchPlaceholderLabel,\n ariaActiveDescendant: activeOptionId,\n fullWidth: true,\n size: 'sm'\n }\"\n ></mn-lib-input-field>\n </div>\n }\n <div [ngClass]=\"isSheet ? 'flex-1 overflow-auto overscroll-contain' : ''\">\n @for (opt of filteredOptions; track opt.value) {\n <!-- Options are not Tab stops: the keyboard reaches them with the arrow keys while focus\n stays on the trigger or the search box, and `aria-activedescendant` names the one it\n is on. The ring marks that option, since it never receives real focus. -->\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"toggleOption(opt); $event.stopPropagation()\"\n [attr.aria-disabled]=\"opt.disabled || isMaxReached(opt) || null\"\n [attr.aria-selected]=\"isSelected(opt)\"\n [class.opacity-50]=\"opt.disabled || isMaxReached(opt)\"\n [class.pointer-events-none]=\"opt.disabled || isMaxReached(opt)\"\n [id]=\"optionId($index)\"\n [ngClass]=\"[isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm', $index === activeIndex ? 'ring-2 ring-inset ring-primary' : '']\"\n class=\"flex items-center gap-x-2 cursor-pointer text-base-content hover:bg-base-200\"\n role=\"option\"\n >\n <input\n [checked]=\"isSelected(opt)\"\n [disabled]=\"opt.disabled || isMaxReached(opt)\"\n class=\"w-4 h-4 accent-primary pointer-events-none shrink-0\"\n tabindex=\"-1\"\n type=\"checkbox\"\n />\n <span>{{ opt.label }}</span>\n </div>\n }\n @if (filteredOptions.length === 0) {\n <div [ngClass]=\"isSheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm'\" class=\"text-base-content/50\">\n {{ noOptionsLabel }}\n </div>\n }\n </div>\n </ng-template>\n\n @if (showError) {\n @if (props.showAllErrors) {\n <div class=\"flex flex-col gap-y-1 mt-1\">\n @for (error of errorMessages; track $index) {\n <mn-error-message [errorMessage]=\"error\" [id]=\"resolvedId + '-' + $index\"></mn-error-message>\n }\n </div>\n } @else {\n @if (errorMessage !== null) {\n <mn-error-message [errorMessage]=\"errorMessage\" [id]=\"resolvedId\"></mn-error-message>\n }\n }\n }\n</div>\n" }]
|
|
3591
|
+
}], ctorParameters: () => [], propDecorators: { props: [{
|
|
3592
|
+
type: Input,
|
|
3593
|
+
args: [{ required: true }]
|
|
3594
|
+
}], triggerRef: [{
|
|
3595
|
+
type: ViewChild,
|
|
3596
|
+
args: ['trigger', { static: false }]
|
|
3597
|
+
}], dropdownRef: [{
|
|
3598
|
+
type: ViewChild,
|
|
3599
|
+
args: ['dropdown', { static: false }]
|
|
3600
|
+
}], shieldRef: [{
|
|
3601
|
+
type: ViewChild,
|
|
3602
|
+
args: ['shield', { static: false }]
|
|
3603
|
+
}], sheetRef: [{
|
|
3604
|
+
type: ViewChild,
|
|
3605
|
+
args: ['sheet', { static: false, read: ElementRef }]
|
|
3606
|
+
}], onDocumentClick: [{
|
|
3607
|
+
type: HostListener,
|
|
3608
|
+
args: ['document:click', ['$event']]
|
|
3609
|
+
}], onEscape: [{
|
|
3610
|
+
type: HostListener,
|
|
3611
|
+
args: ['document:keydown.escape']
|
|
3612
|
+
}], onWindowScrollOrResize: [{
|
|
3613
|
+
type: HostListener,
|
|
3614
|
+
args: ['window:scroll', []]
|
|
3615
|
+
}, {
|
|
3616
|
+
type: HostListener,
|
|
3617
|
+
args: ['window:resize', []]
|
|
3618
|
+
}] } });
|
|
3619
|
+
|
|
3620
|
+
/**
|
|
3621
|
+
* Layout variants for the trigger button. An icon-only trigger (the default ⋯) is a
|
|
3622
|
+
* square affordance; a trigger with a text label grows to fit its content with
|
|
3623
|
+
* horizontal padding instead. The `labeled` axis switches between the two.
|
|
3624
|
+
*/
|
|
3625
|
+
const mnDropdownTriggerVariants = tv({
|
|
3626
|
+
base: 'inline-flex items-center justify-center gap-x-1.5 text-base-content/80 cursor-pointer',
|
|
3627
|
+
variants: {
|
|
3628
|
+
size: {
|
|
3629
|
+
sm: '',
|
|
3630
|
+
md: '',
|
|
3631
|
+
lg: '',
|
|
3632
|
+
},
|
|
3633
|
+
labeled: {
|
|
3634
|
+
true: '',
|
|
3635
|
+
false: '',
|
|
3636
|
+
},
|
|
3637
|
+
borderRadius: {
|
|
3638
|
+
none: 'rounded-none',
|
|
3639
|
+
xs: 'rounded-xs',
|
|
3640
|
+
sm: 'rounded-sm',
|
|
3641
|
+
md: 'rounded-md',
|
|
3642
|
+
lg: 'rounded-lg',
|
|
3643
|
+
xl: 'rounded-xl',
|
|
3644
|
+
full: 'rounded-full',
|
|
3645
|
+
},
|
|
3646
|
+
},
|
|
3647
|
+
compoundVariants: [
|
|
3648
|
+
// Icon-only: a fixed square box.
|
|
3649
|
+
{ labeled: false, size: 'sm', class: 'h-7 w-7' },
|
|
3650
|
+
{ labeled: false, size: 'md', class: 'h-9 w-9' },
|
|
3651
|
+
{ labeled: false, size: 'lg', class: 'h-11 w-11' },
|
|
3652
|
+
// Labeled: content width with padding.
|
|
3653
|
+
{ labeled: true, size: 'sm', class: 'px-2.5 py-1 text-sm' },
|
|
3654
|
+
{ labeled: true, size: 'md', class: 'px-3 py-1.5 text-sm' },
|
|
3655
|
+
{ labeled: true, size: 'lg', class: 'px-4 py-2 text-base' },
|
|
3656
|
+
],
|
|
3657
|
+
defaultVariants: {
|
|
3658
|
+
size: 'md',
|
|
3659
|
+
labeled: false,
|
|
3660
|
+
borderRadius: 'md',
|
|
3661
|
+
},
|
|
3662
|
+
});
|
|
3663
|
+
|
|
3664
|
+
/** Lucide icons this file renders. */
|
|
3665
|
+
const ICONS = lucideIcons({
|
|
3666
|
+
Check: lucide.Check,
|
|
3667
|
+
ChevronDown: lucide.ChevronDown,
|
|
3668
|
+
EllipsisVertical: lucide.EllipsisVertical,
|
|
3669
|
+
SearchX: lucide.SearchX,
|
|
3670
|
+
});
|
|
3671
|
+
const MN_DROPDOWN_CONFIG = new InjectionToken('MN_DROPDOWN_CONFIG');
|
|
3672
|
+
/** Counter backing the auto-generated {@link MnDropdownProps.id} when a caller omits one. */
|
|
3673
|
+
let nextDropdownId = 0;
|
|
3674
|
+
/** Foreground class per action colour token, matching mn-button's text variants. */
|
|
3675
|
+
const ACTION_COLOR_CLASS = {
|
|
3676
|
+
primary: 'text-primary',
|
|
3677
|
+
secondary: 'text-secondary',
|
|
3678
|
+
danger: 'text-error',
|
|
3679
|
+
warning: 'text-warning',
|
|
3680
|
+
success: 'text-success',
|
|
3681
|
+
accent: 'text-accent',
|
|
3682
|
+
gray: 'text-base-content/70',
|
|
3683
|
+
};
|
|
3684
|
+
/**
|
|
3685
|
+
* A ⋯ command menu. The trigger opens a `role="menu"` list of {@link MnDropdownAction}s
|
|
3686
|
+
* that each fire and dismiss on choice — a *command* menu, not a value picker, so it is
|
|
3687
|
+
* intentionally not a ControlValueAccessor.
|
|
3688
|
+
*
|
|
3689
|
+
* Presentation mirrors mn-multi-select: an anchored popover on desktop and the shared
|
|
3690
|
+
* {@link MnBottomSheet} on mobile (< 640px). Both the popover and the sheet host are
|
|
3691
|
+
* portalled to `document.body` so their `position: fixed` anchors to the viewport rather
|
|
3692
|
+
* than any transformed/filtered ancestor (a table cell, a card) — the same root-cause fix
|
|
3693
|
+
* the multi-select applies.
|
|
3694
|
+
*/
|
|
3695
|
+
class MnDropdown {
|
|
3696
|
+
/** Lucide icons the template renders. */
|
|
3697
|
+
icons = ICONS;
|
|
3698
|
+
datasource;
|
|
3699
|
+
uiConfig = {};
|
|
3700
|
+
/** Lucide data for the trailing check shown on the {@link MnDropdownAction.active} row. */
|
|
3701
|
+
checkIcon = ICONS.Check;
|
|
3702
|
+
configService = inject(MnConfigService);
|
|
3703
|
+
sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
|
|
3704
|
+
explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
|
|
3705
|
+
elRef = inject(ElementRef);
|
|
3706
|
+
lang = inject(MnLanguageService);
|
|
3707
|
+
destroyRef = inject(DestroyRef);
|
|
3708
|
+
renderer = inject(Renderer2);
|
|
3709
|
+
cdr = inject(ChangeDetectorRef);
|
|
3710
|
+
/** Reference to the trigger element for positioning the popover. Read as an
|
|
3711
|
+
* `ElementRef` because `button[mnButton]` is a component — the default query would
|
|
3712
|
+
* otherwise return the MnButton instance, which has no `nativeElement`. */
|
|
3713
|
+
triggerRef;
|
|
3714
|
+
/**
|
|
3715
|
+
* Layout classes for the anchored popover panel. Searchable menus become a flex column
|
|
3716
|
+
* so the search box can be pinned (`shrink-0`) above a single scrolling list region —
|
|
3717
|
+
* paired with {@link panelFloorPx}, that keeps the popover a fixed height while the
|
|
3718
|
+
* filter runs, instead of the panel resizing on every keystroke. The mobile sheet is
|
|
3719
|
+
* rendered by mn-bottom-sheet instead, so it needs no branch here.
|
|
3720
|
+
*/
|
|
3721
|
+
get panelClasses() {
|
|
3722
|
+
const base = 'fixed z-9999 min-w-48 max-w-[min(20rem,90vw)] bg-base-100 border border-base-300 rounded-md shadow-lg py-1 max-h-[60vh] -translate-x-full';
|
|
3723
|
+
return this.isSearchable ? `${base} flex flex-col overflow-hidden` : `${base} overflow-auto`;
|
|
3724
|
+
}
|
|
3725
|
+
/** Tailwind's `sm` breakpoint — below this the menu renders as a bottom sheet.
|
|
3726
|
+
* Kept in step with the same constant in mn-bottom-sheet / mn-multi-select. */
|
|
3727
|
+
static SHEET_MAX_WIDTH = 639.98;
|
|
3728
|
+
/** The anchored popover panel currently moved into `document.body`, if any. */
|
|
3729
|
+
movedPanel = null;
|
|
3730
|
+
/** The bottom-sheet host, for outside-click tests. The sheet owns its own placement. */
|
|
3731
|
+
sheetHost = null;
|
|
3732
|
+
/** Whether the viewport is currently narrow enough for the sheet layout. */
|
|
3733
|
+
isNarrowViewport = false;
|
|
3734
|
+
/** Live breakpoint match, so rotating the device re-evaluates the layout. */
|
|
3735
|
+
sheetMedia = null;
|
|
3736
|
+
/** The listener registered on `sheetMedia`, retained for teardown. */
|
|
3737
|
+
sheetMediaListener = null;
|
|
3738
|
+
/** `document.body`'s inline `overflow` before the sheet locked it, restored on close. */
|
|
3739
|
+
previousBodyOverflow = null;
|
|
3740
|
+
/**
|
|
3741
|
+
* The anchored popover's opened height, locked so a shorter filtered list cannot resize
|
|
3742
|
+
* it mid-type. Captured on the frame after the panel appears (with the full, unfiltered
|
|
3743
|
+
* list), so applying it is jump-free — it only stops a later shrink. Null while closed
|
|
3744
|
+
* or when the menu is not searchable, leaving the plain content-height popover untouched.
|
|
3745
|
+
*/
|
|
3746
|
+
panelFloorPx = null;
|
|
3747
|
+
/**
|
|
3748
|
+
* The anchored popover's opened width, locked for the same reason as {@link panelFloorPx}:
|
|
3749
|
+
* the panel is content-sized between its `min-w`/`max-w` bounds, so a filtered list that
|
|
3750
|
+
* drops the widest item would otherwise shrink the popover mid-type. Captured on the same
|
|
3751
|
+
* next-frame pass as the height, so applying it is jump-free. Null while closed or when the
|
|
3752
|
+
* menu is not searchable, leaving the plain content-width popover untouched.
|
|
3753
|
+
*/
|
|
3754
|
+
panelWidthPx = null;
|
|
3755
|
+
/**
|
|
3756
|
+
* The mobile sheet's opened height, applied as a `min-height` floor for the same reason
|
|
3757
|
+
* as {@link panelFloorPx} — mirroring mn-multi-select's sheet floor. Null while anchored,
|
|
3758
|
+
* closed, or non-searchable.
|
|
3759
|
+
*/
|
|
3760
|
+
sheetFloorPx = null;
|
|
3761
|
+
/** Watches the trigger while open, so the panel closes if the trigger is hidden. */
|
|
3762
|
+
visibilityObserver = null;
|
|
3763
|
+
/** Capture-phase scroll listener installed while open, closing on any ancestor scroll. */
|
|
3764
|
+
scrollCapture = null;
|
|
3765
|
+
isOpen = false;
|
|
3766
|
+
/** Stable fallback id, used when {@link MnDropdownProps.id} is omitted. Generated once per
|
|
3767
|
+
* instance so the a11y wiring (menu id, `aria-controls`, the search input) stays valid. */
|
|
3768
|
+
autoId = `mn-dropdown-${++nextDropdownId}`;
|
|
3769
|
+
/** Current text in the search input, cleared on close. Only meaningful when the menu
|
|
3770
|
+
* is {@link MnDropdownProps.searchable}. */
|
|
3771
|
+
searchTerm = '';
|
|
3772
|
+
/** Popover position computed from the trigger's bounding rect. */
|
|
3773
|
+
/** Inline placement of the anchored panel; `maxHeight` only binds when the viewport is the tighter cap. */
|
|
3774
|
+
dropdownStyle = {
|
|
3775
|
+
top: '0px',
|
|
3776
|
+
bottom: 'auto',
|
|
3777
|
+
left: '0px',
|
|
3778
|
+
maxHeight: null,
|
|
3779
|
+
};
|
|
3780
|
+
/**
|
|
3781
|
+
* The popover panel, relocated to `document.body` on appearance (see mn-multi-select's
|
|
3782
|
+
* portal rationale) and detached when the query clears on close/destroy.
|
|
3783
|
+
*/
|
|
3784
|
+
set dropdownRef(ref) {
|
|
3785
|
+
const el = ref?.nativeElement ?? null;
|
|
3786
|
+
this.movedPanel = this.portal(el, this.movedPanel);
|
|
3787
|
+
if (el && this.isSearchable) {
|
|
3788
|
+
this.capturePanelFloor(el);
|
|
3789
|
+
}
|
|
3790
|
+
else if (!el) {
|
|
3791
|
+
this.panelFloorPx = null;
|
|
3792
|
+
this.panelWidthPx = null;
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
/**
|
|
3796
|
+
* The bottom-sheet host, relocated to `document.body` so its `position: fixed`
|
|
3797
|
+
* children anchor to the viewport rather than a transformed ancestor.
|
|
3798
|
+
*/
|
|
3799
|
+
set sheetRef(ref) {
|
|
3800
|
+
const el = ref?.nativeElement ?? null;
|
|
3801
|
+
this.sheetHost = el;
|
|
3802
|
+
if (el && this.isSearchable) {
|
|
3803
|
+
this.captureSheetFloor(el);
|
|
3804
|
+
}
|
|
3805
|
+
else if (!el) {
|
|
3806
|
+
this.sheetFloorPx = null;
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
ngOnInit() {
|
|
3810
|
+
this.resolveConfig();
|
|
3811
|
+
this.startWatchingViewport();
|
|
3812
|
+
const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
|
|
3813
|
+
this.resolveConfig();
|
|
3814
|
+
this.cdr.markForCheck();
|
|
3815
|
+
});
|
|
3816
|
+
this.destroyRef.onDestroy(() => {
|
|
3817
|
+
sub.unsubscribe();
|
|
3818
|
+
this.stopWatchingTrigger();
|
|
3819
|
+
this.stopWatchingViewport();
|
|
3820
|
+
this.unlockBodyScroll();
|
|
3821
|
+
// Guarantee the portalled elements never outlive the component.
|
|
3822
|
+
this.movedPanel = this.portal(null, this.movedPanel);
|
|
3823
|
+
this.sheetHost = null;
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
resolveConfig() {
|
|
3827
|
+
const instanceId = this.explicitInstanceId || `mn-dropdown-${this.resolvedId}`;
|
|
3828
|
+
this.uiConfig = this.configService.resolve('mn-dropdown', this.sectionPath, instanceId);
|
|
3829
|
+
}
|
|
3830
|
+
// ── Breakpoint watching ──
|
|
3831
|
+
startWatchingViewport() {
|
|
3832
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
3833
|
+
return;
|
|
3834
|
+
this.sheetMedia = window.matchMedia(`(max-width: ${MnDropdown.SHEET_MAX_WIDTH}px)`);
|
|
3835
|
+
this.isNarrowViewport = this.sheetMedia.matches;
|
|
3836
|
+
this.sheetMediaListener = (event) => {
|
|
3837
|
+
this.isNarrowViewport = event.matches;
|
|
3838
|
+
this.close();
|
|
3839
|
+
// The listener fires outside Angular, so a zoneless app needs an explicit nudge.
|
|
3840
|
+
this.cdr.markForCheck();
|
|
3841
|
+
};
|
|
3842
|
+
this.sheetMedia.addEventListener('change', this.sheetMediaListener);
|
|
3843
|
+
}
|
|
3844
|
+
stopWatchingViewport() {
|
|
3845
|
+
if (this.sheetMedia && this.sheetMediaListener) {
|
|
3846
|
+
this.sheetMedia.removeEventListener('change', this.sheetMediaListener);
|
|
3847
|
+
}
|
|
3848
|
+
this.sheetMedia = null;
|
|
3849
|
+
this.sheetMediaListener = null;
|
|
3850
|
+
}
|
|
3851
|
+
// ── Open / close ──
|
|
3852
|
+
toggle() {
|
|
3853
|
+
if (this.isOpen) {
|
|
3854
|
+
this.close();
|
|
3855
|
+
return;
|
|
3856
|
+
}
|
|
3857
|
+
if (this.datasource.actions.length === 0)
|
|
3858
|
+
return;
|
|
3859
|
+
this.isOpen = true;
|
|
3860
|
+
if (this.isSheet) {
|
|
3861
|
+
// A sheet is anchored to the viewport, so it needs no trigger tracking — only a
|
|
3862
|
+
// scroll lock so the page behind it stays put.
|
|
3863
|
+
this.lockBodyScroll();
|
|
3864
|
+
return;
|
|
3865
|
+
}
|
|
3866
|
+
this.updateDropdownPosition();
|
|
3867
|
+
this.startWatchingTrigger();
|
|
3868
|
+
}
|
|
3869
|
+
/** The single close path, so every open-only listener is torn down with the panel. */
|
|
3870
|
+
close() {
|
|
3871
|
+
if (!this.isOpen)
|
|
3872
|
+
return;
|
|
3873
|
+
this.isOpen = false;
|
|
3874
|
+
this.searchTerm = '';
|
|
3875
|
+
this.panelFloorPx = null;
|
|
3876
|
+
this.panelWidthPx = null;
|
|
3877
|
+
this.sheetFloorPx = null;
|
|
3878
|
+
this.stopWatchingTrigger();
|
|
3879
|
+
this.unlockBodyScroll();
|
|
3880
|
+
}
|
|
3881
|
+
/** Whether the menu should currently render as a bottom sheet. */
|
|
3882
|
+
get isSheet() {
|
|
3883
|
+
return this.datasource.mobileSheet !== false && this.isNarrowViewport;
|
|
3884
|
+
}
|
|
3885
|
+
/** Fires an action and closes. Ignores disabled items defensively. */
|
|
3886
|
+
select(action) {
|
|
3887
|
+
if (action.disabled)
|
|
3888
|
+
return;
|
|
3889
|
+
this.close();
|
|
3890
|
+
action.run();
|
|
3891
|
+
}
|
|
3892
|
+
// ── Search ──
|
|
3893
|
+
/** Whether the filter input is shown — the explicit `searchable` prop, off by default. */
|
|
3894
|
+
get isSearchable() {
|
|
3895
|
+
return this.datasource.searchable === true;
|
|
3896
|
+
}
|
|
3897
|
+
/**
|
|
3898
|
+
* Records the current filter text as the search input changes. The input's
|
|
3899
|
+
* ControlValueAccessor emits `null` for an empty field (its text adapter maps `''` to
|
|
3900
|
+
* `null`), so coerce to `''` — otherwise clearing or backspacing the box would leave
|
|
3901
|
+
* `searchTerm` null and {@link filteredActions}'s `.trim()` would throw, freezing the menu.
|
|
3902
|
+
*/
|
|
3903
|
+
onSearch(term) {
|
|
3904
|
+
this.searchTerm = term ?? '';
|
|
3905
|
+
}
|
|
3906
|
+
/**
|
|
3907
|
+
* The actions currently passing the filter, in their declared order. Every action when
|
|
3908
|
+
* the menu is not searchable or the box is empty; otherwise those whose resolved label
|
|
3909
|
+
* or {@link MnDropdownAction.keywords} contain the (case-insensitive) query.
|
|
3910
|
+
*/
|
|
3911
|
+
get filteredActions() {
|
|
3912
|
+
const term = (this.searchTerm ?? '').trim().toLowerCase();
|
|
3913
|
+
if (!this.isSearchable || !term)
|
|
3914
|
+
return this.datasource.actions;
|
|
3915
|
+
// While filtering, separators are dropped — a divider stranded between or after hidden
|
|
3916
|
+
// results is meaningless — so match only real actions.
|
|
3917
|
+
return this.datasource.actions.filter(item => {
|
|
3918
|
+
if (this.isSeparator(item))
|
|
3919
|
+
return false;
|
|
3920
|
+
const haystack = `${this.actionLabel(item)} ${item.keywords ?? ''}`.toLowerCase();
|
|
3921
|
+
return haystack.includes(term);
|
|
3922
|
+
});
|
|
3923
|
+
}
|
|
3924
|
+
/**
|
|
3925
|
+
* Runs the first still-visible, enabled action — the Enter key's target, matching a
|
|
3926
|
+
* help search where Enter opens the top hit. Skips separators. No-op when nothing matches.
|
|
3927
|
+
*/
|
|
3928
|
+
selectFirstVisible() {
|
|
3929
|
+
const first = this.filteredActions.find((item) => !this.isSeparator(item) && !item.disabled);
|
|
3930
|
+
if (first)
|
|
3931
|
+
this.select(first);
|
|
3932
|
+
}
|
|
3933
|
+
// ── Positioning ──
|
|
3934
|
+
updateDropdownPosition() {
|
|
3935
|
+
if (!this.triggerRef)
|
|
3936
|
+
return;
|
|
3937
|
+
const rect = this.triggerRef.nativeElement.getBoundingClientRect();
|
|
3938
|
+
// The panel is right-aligned to the trigger via a `-translate-x-full` class, so
|
|
3939
|
+
// `left` is anchored to the trigger's right edge.
|
|
3940
|
+
// Below the trigger while the viewport has room, above it otherwise, never past the edge;
|
|
3941
|
+
// the cap it competes with is the panel's own 60vh.
|
|
3942
|
+
this.dropdownStyle = {
|
|
3943
|
+
...anchoredPanelPlacement(rect, window.innerHeight, 4, window.innerHeight * 0.6),
|
|
3944
|
+
left: `${rect.right}px`,
|
|
3945
|
+
};
|
|
3946
|
+
}
|
|
3947
|
+
startWatchingTrigger() {
|
|
3948
|
+
this.stopWatchingTrigger();
|
|
3949
|
+
const trigger = this.triggerRef?.nativeElement;
|
|
3950
|
+
if (trigger && typeof IntersectionObserver !== 'undefined') {
|
|
3951
|
+
this.visibilityObserver = new IntersectionObserver(entries => {
|
|
3952
|
+
if (!entries.some(entry => !entry.isIntersecting))
|
|
3953
|
+
return;
|
|
3954
|
+
this.close();
|
|
3955
|
+
this.cdr.markForCheck();
|
|
3956
|
+
});
|
|
3957
|
+
this.visibilityObserver.observe(trigger);
|
|
3958
|
+
}
|
|
3959
|
+
this.scrollCapture = (event) => {
|
|
3960
|
+
const target = event.target;
|
|
3961
|
+
if (target && this.movedPanel && (this.movedPanel === target || this.movedPanel.contains(target))) {
|
|
3962
|
+
return;
|
|
3963
|
+
}
|
|
3964
|
+
this.close();
|
|
3965
|
+
this.cdr.markForCheck();
|
|
3966
|
+
};
|
|
3967
|
+
document.addEventListener('scroll', this.scrollCapture, true);
|
|
3968
|
+
}
|
|
3969
|
+
stopWatchingTrigger() {
|
|
3970
|
+
this.visibilityObserver?.disconnect();
|
|
3971
|
+
this.visibilityObserver = null;
|
|
3972
|
+
if (this.scrollCapture) {
|
|
3973
|
+
document.removeEventListener('scroll', this.scrollCapture, true);
|
|
3974
|
+
this.scrollCapture = null;
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
// ── Global dismissal ──
|
|
3978
|
+
onDocumentClick(event) {
|
|
3979
|
+
const target = event.target;
|
|
3980
|
+
const insideHost = !!target && this.elRef.nativeElement.contains(target);
|
|
3981
|
+
const insidePanel = !!target && !!this.movedPanel && this.movedPanel.contains(target);
|
|
3982
|
+
const insideSheet = !!target && !!this.sheetHost && this.sheetHost.contains(target);
|
|
3983
|
+
if (!insideHost && !insidePanel && !insideSheet) {
|
|
3984
|
+
this.close();
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
onEscape() {
|
|
3988
|
+
if (!this.isOpen)
|
|
3989
|
+
return;
|
|
3990
|
+
this.close();
|
|
3991
|
+
// Return focus to the trigger so keyboard users are not stranded.
|
|
3992
|
+
this.triggerRef?.nativeElement.focus();
|
|
3993
|
+
}
|
|
3994
|
+
onWindowScrollOrResize() {
|
|
3995
|
+
// A sheet is viewport-anchored, so it has no stale position to escape; closing it on
|
|
3996
|
+
// the `resize` a soft keyboard fires would also be wrong. The matchMedia listener
|
|
3997
|
+
// handles a genuine layout switch instead.
|
|
3998
|
+
if (this.isSheet)
|
|
3999
|
+
return;
|
|
4000
|
+
this.close();
|
|
4001
|
+
}
|
|
4002
|
+
// ── Body scroll lock (sheet only) ──
|
|
4003
|
+
lockBodyScroll() {
|
|
4004
|
+
if (this.previousBodyOverflow !== null)
|
|
4005
|
+
return;
|
|
4006
|
+
this.previousBodyOverflow = document.body.style.overflow;
|
|
4007
|
+
this.renderer.setStyle(document.body, 'overflow', 'hidden');
|
|
4008
|
+
}
|
|
4009
|
+
unlockBodyScroll() {
|
|
4010
|
+
if (this.previousBodyOverflow === null)
|
|
4011
|
+
return;
|
|
4012
|
+
if (this.previousBodyOverflow) {
|
|
4013
|
+
this.renderer.setStyle(document.body, 'overflow', this.previousBodyOverflow);
|
|
4014
|
+
}
|
|
4015
|
+
else {
|
|
4016
|
+
this.renderer.removeStyle(document.body, 'overflow');
|
|
4017
|
+
}
|
|
4018
|
+
this.previousBodyOverflow = null;
|
|
4019
|
+
}
|
|
4020
|
+
// ── Height floors (searchable only) ──
|
|
4021
|
+
/**
|
|
4022
|
+
* Records the anchored popover's opened height and width, locking them via
|
|
4023
|
+
* {@link panelFloorPx} / {@link panelWidthPx}. Measured on the next frame so the read
|
|
4024
|
+
* reflects the fully-rendered, unfiltered list (the search box is empty on open) and never
|
|
4025
|
+
* forces a reflow mid change-detection. Both values equal the current dimensions, so
|
|
4026
|
+
* applying them is jump-free — they only stop a later, shorter/narrower filtered list from
|
|
4027
|
+
* shrinking the panel.
|
|
4028
|
+
*/
|
|
4029
|
+
capturePanelFloor(panelEl) {
|
|
4030
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
4031
|
+
this.panelFloorPx = panelEl.offsetHeight;
|
|
4032
|
+
this.panelWidthPx = panelEl.offsetWidth;
|
|
4033
|
+
return;
|
|
4034
|
+
}
|
|
4035
|
+
requestAnimationFrame(() => {
|
|
4036
|
+
// The panel may have closed (or the query cleared) before the frame ran.
|
|
4037
|
+
if (!this.isOpen || this.movedPanel !== panelEl)
|
|
4038
|
+
return;
|
|
4039
|
+
this.panelFloorPx = panelEl.offsetHeight;
|
|
4040
|
+
this.panelWidthPx = panelEl.offsetWidth;
|
|
4041
|
+
this.cdr.markForCheck();
|
|
4042
|
+
});
|
|
4043
|
+
}
|
|
4044
|
+
/**
|
|
4045
|
+
* Records the sheet's opened height as its `min-height` floor, on the same next-frame
|
|
4046
|
+
* basis as {@link capturePanelFloor}. `hostEl` is the portalled mn-bottom-sheet host
|
|
4047
|
+
* (`display: contents`), so the height is read from its `.mn-sheet-container` child.
|
|
4048
|
+
*/
|
|
4049
|
+
captureSheetFloor(hostEl) {
|
|
4050
|
+
const measure = () => {
|
|
4051
|
+
const container = hostEl.querySelector('.mn-sheet-container');
|
|
4052
|
+
return container?.offsetHeight ?? hostEl.offsetHeight;
|
|
4053
|
+
};
|
|
4054
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
4055
|
+
this.sheetFloorPx = measure();
|
|
4056
|
+
return;
|
|
4057
|
+
}
|
|
4058
|
+
requestAnimationFrame(() => {
|
|
4059
|
+
if (!this.isOpen || this.sheetHost !== hostEl)
|
|
4060
|
+
return;
|
|
4061
|
+
this.sheetFloorPx = measure();
|
|
4062
|
+
this.cdr.markForCheck();
|
|
4063
|
+
});
|
|
4064
|
+
}
|
|
4065
|
+
// ── Portal helper (see mn-multi-select for the full rationale) ──
|
|
4066
|
+
portal(el, current) {
|
|
4067
|
+
if (el) {
|
|
4068
|
+
if (current === el)
|
|
4069
|
+
return current;
|
|
4070
|
+
this.renderer.appendChild(document.body, el);
|
|
4071
|
+
return el;
|
|
4072
|
+
}
|
|
4073
|
+
if (current) {
|
|
4074
|
+
const parent = current.parentNode;
|
|
4075
|
+
if (parent) {
|
|
4076
|
+
this.renderer.removeChild(parent, current);
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
return null;
|
|
4080
|
+
}
|
|
4081
|
+
// ── Resolved presentation ──
|
|
4082
|
+
/** The label shown for an action, preferring a resolved translation key. */
|
|
4083
|
+
actionLabel(action) {
|
|
4084
|
+
const translated = action.labelKey ? this.lang.translateIfPresent(action.labelKey) : undefined;
|
|
4085
|
+
return translated ?? action.label ?? '';
|
|
4086
|
+
}
|
|
4087
|
+
/**
|
|
4088
|
+
* Whether an icon was supplied as a `TemplateRef` rather than lucide icon data, which
|
|
4089
|
+
* decides how the template renders it. Kept as a method (not a pipe) so the narrowing
|
|
4090
|
+
* is available inline in the item loop.
|
|
4091
|
+
* @param value The icon to test.
|
|
4092
|
+
* @returns True when the icon is a template the caller owns.
|
|
4093
|
+
*/
|
|
4094
|
+
isTemplateRef(value) {
|
|
4095
|
+
return value instanceof TemplateRef;
|
|
4096
|
+
}
|
|
4097
|
+
/** Whether a list entry is a {@link MnDropdownSeparator} rather than a command. */
|
|
4098
|
+
isSeparator(item) {
|
|
4099
|
+
return item.separator;
|
|
4100
|
+
}
|
|
4101
|
+
/**
|
|
4102
|
+
* Narrows a list entry to a command, or null for a separator. Used as `@if (asAction(item);
|
|
4103
|
+
* as action)` in the template so the item loop gets a reliably-typed {@link MnDropdownAction}
|
|
4104
|
+
* without depending on template narrowing of the {@link isSeparator} guard.
|
|
4105
|
+
* @param item The list entry to narrow.
|
|
4106
|
+
* @returns The command, or null when the entry is a separator.
|
|
4107
|
+
*/
|
|
4108
|
+
asAction(item) {
|
|
4109
|
+
return this.isSeparator(item) ? null : item;
|
|
4110
|
+
}
|
|
4111
|
+
/**
|
|
4112
|
+
* Foreground class for an item: an explicit {@link MnDropdownAction.color}, else the
|
|
4113
|
+
* destructive red for a {@link MnDropdownAction.danger} item, else the default text.
|
|
4114
|
+
*/
|
|
4115
|
+
actionColorClass(action) {
|
|
4116
|
+
if (action.color)
|
|
4117
|
+
return ACTION_COLOR_CLASS[action.color];
|
|
4118
|
+
if (action.danger)
|
|
4119
|
+
return ACTION_COLOR_CLASS.danger;
|
|
4120
|
+
return 'text-base-content';
|
|
4121
|
+
}
|
|
4122
|
+
/** Accessible name for the ⋯ trigger button. */
|
|
4123
|
+
get triggerAriaLabel() {
|
|
4124
|
+
const translated = this.datasource.ariaLabelKey ? this.lang.translateIfPresent(this.datasource.ariaLabelKey) : undefined;
|
|
4125
|
+
return translated ?? this.datasource.ariaLabel ?? this.uiConfig.ariaLabel ?? 'Actions';
|
|
4126
|
+
}
|
|
4127
|
+
/** The visible text on the trigger, or null for an icon-only ⋯ trigger. */
|
|
4128
|
+
get triggerLabelText() {
|
|
4129
|
+
const translated = this.datasource.triggerLabelKey ? this.lang.translateIfPresent(this.datasource.triggerLabelKey) : undefined;
|
|
4130
|
+
return translated ?? this.datasource.triggerLabel ?? null;
|
|
4131
|
+
}
|
|
4132
|
+
/**
|
|
4133
|
+
* The trigger's glyph, normalised to a single representation so the template renders it
|
|
4134
|
+
* one way — the same template-or-lucide-data path the menu items use — with no per-preset
|
|
4135
|
+
* switch. Resolves, in order: an explicit `'none'` (no glyph); a caller's custom template
|
|
4136
|
+
* or lucide data ({@link MnActionIcon}); otherwise a built-in preset mapped to its own
|
|
4137
|
+
* lucide data (a labelled trigger defaults to the chevron, an icon-only one to the dots).
|
|
4138
|
+
* @returns A template glyph, an icon-data glyph with its render size, or null for none.
|
|
4139
|
+
*/
|
|
4140
|
+
resolveTriggerGlyph() {
|
|
4141
|
+
const icon = this.datasource.triggerIcon;
|
|
4142
|
+
if (icon === 'none')
|
|
4143
|
+
return null;
|
|
4144
|
+
if (icon instanceof TemplateRef)
|
|
4145
|
+
return { template: icon };
|
|
4146
|
+
if (icon != null && typeof icon !== 'string')
|
|
4147
|
+
return { data: icon, size: 18, dim: false };
|
|
4148
|
+
const preset = typeof icon === 'string' ? icon : this.triggerLabelText ? 'chevron' : 'dots-vertical';
|
|
4149
|
+
// The chevron is a touch smaller and dimmed, matching a select's trailing affordance.
|
|
4150
|
+
return preset === 'chevron'
|
|
4151
|
+
? { data: ICONS.ChevronDown, size: 16, dim: true }
|
|
4152
|
+
: { data: ICONS.EllipsisVertical, size: 18, dim: false };
|
|
4153
|
+
}
|
|
4154
|
+
/** The trigger glyph when it is a caller's template, else null. Split from
|
|
4155
|
+
* {@link triggerIconData} so the template narrows without a discriminated union. */
|
|
4156
|
+
get triggerIconTemplate() {
|
|
4157
|
+
const glyph = this.resolveTriggerGlyph();
|
|
4158
|
+
return glyph && 'template' in glyph ? glyph.template : null;
|
|
4159
|
+
}
|
|
4160
|
+
/** The trigger glyph when it is lucide data (a preset or caller data), with its render
|
|
4161
|
+
* size and dim flag, else null. */
|
|
4162
|
+
get triggerIconData() {
|
|
4163
|
+
const glyph = this.resolveTriggerGlyph();
|
|
4164
|
+
return glyph && 'data' in glyph ? glyph : null;
|
|
4165
|
+
}
|
|
4166
|
+
/** Heading shown above the menu/sheet, or null when none is configured. */
|
|
4167
|
+
get menuLabel() {
|
|
4168
|
+
const translated = this.datasource.menuLabelKey ? this.lang.translateIfPresent(this.datasource.menuLabelKey) : undefined;
|
|
4169
|
+
return translated ?? this.datasource.menuLabel ?? this.uiConfig.menuLabel ?? null;
|
|
4170
|
+
}
|
|
4171
|
+
/** Placeholder shown in the search input, preferring a resolved translation key. */
|
|
4172
|
+
get searchPlaceholder() {
|
|
4173
|
+
const translated = this.datasource.searchPlaceholderKey ? this.lang.translateIfPresent(this.datasource.searchPlaceholderKey) : undefined;
|
|
4174
|
+
return translated ?? this.datasource.searchPlaceholder ?? this.uiConfig.searchPlaceholder ?? 'Search...';
|
|
4175
|
+
}
|
|
4176
|
+
/** Text shown in place of the list when the filter matches no actions. */
|
|
4177
|
+
get searchEmptyLabel() {
|
|
4178
|
+
const translated = this.datasource.searchEmptyLabelKey ? this.lang.translateIfPresent(this.datasource.searchEmptyLabelKey) : undefined;
|
|
4179
|
+
return translated ?? this.datasource.searchEmptyLabel ?? this.uiConfig.searchEmptyLabel ?? 'No results';
|
|
4180
|
+
}
|
|
4181
|
+
/** The ghost look the trigger has always used; a bare or partial `triggerButton` merges
|
|
4182
|
+
* over this, so opting in without overriding anything keeps the current appearance. */
|
|
4183
|
+
static DEFAULT_TRIGGER_BUTTON = {
|
|
4184
|
+
size: 'sm',
|
|
4185
|
+
variant: 'text',
|
|
4186
|
+
color: 'gray',
|
|
4187
|
+
};
|
|
4188
|
+
/** mn-button config for the trigger: the ghost default, overlaid with any
|
|
4189
|
+
* {@link MnDropdownProps.triggerButton} the caller supplied. */
|
|
4190
|
+
get triggerData() {
|
|
4191
|
+
return { ...MnDropdown.DEFAULT_TRIGGER_BUTTON, ...this.datasource.triggerButton };
|
|
4192
|
+
}
|
|
4193
|
+
get triggerClasses() {
|
|
4194
|
+
// Button mode: mn-button owns the entire look (fill/outline/size/radius/shape). The
|
|
4195
|
+
// trigger's square-box variants would fight that — `h-7 w-7` overrides its padding,
|
|
4196
|
+
// `text-base-content/80` its text colour — so keep only the label↔icon gap, which
|
|
4197
|
+
// mn-button's base does not provide.
|
|
4198
|
+
if (this.datasource.triggerButton)
|
|
4199
|
+
return 'gap-x-1.5';
|
|
4200
|
+
// A caller's template can be any size (an avatar, a badge) and sizes the trigger itself,
|
|
4201
|
+
// so skip the preset square-box — otherwise its `h-7 w-7` would clip the content, which
|
|
4202
|
+
// is why custom triggers used to need a `triggerButton` just to undo it. (A lucide-data
|
|
4203
|
+
// glyph is preset-sized, so it keeps the box for a consistent tap target.)
|
|
4204
|
+
if (this.datasource.triggerIcon instanceof TemplateRef)
|
|
4205
|
+
return 'gap-x-1.5';
|
|
4206
|
+
return mnDropdownTriggerVariants({
|
|
4207
|
+
size: this.datasource.size,
|
|
4208
|
+
borderRadius: this.datasource.borderRadius,
|
|
4209
|
+
labeled: !!this.triggerLabelText,
|
|
4210
|
+
});
|
|
4211
|
+
}
|
|
4212
|
+
get resolvedId() {
|
|
4213
|
+
return this.datasource.id ?? this.autoId;
|
|
4214
|
+
}
|
|
4215
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnDropdown, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
4216
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnDropdown, isStandalone: true, selector: "mn-lib-dropdown", inputs: { datasource: "datasource" }, host: { listeners: { "document:click": "onDocumentClick($event)", "document:keydown.escape": "onEscape()", "window:scroll": "onWindowScrollOrResize()", "window:resize": "onWindowScrollOrResize()" } }, viewQueries: [{ propertyName: "triggerRef", first: true, predicate: ["trigger"], descendants: true, read: ElementRef }, { propertyName: "dropdownRef", first: true, predicate: ["dropdown"], descendants: true }, { propertyName: "sheetRef", first: true, predicate: ["sheet"], descendants: true, read: ElementRef }], ngImport: i0, template: "<div class=\"relative inline-flex\">\n <!-- Trigger -->\n <button\n #trigger\n mnButton\n type=\"button\"\n [id]=\"resolvedId\"\n [data]=\"triggerData\"\n [ngClass]=\"triggerClasses\"\n [attr.aria-label]=\"triggerLabelText ? null : triggerAriaLabel\"\n [attr.aria-haspopup]=\"'menu'\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-controls]=\"isOpen ? resolvedId + '-menu' : null\"\n (click)=\"toggle()\"\n >\n @if (triggerLabelText) {\n <span class=\"truncate\">{{ triggerLabelText }}</span>\n }\n <!-- One glyph, rendered like a menu item's icon: a caller's template, else lucide data\n (a preset resolves to its own data). No per-preset switch. -->\n @if (triggerIconTemplate; as tpl) {\n <span class=\"shrink-0 inline-flex items-center\">\n <ng-container [ngTemplateOutlet]=\"tpl\"></ng-container>\n </span>\n } @else if (triggerIconData; as glyph) {\n <span class=\"shrink-0 inline-flex items-center\">\n <svg [lucideIcon]=\"glyph.data\" [size]=\"glyph.size\" [class.opacity-70]=\"glyph.dim\"></svg>\n </span>\n }\n </button>\n\n <!-- Menu -->\n @if (isOpen) {\n @if (isSheet) {\n <!-- On mobile the menu is presented as the shared bottom sheet: chrome (backdrop,\n grabber, swipe-to-dismiss, slide animation) lives in mn-bottom-sheet; this\n component only projects the item list into it. The host is portalled to\n document.body (see the `sheet` ViewChild). -->\n <mn-bottom-sheet\n #sheet\n (dismiss)=\"close()\"\n [ariaLabel]=\"menuLabel || triggerAriaLabel\"\n [maxHeightVh]=\"80\"\n [minHeightPx]=\"sheetFloorPx\"\n >\n <div [id]=\"resolvedId + '-menu'\" role=\"menu\" class=\"flex flex-col flex-1 min-h-0 overflow-hidden\">\n <!-- The sheet covers its own trigger, so it carries a header to name itself; the\n way out is the grabber (swipe-to-dismiss) and a backdrop tap. -->\n <div class=\"px-4 pt-1 pb-2 shrink-0\">\n <p class=\"text-base font-bold text-base-content truncate\">{{ menuLabel || triggerAriaLabel }}</p>\n </div>\n <ng-container [ngTemplateOutlet]=\"searchBox\" [ngTemplateOutletContext]=\"{ sheet: true }\"></ng-container>\n <div class=\"flex-1 flex flex-col overflow-auto overscroll-contain\">\n <ng-container [ngTemplateOutlet]=\"items\" [ngTemplateOutletContext]=\"{ sheet: true }\"></ng-container>\n </div>\n </div>\n </mn-bottom-sheet>\n } @else {\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n #dropdown\n (click)=\"$event.stopPropagation()\"\n [id]=\"resolvedId + '-menu'\"\n [ngClass]=\"panelClasses\"\n [style.left]=\"dropdownStyle.left\"\n [style.top]=\"dropdownStyle.top\"\n [style.bottom]=\"dropdownStyle.bottom\"\n [style.max-height]=\"dropdownStyle.maxHeight\"\n [style.height.px]=\"panelFloorPx\"\n [style.width.px]=\"panelWidthPx\"\n role=\"menu\"\n >\n @if (menuLabel) {\n <p class=\"px-3 pt-1 pb-1.5 text-xs font-medium text-base-content/50 truncate shrink-0\">{{ menuLabel }}</p>\n }\n <ng-container [ngTemplateOutlet]=\"searchBox\" [ngTemplateOutletContext]=\"{ sheet: false }\"></ng-container>\n @if (isSearchable) {\n <!-- Its own scroll region so the pinned search box above stays fixed and the\n locked panel height (panelFloorPx) doesn't change as the list filters. The\n flex column lets the empty state fill and centre in the reserved space. -->\n <div class=\"flex-1 min-h-0 flex flex-col overflow-auto\">\n <ng-container [ngTemplateOutlet]=\"items\" [ngTemplateOutletContext]=\"{ sheet: false }\"></ng-container>\n </div>\n } @else {\n <ng-container [ngTemplateOutlet]=\"items\" [ngTemplateOutletContext]=\"{ sheet: false }\"></ng-container>\n }\n </div>\n }\n }\n\n <!-- The item list, shared verbatim by the sheet and the anchored popover. `sheet`\n only tunes the spacing so touch targets are roomier on mobile. -->\n <ng-template #items let-sheet=\"sheet\">\n @for (item of filteredActions; track $index) {\n @if (asAction(item); as action) {\n <button\n type=\"button\"\n role=\"menuitem\"\n [disabled]=\"action.disabled\"\n [attr.aria-current]=\"action.active ? 'true' : null\"\n [class.opacity-50]=\"action.disabled\"\n [class.pointer-events-none]=\"action.disabled\"\n [ngClass]=\"[actionColorClass(action), sheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm', action.active ? 'bg-primary/10 font-medium' : '']\"\n class=\"flex w-full shrink-0 items-center gap-x-2.5 text-left cursor-pointer hover:bg-base-200 focus-visible:bg-base-200 focus:outline-none transition-colors\"\n (click)=\"select(action)\"\n >\n @if (action.icon) {\n <span class=\"shrink-0 inline-flex items-center\">\n @if (isTemplateRef(action.icon)) {\n <ng-container [ngTemplateOutlet]=\"action.icon\"></ng-container>\n } @else {\n <!-- Data icon: rendered here so the item sizes it to match its own text\n (larger in the sheet, where the rows are touch-sized). -->\n <svg [lucideIcon]=\"$any(action.icon)\" [size]=\"sheet ? 18 : 16\"></svg>\n }\n </span>\n }\n <span class=\"truncate min-w-0\">{{ actionLabel(action) }}</span>\n <!-- The current choice's marker (e.g. the active language). Decorative: the\n state is conveyed to assistive tech by `aria-current` on the row. -->\n @if (action.active) {\n <svg\n [lucideIcon]=\"checkIcon\"\n [size]=\"sheet ? 18 : 16\"\n class=\"ml-auto shrink-0 text-primary\"\n aria-hidden=\"true\"\n ></svg>\n }\n </button>\n } @else {\n <hr role=\"separator\" [ngClass]=\"sheet ? 'mx-4 my-1.5' : 'mx-2 my-1'\" class=\"shrink-0 border-t border-base-300\" />\n }\n }\n @if (isSearchable && filteredActions.length === 0) {\n <div class=\"flex-1 flex flex-col items-center justify-center gap-2 px-4 py-6 text-center text-base-content/50\">\n <svg [lucideIcon]=\"icons.SearchX\" [size]=\"sheet ? 28 : 24\" class=\"opacity-60\"></svg>\n <span [ngClass]=\"sheet ? 'text-base' : 'text-sm'\">{{ searchEmptyLabel }}</span>\n </div>\n }\n </ng-template>\n\n <!-- The filter input, shared by the sheet and the anchored popover. Autofocused on\n desktop (`!sheet`) so typing starts immediately; deliberately not on mobile, where\n it would pop the soft keyboard and fight the viewport-anchored sheet. Enter runs\n the first visible action via the wrapper's bubbled keydown. -->\n <ng-template #searchBox let-sheet=\"sheet\">\n @if (isSearchable) {\n <!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"$event.stopPropagation()\"\n (keydown.enter)=\"selectFirstVisible()\"\n [ngClass]=\"sheet ? 'px-4 py-2' : 'p-2'\"\n class=\"border-b border-base-300 shrink-0\"\n >\n <mn-lib-input-field\n (ngModelChange)=\"onSearch($event)\"\n [ngModelOptions]=\"{ standalone: true }\"\n [ngModel]=\"searchTerm\"\n [props]=\"{\n id: resolvedId + '-search',\n type: 'search',\n placeholder: searchPlaceholder,\n ariaLabel: searchPlaceholder,\n fullWidth: true,\n size: 'sm',\n autoFocus: !sheet\n }\"\n ></mn-lib-input-field>\n </div>\n }\n </ng-template>\n</div>\n", styles: [""], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: MnButton, selector: "button[mnButton], a[mnButton]", inputs: ["data"] }, { kind: "component", type: MnBottomSheet, selector: "mn-bottom-sheet", inputs: ["showBackdrop", "showGrabber", "dismissible", "minHeightPx", "maxHeightVh", "containerClass", "ariaLabel", "ariaLabelledby", "growWithKeyboard", "dismissGuard"], outputs: ["dismiss"] }, { kind: "component", type: MnInputField, selector: "mn-lib-input-field", inputs: ["props"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }] });
|
|
4217
|
+
}
|
|
4218
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnDropdown, decorators: [{
|
|
4219
|
+
type: Component,
|
|
4220
|
+
args: [{ selector: 'mn-lib-dropdown', standalone: true, imports: [NgClass, NgTemplateOutlet, FormsModule, MnButton, MnBottomSheet, MnInputField, LucideDynamicIcon], template: "<div class=\"relative inline-flex\">\n <!-- Trigger -->\n <button\n #trigger\n mnButton\n type=\"button\"\n [id]=\"resolvedId\"\n [data]=\"triggerData\"\n [ngClass]=\"triggerClasses\"\n [attr.aria-label]=\"triggerLabelText ? null : triggerAriaLabel\"\n [attr.aria-haspopup]=\"'menu'\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-controls]=\"isOpen ? resolvedId + '-menu' : null\"\n (click)=\"toggle()\"\n >\n @if (triggerLabelText) {\n <span class=\"truncate\">{{ triggerLabelText }}</span>\n }\n <!-- One glyph, rendered like a menu item's icon: a caller's template, else lucide data\n (a preset resolves to its own data). No per-preset switch. -->\n @if (triggerIconTemplate; as tpl) {\n <span class=\"shrink-0 inline-flex items-center\">\n <ng-container [ngTemplateOutlet]=\"tpl\"></ng-container>\n </span>\n } @else if (triggerIconData; as glyph) {\n <span class=\"shrink-0 inline-flex items-center\">\n <svg [lucideIcon]=\"glyph.data\" [size]=\"glyph.size\" [class.opacity-70]=\"glyph.dim\"></svg>\n </span>\n }\n </button>\n\n <!-- Menu -->\n @if (isOpen) {\n @if (isSheet) {\n <!-- On mobile the menu is presented as the shared bottom sheet: chrome (backdrop,\n grabber, swipe-to-dismiss, slide animation) lives in mn-bottom-sheet; this\n component only projects the item list into it. The host is portalled to\n document.body (see the `sheet` ViewChild). -->\n <mn-bottom-sheet\n #sheet\n (dismiss)=\"close()\"\n [ariaLabel]=\"menuLabel || triggerAriaLabel\"\n [maxHeightVh]=\"80\"\n [minHeightPx]=\"sheetFloorPx\"\n >\n <div [id]=\"resolvedId + '-menu'\" role=\"menu\" class=\"flex flex-col flex-1 min-h-0 overflow-hidden\">\n <!-- The sheet covers its own trigger, so it carries a header to name itself; the\n way out is the grabber (swipe-to-dismiss) and a backdrop tap. -->\n <div class=\"px-4 pt-1 pb-2 shrink-0\">\n <p class=\"text-base font-bold text-base-content truncate\">{{ menuLabel || triggerAriaLabel }}</p>\n </div>\n <ng-container [ngTemplateOutlet]=\"searchBox\" [ngTemplateOutletContext]=\"{ sheet: true }\"></ng-container>\n <div class=\"flex-1 flex flex-col overflow-auto overscroll-contain\">\n <ng-container [ngTemplateOutlet]=\"items\" [ngTemplateOutletContext]=\"{ sheet: true }\"></ng-container>\n </div>\n </div>\n </mn-bottom-sheet>\n } @else {\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div\n #dropdown\n (click)=\"$event.stopPropagation()\"\n [id]=\"resolvedId + '-menu'\"\n [ngClass]=\"panelClasses\"\n [style.left]=\"dropdownStyle.left\"\n [style.top]=\"dropdownStyle.top\"\n [style.bottom]=\"dropdownStyle.bottom\"\n [style.max-height]=\"dropdownStyle.maxHeight\"\n [style.height.px]=\"panelFloorPx\"\n [style.width.px]=\"panelWidthPx\"\n role=\"menu\"\n >\n @if (menuLabel) {\n <p class=\"px-3 pt-1 pb-1.5 text-xs font-medium text-base-content/50 truncate shrink-0\">{{ menuLabel }}</p>\n }\n <ng-container [ngTemplateOutlet]=\"searchBox\" [ngTemplateOutletContext]=\"{ sheet: false }\"></ng-container>\n @if (isSearchable) {\n <!-- Its own scroll region so the pinned search box above stays fixed and the\n locked panel height (panelFloorPx) doesn't change as the list filters. The\n flex column lets the empty state fill and centre in the reserved space. -->\n <div class=\"flex-1 min-h-0 flex flex-col overflow-auto\">\n <ng-container [ngTemplateOutlet]=\"items\" [ngTemplateOutletContext]=\"{ sheet: false }\"></ng-container>\n </div>\n } @else {\n <ng-container [ngTemplateOutlet]=\"items\" [ngTemplateOutletContext]=\"{ sheet: false }\"></ng-container>\n }\n </div>\n }\n }\n\n <!-- The item list, shared verbatim by the sheet and the anchored popover. `sheet`\n only tunes the spacing so touch targets are roomier on mobile. -->\n <ng-template #items let-sheet=\"sheet\">\n @for (item of filteredActions; track $index) {\n @if (asAction(item); as action) {\n <button\n type=\"button\"\n role=\"menuitem\"\n [disabled]=\"action.disabled\"\n [attr.aria-current]=\"action.active ? 'true' : null\"\n [class.opacity-50]=\"action.disabled\"\n [class.pointer-events-none]=\"action.disabled\"\n [ngClass]=\"[actionColorClass(action), sheet ? 'px-4 py-3 text-base' : 'px-3 py-2 text-sm', action.active ? 'bg-primary/10 font-medium' : '']\"\n class=\"flex w-full shrink-0 items-center gap-x-2.5 text-left cursor-pointer hover:bg-base-200 focus-visible:bg-base-200 focus:outline-none transition-colors\"\n (click)=\"select(action)\"\n >\n @if (action.icon) {\n <span class=\"shrink-0 inline-flex items-center\">\n @if (isTemplateRef(action.icon)) {\n <ng-container [ngTemplateOutlet]=\"action.icon\"></ng-container>\n } @else {\n <!-- Data icon: rendered here so the item sizes it to match its own text\n (larger in the sheet, where the rows are touch-sized). -->\n <svg [lucideIcon]=\"$any(action.icon)\" [size]=\"sheet ? 18 : 16\"></svg>\n }\n </span>\n }\n <span class=\"truncate min-w-0\">{{ actionLabel(action) }}</span>\n <!-- The current choice's marker (e.g. the active language). Decorative: the\n state is conveyed to assistive tech by `aria-current` on the row. -->\n @if (action.active) {\n <svg\n [lucideIcon]=\"checkIcon\"\n [size]=\"sheet ? 18 : 16\"\n class=\"ml-auto shrink-0 text-primary\"\n aria-hidden=\"true\"\n ></svg>\n }\n </button>\n } @else {\n <hr role=\"separator\" [ngClass]=\"sheet ? 'mx-4 my-1.5' : 'mx-2 my-1'\" class=\"shrink-0 border-t border-base-300\" />\n }\n }\n @if (isSearchable && filteredActions.length === 0) {\n <div class=\"flex-1 flex flex-col items-center justify-center gap-2 px-4 py-6 text-center text-base-content/50\">\n <svg [lucideIcon]=\"icons.SearchX\" [size]=\"sheet ? 28 : 24\" class=\"opacity-60\"></svg>\n <span [ngClass]=\"sheet ? 'text-base' : 'text-sm'\">{{ searchEmptyLabel }}</span>\n </div>\n }\n </ng-template>\n\n <!-- The filter input, shared by the sheet and the anchored popover. Autofocused on\n desktop (`!sheet`) so typing starts immediately; deliberately not on mobile, where\n it would pop the soft keyboard and fight the viewport-anchored sheet. Enter runs\n the first visible action via the wrapper's bubbled keydown. -->\n <ng-template #searchBox let-sheet=\"sheet\">\n @if (isSearchable) {\n <!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->\n <div\n (click)=\"$event.stopPropagation()\"\n (keydown.enter)=\"selectFirstVisible()\"\n [ngClass]=\"sheet ? 'px-4 py-2' : 'p-2'\"\n class=\"border-b border-base-300 shrink-0\"\n >\n <mn-lib-input-field\n (ngModelChange)=\"onSearch($event)\"\n [ngModelOptions]=\"{ standalone: true }\"\n [ngModel]=\"searchTerm\"\n [props]=\"{\n id: resolvedId + '-search',\n type: 'search',\n placeholder: searchPlaceholder,\n ariaLabel: searchPlaceholder,\n fullWidth: true,\n size: 'sm',\n autoFocus: !sheet\n }\"\n ></mn-lib-input-field>\n </div>\n }\n </ng-template>\n</div>\n" }]
|
|
4221
|
+
}], propDecorators: { datasource: [{
|
|
4222
|
+
type: Input,
|
|
4223
|
+
args: [{ required: true }]
|
|
4224
|
+
}], triggerRef: [{
|
|
4225
|
+
type: ViewChild,
|
|
4226
|
+
args: ['trigger', { static: false, read: ElementRef }]
|
|
4227
|
+
}], dropdownRef: [{
|
|
4228
|
+
type: ViewChild,
|
|
4229
|
+
args: ['dropdown', { static: false }]
|
|
4230
|
+
}], sheetRef: [{
|
|
4231
|
+
type: ViewChild,
|
|
4232
|
+
args: ['sheet', { static: false, read: ElementRef }]
|
|
4233
|
+
}], onDocumentClick: [{
|
|
4234
|
+
type: HostListener,
|
|
4235
|
+
args: ['document:click', ['$event']]
|
|
4236
|
+
}], onEscape: [{
|
|
4237
|
+
type: HostListener,
|
|
4238
|
+
args: ['document:keydown.escape']
|
|
4239
|
+
}], onWindowScrollOrResize: [{
|
|
4240
|
+
type: HostListener,
|
|
4241
|
+
args: ['window:scroll', []]
|
|
4242
|
+
}, {
|
|
4243
|
+
type: HostListener,
|
|
4244
|
+
args: ['window:resize', []]
|
|
4245
|
+
}] } });
|
|
4246
|
+
|
|
4247
|
+
/**
|
|
4248
|
+
* Public API of the `mn-angular-lib/forms` entry point: form fields (input, checkbox, textarea, datetime, file input, select, multi-select, dropdown).
|
|
4249
|
+
*
|
|
4250
|
+
* Each entry point is its own module in the published package, so a consumer's bundler
|
|
4251
|
+
* splits it into the chunk that uses it instead of loading the whole library at startup.
|
|
4252
|
+
* The root `mn-angular-lib` entry re-exports every entry point.
|
|
4253
|
+
*/
|
|
4254
|
+
|
|
4255
|
+
/**
|
|
4256
|
+
* Generated bundle index. Do not edit.
|
|
4257
|
+
*/
|
|
4258
|
+
|
|
4259
|
+
export { MN_CHECKBOX_CONFIG, MN_DATETIME_CONFIG, MN_DROPDOWN_CONFIG, MN_INPUT_FIELD_CONFIG, MN_MULTI_SELECT_CONFIG, MN_SELECT_CONFIG, MN_TEXTAREA_CONFIG, MnCheckbox, MnDatetime, MnDropdown, MnFileInput, MnInputField, MnMultiSelect, MnSelect, MnTextarea, dateTimeAdapter, defaultTextAdapter, mnCheckboxVariants, mnCheckboxWrapperVariants, mnDatetimeVariants, mnDropdownTriggerVariants, mnFileInputVariants, mnInputFieldVariants, mnMultiSelectVariants, mnSelectVariants, mnTextareaVariants, numberAdapter, pickAdapter };
|
|
4260
|
+
//# sourceMappingURL=mn-angular-lib-forms.mjs.map
|