@wirekyt/angular 0.0.6 → 0.0.7

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.
@@ -0,0 +1,628 @@
1
+ import * as checkbox from '@wirekyt/dom/machines/checkbox';
2
+ import { anatomy } from '@wirekyt/dom/machines/checkbox';
3
+ import * as i0 from '@angular/core';
4
+ import { InjectionToken, inject, TemplateRef, ViewContainerRef, effect, DestroyRef, Directive, Renderer2, ElementRef, signal, computed, untracked, input, model, booleanAttribute, forwardRef, output } from '@angular/core';
5
+ import { bindProps, injectLocale, injectEnvironment, createId, useMachine, createCvaController } from '@wirekyt/angular';
6
+ import { injectFieldsetContextOptional } from '@wirekyt/angular/fieldset';
7
+ import { injectFieldContextOptional } from '@wirekyt/angular/field';
8
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
9
+
10
+ const checkboxAnatomy = anatomy.extendWith("group");
11
+
12
+ const CHECKBOX_CONTEXT = new InjectionToken("WIREKYT.CHECKBOX_CONTEXT");
13
+ function injectCheckboxContext() {
14
+ return inject(CHECKBOX_CONTEXT);
15
+ }
16
+
17
+ class CheckboxContext {
18
+ static ngTemplateContextGuard(_directive, context) {
19
+ void context;
20
+ return true;
21
+ }
22
+ checkbox = injectCheckboxContext();
23
+ templateRef = inject(TemplateRef);
24
+ viewContainer = inject(ViewContainerRef);
25
+ constructor() {
26
+ const view = this.viewContainer.createEmbeddedView(this.templateRef, {
27
+ $implicit: this.checkbox.api,
28
+ api: this.checkbox.api,
29
+ });
30
+ effect(() => {
31
+ this.checkbox.api();
32
+ view.detectChanges();
33
+ });
34
+ inject(DestroyRef).onDestroy(() => view.destroy());
35
+ }
36
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxContext, deps: [], target: i0.ɵɵFactoryTarget.Directive });
37
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.0", type: CheckboxContext, isStandalone: true, selector: "[checkboxContext]", exportAs: ["checkboxContext"], ngImport: i0 });
38
+ }
39
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxContext, decorators: [{
40
+ type: Directive,
41
+ args: [{
42
+ selector: "[checkboxContext]",
43
+ standalone: true,
44
+ exportAs: "checkboxContext",
45
+ }]
46
+ }], ctorParameters: () => [] });
47
+
48
+ class CheckboxControl {
49
+ constructor() {
50
+ const context = injectCheckboxContext();
51
+ bindProps({
52
+ elementRef: inject(ElementRef),
53
+ renderer: inject(Renderer2),
54
+ destroyRef: inject(DestroyRef),
55
+ props: () => context.api().getControlProps(),
56
+ });
57
+ }
58
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxControl, deps: [], target: i0.ɵɵFactoryTarget.Directive });
59
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.0", type: CheckboxControl, isStandalone: true, selector: "[checkboxControl]", exportAs: ["checkboxControl"], ngImport: i0 });
60
+ }
61
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxControl, decorators: [{
62
+ type: Directive,
63
+ args: [{
64
+ selector: "[checkboxControl]",
65
+ standalone: true,
66
+ exportAs: "checkboxControl",
67
+ }]
68
+ }], ctorParameters: () => [] });
69
+
70
+ const uniqueValues = (values) => Array.from(new Set(values.map((value) => String(value))));
71
+ function useCheckboxGroup(options = { context: () => ({}) }) {
72
+ const fieldset = injectFieldsetContextOptional();
73
+ const uncontrolledValue = signal(uniqueValues(options.context().defaultValue ?? []), /* @ts-ignore */
74
+ ...(ngDevMode ? [{ debugName: "uncontrolledValue" }] : /* istanbul ignore next */ []));
75
+ let defaultEffectInitialized = false;
76
+ let defaultHydrationChecked = false;
77
+ let userTouched = false;
78
+ const resolved = computed(() => {
79
+ const props = options.context();
80
+ return {
81
+ defaultValue: props.defaultValue,
82
+ value: props.value,
83
+ name: props.name,
84
+ disabled: Boolean(props.disabled) || Boolean(fieldset?.disabled()),
85
+ readOnly: Boolean(props.readOnly),
86
+ invalid: Boolean(props.invalid) || Boolean(fieldset?.invalid()),
87
+ maxSelectedValues: props.maxSelectedValues,
88
+ onValueChange: props.onValueChange,
89
+ };
90
+ }, /* @ts-ignore */
91
+ ...(ngDevMode ? [{ debugName: "resolved" }] : /* istanbul ignore next */ []));
92
+ const value = computed(() => uniqueValues(resolved().value ??
93
+ (userTouched ? uncontrolledValue() : (resolved().defaultValue ?? uncontrolledValue()))), /* @ts-ignore */
94
+ ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
95
+ const name = computed(() => resolved().name, /* @ts-ignore */
96
+ ...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
97
+ const disabled = computed(() => resolved().disabled, /* @ts-ignore */
98
+ ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
99
+ const readOnly = computed(() => resolved().readOnly, /* @ts-ignore */
100
+ ...(ngDevMode ? [{ debugName: "readOnly" }] : /* istanbul ignore next */ []));
101
+ const invalid = computed(() => resolved().invalid, /* @ts-ignore */
102
+ ...(ngDevMode ? [{ debugName: "invalid" }] : /* istanbul ignore next */ []));
103
+ const interactive = computed(() => !(disabled() || readOnly()), /* @ts-ignore */
104
+ ...(ngDevMode ? [{ debugName: "interactive" }] : /* istanbul ignore next */ []));
105
+ const isAtMax = computed(() => {
106
+ const max = resolved().maxSelectedValues;
107
+ return max != null && value().length >= max;
108
+ }, /* @ts-ignore */
109
+ ...(ngDevMode ? [{ debugName: "isAtMax" }] : /* istanbul ignore next */ []));
110
+ const setValue = (nextValue) => {
111
+ const next = uniqueValues(nextValue);
112
+ if (resolved().value === undefined) {
113
+ userTouched = true;
114
+ uncontrolledValue.set(next);
115
+ }
116
+ untracked(() => resolved().onValueChange?.(next));
117
+ };
118
+ effect(() => {
119
+ const next = resolved();
120
+ if (!defaultEffectInitialized) {
121
+ defaultEffectInitialized = true;
122
+ return;
123
+ }
124
+ if (userTouched || next.value !== undefined || defaultHydrationChecked)
125
+ return;
126
+ defaultHydrationChecked = true;
127
+ if (next.defaultValue === undefined)
128
+ return;
129
+ uncontrolledValue.set(uniqueValues(next.defaultValue));
130
+ });
131
+ const isChecked = (itemValue) => {
132
+ if (itemValue == null)
133
+ return false;
134
+ return value().some((current) => String(current) === String(itemValue));
135
+ };
136
+ const addValue = (itemValue) => {
137
+ if (!interactive())
138
+ return;
139
+ if (isChecked(itemValue))
140
+ return;
141
+ if (isAtMax())
142
+ return;
143
+ setValue(value().concat(itemValue));
144
+ };
145
+ const removeValue = (itemValue) => {
146
+ if (!interactive())
147
+ return;
148
+ setValue(value().filter((current) => String(current) !== String(itemValue)));
149
+ };
150
+ const toggleValue = (itemValue) => {
151
+ if (isChecked(itemValue)) {
152
+ removeValue(itemValue);
153
+ }
154
+ else {
155
+ addValue(itemValue);
156
+ }
157
+ };
158
+ const getItemProps = (props) => {
159
+ const checked = props.value != null ? isChecked(props.value) : undefined;
160
+ return {
161
+ checked,
162
+ onCheckedChange() {
163
+ if (props.value != null) {
164
+ toggleValue(props.value);
165
+ }
166
+ },
167
+ name: name(),
168
+ disabled: disabled() || (isAtMax() && !checked) || undefined,
169
+ readOnly: readOnly() || undefined,
170
+ invalid: invalid() || undefined,
171
+ };
172
+ };
173
+ return {
174
+ value,
175
+ name,
176
+ disabled,
177
+ readOnly,
178
+ invalid,
179
+ isChecked,
180
+ setValue,
181
+ addValue,
182
+ removeValue,
183
+ toggleValue,
184
+ getItemProps,
185
+ };
186
+ }
187
+
188
+ const CHECKBOX_GROUP_CONTEXT = new InjectionToken("WIREKYT.CHECKBOX_GROUP_CONTEXT");
189
+ function injectCheckboxGroupContext() {
190
+ return inject(CHECKBOX_GROUP_CONTEXT);
191
+ }
192
+ function injectCheckboxGroupContextOptional() {
193
+ return inject(CHECKBOX_GROUP_CONTEXT, { optional: true });
194
+ }
195
+
196
+ class CheckboxGroup {
197
+ defaultValue = input(undefined, /* @ts-ignore */
198
+ ...(ngDevMode ? [{ debugName: "defaultValue" }] : /* istanbul ignore next */ []));
199
+ valueModel = model(undefined, { ...(ngDevMode ? { debugName: "valueModel" } : /* istanbul ignore next */ {}), alias: "value" });
200
+ nameInput = input(undefined, { ...(ngDevMode ? { debugName: "nameInput" } : /* istanbul ignore next */ {}), alias: "name" });
201
+ disabledInput = input(false, { ...(ngDevMode ? { debugName: "disabledInput" } : /* istanbul ignore next */ {}), alias: "disabled",
202
+ transform: booleanAttribute });
203
+ readOnlyInput = input(false, { ...(ngDevMode ? { debugName: "readOnlyInput" } : /* istanbul ignore next */ {}), alias: "readOnly",
204
+ transform: booleanAttribute });
205
+ invalidInput = input(false, { ...(ngDevMode ? { debugName: "invalidInput" } : /* istanbul ignore next */ {}), alias: "invalid",
206
+ transform: booleanAttribute });
207
+ maxSelectedValues = input(undefined, /* @ts-ignore */
208
+ ...(ngDevMode ? [{ debugName: "maxSelectedValues" }] : /* istanbul ignore next */ []));
209
+ group = useCheckboxGroup({
210
+ context: () => ({
211
+ defaultValue: this.defaultValue(),
212
+ value: this.valueModel(),
213
+ name: this.nameInput(),
214
+ disabled: this.disabledInput(),
215
+ readOnly: this.readOnlyInput(),
216
+ invalid: this.invalidInput(),
217
+ maxSelectedValues: this.maxSelectedValues(),
218
+ onValueChange: (value) => this.valueModel.set(value),
219
+ }),
220
+ });
221
+ value = this.group.value;
222
+ name = this.group.name;
223
+ disabled = this.group.disabled;
224
+ readOnly = this.group.readOnly;
225
+ invalid = this.group.invalid;
226
+ isChecked(value) {
227
+ return this.group.isChecked(value);
228
+ }
229
+ setValue(value) {
230
+ this.group.setValue(value);
231
+ }
232
+ addValue(value) {
233
+ this.group.addValue(value);
234
+ }
235
+ removeValue(value) {
236
+ this.group.removeValue(value);
237
+ }
238
+ toggleValue(value) {
239
+ this.group.toggleValue(value);
240
+ }
241
+ getItemProps(props) {
242
+ return this.group.getItemProps(props);
243
+ }
244
+ constructor() {
245
+ bindProps({
246
+ elementRef: inject(ElementRef),
247
+ renderer: inject(Renderer2),
248
+ destroyRef: inject(DestroyRef),
249
+ props: () => ({ role: "group", ...checkboxAnatomy.build().group.attrs }),
250
+ });
251
+ }
252
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxGroup, deps: [], target: i0.ɵɵFactoryTarget.Directive });
253
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.0", type: CheckboxGroup, isStandalone: true, selector: "[checkboxGroup]", inputs: { defaultValue: { classPropertyName: "defaultValue", publicName: "defaultValue", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, nameInput: { classPropertyName: "nameInput", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, disabledInput: { classPropertyName: "disabledInput", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, readOnlyInput: { classPropertyName: "readOnlyInput", publicName: "readOnly", isSignal: true, isRequired: false, transformFunction: null }, invalidInput: { classPropertyName: "invalidInput", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, maxSelectedValues: { classPropertyName: "maxSelectedValues", publicName: "maxSelectedValues", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "valueChange" }, providers: [{ provide: CHECKBOX_GROUP_CONTEXT, useExisting: forwardRef(() => CheckboxGroup) }], exportAs: ["checkboxGroup"], ngImport: i0 });
254
+ }
255
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxGroup, decorators: [{
256
+ type: Directive,
257
+ args: [{
258
+ selector: "[checkboxGroup]",
259
+ standalone: true,
260
+ exportAs: "checkboxGroup",
261
+ providers: [{ provide: CHECKBOX_GROUP_CONTEXT, useExisting: forwardRef(() => CheckboxGroup) }],
262
+ }]
263
+ }], ctorParameters: () => [], propDecorators: { defaultValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultValue", required: false }] }], valueModel: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], nameInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], disabledInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], readOnlyInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "readOnly", required: false }] }], invalidInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], maxSelectedValues: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxSelectedValues", required: false }] }] } });
264
+
265
+ class CheckboxGroupProvider {
266
+ groupValue = input.required({ ...(ngDevMode ? { debugName: "groupValue" } : /* istanbul ignore next */ {}), alias: "value" });
267
+ get value() {
268
+ return this.groupValue().value;
269
+ }
270
+ get name() {
271
+ return this.groupValue().name;
272
+ }
273
+ get disabled() {
274
+ return this.groupValue().disabled;
275
+ }
276
+ get readOnly() {
277
+ return this.groupValue().readOnly;
278
+ }
279
+ get invalid() {
280
+ return this.groupValue().invalid;
281
+ }
282
+ isChecked(value) {
283
+ return this.groupValue().isChecked(value);
284
+ }
285
+ setValue(value) {
286
+ this.groupValue().setValue(value);
287
+ }
288
+ addValue(value) {
289
+ this.groupValue().addValue(value);
290
+ }
291
+ removeValue(value) {
292
+ this.groupValue().removeValue(value);
293
+ }
294
+ toggleValue(value) {
295
+ this.groupValue().toggleValue(value);
296
+ }
297
+ getItemProps(props) {
298
+ return this.groupValue().getItemProps(props);
299
+ }
300
+ constructor() {
301
+ bindProps({
302
+ elementRef: inject(ElementRef),
303
+ renderer: inject(Renderer2),
304
+ destroyRef: inject(DestroyRef),
305
+ props: () => ({ role: "group", ...checkboxAnatomy.build().group.attrs }),
306
+ });
307
+ }
308
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxGroupProvider, deps: [], target: i0.ɵɵFactoryTarget.Directive });
309
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.0", type: CheckboxGroupProvider, isStandalone: true, selector: "[checkboxGroupProvider]", inputs: { groupValue: { classPropertyName: "groupValue", publicName: "value", isSignal: true, isRequired: true, transformFunction: null } }, providers: [
310
+ { provide: CHECKBOX_GROUP_CONTEXT, useExisting: forwardRef(() => CheckboxGroupProvider) },
311
+ ], exportAs: ["checkboxGroupProvider"], ngImport: i0 });
312
+ }
313
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxGroupProvider, decorators: [{
314
+ type: Directive,
315
+ args: [{
316
+ selector: "[checkboxGroupProvider]",
317
+ standalone: true,
318
+ exportAs: "checkboxGroupProvider",
319
+ providers: [
320
+ { provide: CHECKBOX_GROUP_CONTEXT, useExisting: forwardRef(() => CheckboxGroupProvider) },
321
+ ],
322
+ }]
323
+ }], ctorParameters: () => [], propDecorators: { groupValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }] } });
324
+
325
+ class CheckboxHiddenInput {
326
+ constructor() {
327
+ const context = injectCheckboxContext();
328
+ const field = injectFieldContextOptional();
329
+ bindProps({
330
+ elementRef: inject(ElementRef),
331
+ renderer: inject(Renderer2),
332
+ destroyRef: inject(DestroyRef),
333
+ props: () => {
334
+ const props = context.api().getHiddenInputProps();
335
+ const onBlur = props["onBlur"];
336
+ return {
337
+ ...props,
338
+ "aria-describedby": field?.ariaDescribedby(),
339
+ onBlur: (event) => {
340
+ onBlur?.(event);
341
+ context.markTouched?.();
342
+ },
343
+ };
344
+ },
345
+ });
346
+ }
347
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxHiddenInput, deps: [], target: i0.ɵɵFactoryTarget.Directive });
348
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.0", type: CheckboxHiddenInput, isStandalone: true, selector: "[checkboxHiddenInput]", exportAs: ["checkboxHiddenInput"], ngImport: i0 });
349
+ }
350
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxHiddenInput, decorators: [{
351
+ type: Directive,
352
+ args: [{
353
+ selector: "[checkboxHiddenInput]",
354
+ standalone: true,
355
+ exportAs: "checkboxHiddenInput",
356
+ }]
357
+ }], ctorParameters: () => [] });
358
+
359
+ class CheckboxIndicator {
360
+ indeterminate = input(false, { ...(ngDevMode ? { debugName: "indeterminate" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
361
+ constructor() {
362
+ const context = injectCheckboxContext();
363
+ bindProps({
364
+ elementRef: inject(ElementRef),
365
+ renderer: inject(Renderer2),
366
+ destroyRef: inject(DestroyRef),
367
+ props: () => {
368
+ const api = context.api();
369
+ return {
370
+ ...api.getIndicatorProps(),
371
+ hidden: this.indeterminate() ? !api.indeterminate : !api.checked,
372
+ };
373
+ },
374
+ });
375
+ }
376
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxIndicator, deps: [], target: i0.ɵɵFactoryTarget.Directive });
377
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.0", type: CheckboxIndicator, isStandalone: true, selector: "[checkboxIndicator]", inputs: { indeterminate: { classPropertyName: "indeterminate", publicName: "indeterminate", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["checkboxIndicator"], ngImport: i0 });
378
+ }
379
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxIndicator, decorators: [{
380
+ type: Directive,
381
+ args: [{
382
+ selector: "[checkboxIndicator]",
383
+ standalone: true,
384
+ exportAs: "checkboxIndicator",
385
+ }]
386
+ }], ctorParameters: () => [], propDecorators: { indeterminate: [{ type: i0.Input, args: [{ isSignal: true, alias: "indeterminate", required: false }] }] } });
387
+
388
+ class CheckboxLabel {
389
+ constructor() {
390
+ const context = injectCheckboxContext();
391
+ bindProps({
392
+ elementRef: inject(ElementRef),
393
+ renderer: inject(Renderer2),
394
+ destroyRef: inject(DestroyRef),
395
+ props: () => context.api().getLabelProps(),
396
+ });
397
+ }
398
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
399
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.0", type: CheckboxLabel, isStandalone: true, selector: "[checkboxLabel]", exportAs: ["checkboxLabel"], ngImport: i0 });
400
+ }
401
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxLabel, decorators: [{
402
+ type: Directive,
403
+ args: [{
404
+ selector: "[checkboxLabel]",
405
+ standalone: true,
406
+ exportAs: "checkboxLabel",
407
+ }]
408
+ }], ctorParameters: () => [] });
409
+
410
+ function useCheckbox(options = { context: () => ({}) }) {
411
+ const locale = injectLocale();
412
+ const environment = injectEnvironment();
413
+ const field = injectFieldContextOptional();
414
+ const group = injectCheckboxGroupContextOptional();
415
+ const fallbackId = createId();
416
+ return useMachine({
417
+ machine: checkbox.machine,
418
+ context: () => {
419
+ const ownProps = options.context();
420
+ const groupProps = group?.getItemProps({ value: ownProps.value });
421
+ const groupCheckedChange = groupProps?.onCheckedChange;
422
+ const ownCheckedChange = ownProps.onCheckedChange;
423
+ const ids = {
424
+ label: field?.ids.label,
425
+ hiddenInput: field?.ids.control,
426
+ ...ownProps.ids,
427
+ };
428
+ return {
429
+ dir: locale.dir,
430
+ getRootNode: environment.getRootNode,
431
+ ...groupProps,
432
+ ...ownProps,
433
+ id: ownProps.id ?? fallbackId,
434
+ ids,
435
+ checked: ownProps.checked ?? groupProps?.checked,
436
+ name: ownProps.name ?? groupProps?.name,
437
+ disabled: Boolean(groupProps?.disabled) ||
438
+ Boolean(ownProps.disabled) ||
439
+ Boolean(field?.disabled()) ||
440
+ undefined,
441
+ invalid: Boolean(groupProps?.invalid) ||
442
+ Boolean(ownProps.invalid) ||
443
+ Boolean(field?.invalid()) ||
444
+ undefined,
445
+ readOnly: Boolean(groupProps?.readOnly) ||
446
+ Boolean(ownProps.readOnly) ||
447
+ Boolean(field?.readOnly()) ||
448
+ undefined,
449
+ required: Boolean(ownProps.required) || Boolean(field?.required()) || undefined,
450
+ onCheckedChange: (details) => {
451
+ groupCheckedChange?.();
452
+ ownCheckedChange?.(details);
453
+ },
454
+ };
455
+ },
456
+ connect: (service, normalize) => checkbox.connect(service, normalize),
457
+ });
458
+ }
459
+
460
+ class CheckboxRoot {
461
+ id = input(undefined, /* @ts-ignore */
462
+ ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
463
+ elementIds = input(undefined, { ...(ngDevMode ? { debugName: "elementIds" } : /* istanbul ignore next */ {}), alias: "ids" });
464
+ checked = model(undefined, /* @ts-ignore */
465
+ ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
466
+ defaultChecked = input(undefined, { ...(ngDevMode ? { debugName: "defaultChecked" } : /* istanbul ignore next */ {}), transform: (value) => typeof value === "boolean"
467
+ ? value
468
+ : value === "indeterminate"
469
+ ? value
470
+ : booleanAttribute(value) });
471
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
472
+ invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
473
+ required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
474
+ readOnly = input(false, { ...(ngDevMode ? { debugName: "readOnly" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
475
+ name = input(undefined, /* @ts-ignore */
476
+ ...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
477
+ form = input(undefined, /* @ts-ignore */
478
+ ...(ngDevMode ? [{ debugName: "form" }] : /* istanbul ignore next */ []));
479
+ value = input(undefined, /* @ts-ignore */
480
+ ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
481
+ checkedDetailsChange = output();
482
+ group = injectCheckboxGroupContextOptional();
483
+ disabledFromForm = signal(false, /* @ts-ignore */
484
+ ...(ngDevMode ? [{ debugName: "disabledFromForm" }] : /* istanbul ignore next */ []));
485
+ pendingInternalWrites = 0;
486
+ hasExternalCheckedBinding = false;
487
+ hasReceivedFormWrite = false;
488
+ cva = createCvaController({
489
+ value: this.checked,
490
+ setDisabled: (disabled) => this.disabledFromForm.set(disabled),
491
+ componentName: "CheckboxRoot",
492
+ hasExternalModelBinding: () => this.hasExternalCheckedBinding,
493
+ });
494
+ machine = useCheckbox({
495
+ context: () => ({
496
+ id: this.id(),
497
+ ids: this.elementIds(),
498
+ checked: this.checked(),
499
+ defaultChecked: this.defaultChecked(),
500
+ disabled: this.disabled() || this.disabledFromForm() || undefined,
501
+ invalid: this.invalid() || undefined,
502
+ required: this.required() || undefined,
503
+ readOnly: this.readOnly() || undefined,
504
+ name: this.name(),
505
+ form: this.form(),
506
+ value: this.value(),
507
+ onCheckedChange: (details) => {
508
+ const shouldWriteModel = !this.group || this.hasExternalCheckedBinding || this.checked() !== undefined;
509
+ if (shouldWriteModel && this.checked() !== details.checked) {
510
+ this.pendingInternalWrites++;
511
+ this.checked.set(details.checked);
512
+ }
513
+ this.checkedDetailsChange.emit(details);
514
+ this.cva.notifyValueChange(details.checked);
515
+ },
516
+ }),
517
+ });
518
+ state = this.machine.state;
519
+ api = this.machine.api;
520
+ service = this.machine.service;
521
+ send = this.machine.send;
522
+ constructor() {
523
+ let firstRun = true;
524
+ effect(() => {
525
+ void this.checked();
526
+ if (firstRun) {
527
+ firstRun = false;
528
+ this.pendingInternalWrites = 0;
529
+ return;
530
+ }
531
+ if (this.pendingInternalWrites > 0) {
532
+ this.pendingInternalWrites--;
533
+ return;
534
+ }
535
+ this.hasExternalCheckedBinding = true;
536
+ });
537
+ bindProps({
538
+ elementRef: inject(ElementRef),
539
+ renderer: inject(Renderer2),
540
+ destroyRef: inject(DestroyRef),
541
+ props: () => this.api().getRootProps(),
542
+ });
543
+ }
544
+ markTouched() {
545
+ this.cva.markTouched();
546
+ }
547
+ writeValue(value) {
548
+ const next = value === null ? undefined : value;
549
+ const current = this.checked();
550
+ if (!this.hasReceivedFormWrite && current !== undefined) {
551
+ this.hasExternalCheckedBinding = true;
552
+ }
553
+ this.hasReceivedFormWrite = true;
554
+ if (current !== next) {
555
+ this.pendingInternalWrites++;
556
+ }
557
+ this.cva.writeValue(value);
558
+ }
559
+ registerOnChange(fn) {
560
+ this.cva.registerOnChange(fn);
561
+ }
562
+ registerOnTouched(fn) {
563
+ this.cva.registerOnTouched(fn);
564
+ }
565
+ setDisabledState(disabled) {
566
+ this.cva.setDisabledState(disabled);
567
+ }
568
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxRoot, deps: [], target: i0.ɵɵFactoryTarget.Directive });
569
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.0", type: CheckboxRoot, isStandalone: true, selector: "[checkboxRoot]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, elementIds: { classPropertyName: "elementIds", publicName: "ids", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, defaultChecked: { classPropertyName: "defaultChecked", publicName: "defaultChecked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, readOnly: { classPropertyName: "readOnly", publicName: "readOnly", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, form: { classPropertyName: "form", publicName: "form", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", checkedDetailsChange: "checkedDetailsChange" }, providers: [
570
+ { provide: CHECKBOX_CONTEXT, useExisting: forwardRef(() => CheckboxRoot) },
571
+ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxRoot), multi: true },
572
+ ], exportAs: ["checkboxRoot"], ngImport: i0 });
573
+ }
574
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxRoot, decorators: [{
575
+ type: Directive,
576
+ args: [{
577
+ selector: "[checkboxRoot]",
578
+ standalone: true,
579
+ exportAs: "checkboxRoot",
580
+ providers: [
581
+ { provide: CHECKBOX_CONTEXT, useExisting: forwardRef(() => CheckboxRoot) },
582
+ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxRoot), multi: true },
583
+ ],
584
+ }]
585
+ }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], elementIds: [{ type: i0.Input, args: [{ isSignal: true, alias: "ids", required: false }] }], checked: [{ type: i0.Input, args: [{ isSignal: true, alias: "checked", required: false }] }, { type: i0.Output, args: ["checkedChange"] }], defaultChecked: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultChecked", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], readOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readOnly", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], form: [{ type: i0.Input, args: [{ isSignal: true, alias: "form", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], checkedDetailsChange: [{ type: i0.Output, args: ["checkedDetailsChange"] }] } });
586
+
587
+ class CheckboxRootProvider {
588
+ value = input.required(/* @ts-ignore */
589
+ ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
590
+ get state() {
591
+ return this.value().state;
592
+ }
593
+ get api() {
594
+ return this.value().api;
595
+ }
596
+ get service() {
597
+ return this.value().service;
598
+ }
599
+ get send() {
600
+ return this.value().send;
601
+ }
602
+ constructor() {
603
+ bindProps({
604
+ elementRef: inject(ElementRef),
605
+ renderer: inject(Renderer2),
606
+ destroyRef: inject(DestroyRef),
607
+ props: () => this.value().api().getRootProps(),
608
+ });
609
+ }
610
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxRootProvider, deps: [], target: i0.ɵɵFactoryTarget.Directive });
611
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.0", type: CheckboxRootProvider, isStandalone: true, selector: "[checkboxRootProvider]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null } }, providers: [{ provide: CHECKBOX_CONTEXT, useExisting: forwardRef(() => CheckboxRootProvider) }], exportAs: ["checkboxRootProvider"], ngImport: i0 });
612
+ }
613
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.0", ngImport: i0, type: CheckboxRootProvider, decorators: [{
614
+ type: Directive,
615
+ args: [{
616
+ selector: "[checkboxRootProvider]",
617
+ standalone: true,
618
+ exportAs: "checkboxRootProvider",
619
+ providers: [{ provide: CHECKBOX_CONTEXT, useExisting: forwardRef(() => CheckboxRootProvider) }],
620
+ }]
621
+ }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }] } });
622
+
623
+ /**
624
+ * Generated bundle index. Do not edit.
625
+ */
626
+
627
+ export { CHECKBOX_CONTEXT, CHECKBOX_GROUP_CONTEXT, CheckboxContext, CheckboxControl, CheckboxGroup, CheckboxGroupProvider, CheckboxHiddenInput, CheckboxIndicator, CheckboxLabel, CheckboxRoot, CheckboxRootProvider, checkboxAnatomy, injectCheckboxContext, injectCheckboxGroupContext, injectCheckboxGroupContextOptional, useCheckbox, useCheckboxGroup };
628
+ //# sourceMappingURL=wirekyt-angular-checkbox.mjs.map