forty-cdk 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tutkli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,343 @@
1
+ # forty-cdk
2
+
3
+ Headless / styleless UI primitives for Angular with WAI-ARIA accessibility built in.
4
+ Inspired by Radix UI and Base UI but reinterpreted idiomatically for modern Angular.
5
+
6
+ **New here?** [Your first overlay](../../docs/your-first-overlay.md) walks one Popover from empty markup to styled-and-animated and explains the two concepts every overlay shares: the `@if` / open-state model and the portal → global CSS requirement.
7
+
8
+ **Styling these primitives?** [Styling forty-cdk](../../docs/styling.md) explains the three hooks you style against — your own class (not the directive selector), `data-*` state attributes, and `--for-*` custom properties — and links to each primitive's styling reference.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install forty-cdk
14
+ ```
15
+
16
+ ### Peer dependencies
17
+
18
+ Required:
19
+
20
+ - `@angular/common` `^22.0.0`
21
+ - `@angular/core` `^22.0.0`
22
+
23
+ Optional — install only if you use the matching entry point / primitives:
24
+
25
+ | Peer | Needed by |
26
+ | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
27
+ | `@angular/forms` `^22.0.0` | Form-control primitives (`Switch`, `Checkbox`, `RadioGroup`, `Listbox`, `Select`, `Slider`, `Combobox`, …). They implement `FormValueControl` / `FormCheckboxControl` from `@angular/forms/signals` for `[formField]` auto-wiring. The contract is type-only, so the published bundle never references the package — consumers using only non-form primitives can skip it. |
28
+ | `@internationalized/date` `^3.0.0` | The `forty-cdk/internationalized-date` entry point (`InternationalizedDateAdapter`, `InternationalizedDateTimeAdapter`). The date/time primitives themselves only depend on the abstract `DateAdapter` contract from the main entry point — install this peer only when you import that entry point. |
29
+
30
+ `@angular/forms/signals` is stable as of Angular 22, so the peer follows the standard major range (`^22.0.0`).
31
+
32
+ ### Regular dependencies
33
+
34
+ `@floating-ui/dom` is a regular dependency, installed automatically with the package. Positioned overlays (`Tooltip`, `Popover`, `Menu`, `Combobox`, `Select`, etc.) import it statically from the main entry point, so every consumer's build must be able to resolve it — but it is internal-only (no floating-ui value crosses the public API) and tree-shakes out of your bundle when you don't use any positioned primitive.
35
+
36
+ ## Primitives
37
+
38
+ Each primitive lives under [`src/lib/<primitive>/`](src/lib) with its own `README.md` and a minimal styleless usage example.
39
+
40
+ The library ships one main entry point (`forty-cdk`) plus a single secondary entry point, `forty-cdk/internationalized-date`, which holds the `@internationalized/date` adapters so that optional peer stays truly optional. Standalone directives plus `"sideEffects": false` let tree-shakers drop primitives you don't import.
41
+
42
+ ## Directive → host element matrix
43
+
44
+ Quick reference for "which HTML element should I put this directive on?". Recommendations are derived from each primitive's WAI-ARIA pattern (e.g. focusable triggers as `<button type="button">`, the combobox input as a real `<input>` so caret/selection work) and from each primitive's README usage example. `any element` means the directive is element-agnostic — pick the tag that matches your semantics.
45
+
46
+ Selectors marked with `(element)` use an element selector instead of an attribute selector; everything else is `[attribute]`. Form-control hosts (`forSwitch`, `forCheckbox`, `forRadio`, `forToggle`) deliberately render as `<button type="button">` — the directive forces `type="button"` and provides `role="switch"` / `"checkbox"` / `"radio"` / `aria-pressed` so the consumer keeps full keyboard, focus, and form-state behaviour without an `<input>` whose chrome can't be styled.
47
+
48
+ ### Accordion
49
+
50
+ | Selector | Host |
51
+ | ----------------------- | ---------------------------------------------- |
52
+ | `[forAccordion]` | `<div>` |
53
+ | `[forAccordionItem]` | `<div>` |
54
+ | `[forAccordionTrigger]` | `<button>` (wrapped in `<h2>`–`<h6>`, per APG) |
55
+ | `[forAccordionContent]` | `<section>` |
56
+
57
+ ### Aspect Ratio
58
+
59
+ | Selector | Host |
60
+ | ------------------ | ------- |
61
+ | `[forAspectRatio]` | `<div>` |
62
+
63
+ ### Avatar
64
+
65
+ | Selector | Host |
66
+ | --------------------- | ------------------------------ |
67
+ | `[forAvatar]` | `<span>` |
68
+ | `img[forAvatarImage]` | `<img>` (selector enforces it) |
69
+ | `[forAvatarFallback]` | `<span>` |
70
+
71
+ ### Checkbox
72
+
73
+ | Selector | Host |
74
+ | ------------------------ | --------------------------------- |
75
+ | `[forCheckbox]` | `<button type="button">` (forced) |
76
+ | `[forCheckboxIndicator]` | `<span>` |
77
+
78
+ ### Combobox
79
+
80
+ | Selector | Host |
81
+ | ------------------------- | ------------------------------------------------------------------- |
82
+ | `[forCombobox]` | `<div>` |
83
+ | `[forComboboxInput]` | `<input>` (a real text field — `role="combobox"` + caret semantics) |
84
+ | `[forComboboxContent]` | `<div>` |
85
+ | `[forComboboxOption]` | `<div>` |
86
+ | `[forComboboxIndicator]` | `<span>` |
87
+ | `[forComboboxEmpty]` | `<div>` |
88
+ | `[forComboboxStatus]` | `<div>` |
89
+ | `[forComboboxClear]` | `<button>` |
90
+ | `[forComboboxChips]` | `<div>` |
91
+ | `[forComboboxChip]` | `<span>` |
92
+ | `[forComboboxChipRemove]` | `<button>` |
93
+ | `[forComboboxGroup]` | `<div>` |
94
+ | `[forComboboxGroupLabel]` | `<div>` |
95
+ | `[forComboboxSeparator]` | `<div>` |
96
+
97
+ ### Context Menu
98
+
99
+ | Selector | Host |
100
+ | ------------------------------------------------------------ | ---------------- |
101
+ | `[forContextMenu]` | `<div>` |
102
+ | `[forContextMenuTrigger]` | any element |
103
+ | Menu surface pieces (`[forMenuContent]`, `[forMenuItem]`, …) | see _Menu_ below |
104
+
105
+ ### Dialog
106
+
107
+ | Selector | Host |
108
+ | ------------------------ | ---------------------------------------------------------- |
109
+ | `[forDialog]` | `<div>` |
110
+ | `[forDialogTrigger]` | `<button>` |
111
+ | `[forDialogTitle]` | `<h2>` (any heading level works; pick by document outline) |
112
+ | `[forDialogDescription]` | `<p>` |
113
+ | `[forDialogClose]` | `<button>` |
114
+ | `[forDialogBackdrop]` | `<div>` |
115
+
116
+ ### Disclosure
117
+
118
+ | Selector | Host |
119
+ | ------------------------ | ------------------------ |
120
+ | `[forDisclosure]` | `<div>` |
121
+ | `[forDisclosureTrigger]` | `<button>` |
122
+ | `[forDisclosureContent]` | `<div>` (or `<section>`) |
123
+
124
+ ### Dropdown Menu
125
+
126
+ | Selector | Host |
127
+ | ------------------------------------------------------------ | ---------------- |
128
+ | `[forDropdownMenu]` | `<div>` |
129
+ | `[forDropdownMenuTrigger]` | `<button>` |
130
+ | Menu surface pieces (`[forMenuContent]`, `[forMenuItem]`, …) | see _Menu_ below |
131
+
132
+ ### Hover Card
133
+
134
+ | Selector | Host |
135
+ | ----------------------- | ----------- |
136
+ | `[forHoverCard]` | `<div>` |
137
+ | `[forHoverCardTrigger]` | any element |
138
+ | `[forHoverCardContent]` | `<div>` |
139
+ | `[forHoverCardArrow]` | `<div>` |
140
+
141
+ ### Listbox
142
+
143
+ | Selector | Host |
144
+ | ----------------------------- | -------- |
145
+ | `[forListbox]` | `<div>` |
146
+ | `[forListboxOption]` | `<div>` |
147
+ | `[forListboxOptionIndicator]` | `<span>` |
148
+ | `[forListboxGroup]` | `<div>` |
149
+ | `[forListboxGroupLabel]` | `<div>` |
150
+
151
+ ### Menu
152
+
153
+ | Selector | Host |
154
+ | -------------------------- | -------- |
155
+ | `[forMenu]` | `<div>` |
156
+ | `[forMenuContent]` | `<div>` |
157
+ | `[forMenuItem]` | `<div>` |
158
+ | `[forMenuItemIndicator]` | `<span>` |
159
+ | `[forMenuCheckboxItem]` | `<div>` |
160
+ | `[forMenuRadioItem]` | `<div>` |
161
+ | `[forMenuRadioGroup]` | `<div>` |
162
+ | `[forMenuSeparator]` | `<div>` |
163
+ | `[forMenuGroup]` | `<div>` |
164
+ | `[forMenuGroupLabel]` | `<div>` |
165
+ | `[forMenuSub]` | `<div>` |
166
+ | `[forMenuSubTrigger]` | `<div>` |
167
+ | `[forMenuHorizontalArrow]` | `<span>` |
168
+
169
+ ### Menubar
170
+
171
+ | Selector | Host |
172
+ | ------------------------------------------------------------ | ---------------- |
173
+ | `[forMenubar]` | `<div>` |
174
+ | `[forMenubarTrigger]` | `<button>` |
175
+ | Menu surface pieces (`[forMenuContent]`, `[forMenuItem]`, …) | see _Menu_ above |
176
+
177
+ ### Meter
178
+
179
+ | Selector | Host |
180
+ | --------------------- | ------- |
181
+ | `[forMeter]` | `<div>` |
182
+ | `[forMeterIndicator]` | `<div>` |
183
+
184
+ ### Navigation Menu
185
+
186
+ | Selector | Host |
187
+ | ------------------------------ | ---------------------------------------- |
188
+ | `[forNavigationMenu]` | `<nav>` |
189
+ | `[forNavigationMenuList]` | `<ul>` (or `<div>`) |
190
+ | `[forNavigationMenuItem]` | `<li>` (or `<div>`, matching the list) |
191
+ | `[forNavigationMenuTrigger]` | `<button>` |
192
+ | `[forNavigationMenuLink]` | `<a>` (or `<button>` for in-app actions) |
193
+ | `[forNavigationMenuContent]` | `<div>` |
194
+ | `[forNavigationMenuViewport]` | `<div>` |
195
+ | `[forNavigationMenuIndicator]` | `<div>` |
196
+
197
+ ### Pane Resizer
198
+
199
+ | Selector | Host |
200
+ | ------------------ | ------- |
201
+ | `[forPaneResizer]` | `<div>` |
202
+
203
+ ### Popover
204
+
205
+ | Selector | Host |
206
+ | ------------------------- | ------------------------------------- |
207
+ | `[forPopover]` | `<div>` |
208
+ | `[forPopoverTrigger]` | `<button>` |
209
+ | `[forPopoverContent]` | `<div>` |
210
+ | `[forPopoverTitle]` | `<h2>` (any heading; pick by outline) |
211
+ | `[forPopoverDescription]` | `<p>` |
212
+ | `[forPopoverClose]` | `<button>` |
213
+ | `[forPopoverArrow]` | `<div>` |
214
+ | `[forPopoverAnchor]` | any element |
215
+
216
+ ### Progress
217
+
218
+ | Selector | Host |
219
+ | ------------------------ | ------- |
220
+ | `[forProgress]` | `<div>` |
221
+ | `[forProgressIndicator]` | `<div>` |
222
+
223
+ ### Radio Group
224
+
225
+ | Selector | Host |
226
+ | ----------------- | --------------------------------- |
227
+ | `[forRadioGroup]` | `<div>` |
228
+ | `[forRadio]` | `<button type="button">` (forced) |
229
+
230
+ ### Scroll Area
231
+
232
+ | Selector | Host |
233
+ | -------------------------- | ------- |
234
+ | `[forScrollArea]` | `<div>` |
235
+ | `[forScrollAreaViewport]` | `<div>` |
236
+ | `[forScrollAreaContent]` | `<div>` |
237
+ | `[forScrollAreaScrollbar]` | `<div>` |
238
+ | `[forScrollAreaThumb]` | `<div>` |
239
+ | `[forScrollAreaCorner]` | `<div>` |
240
+
241
+ ### Select
242
+
243
+ | Selector | Host |
244
+ | ----------------------- | ---------- |
245
+ | `[forSelect]` | `<div>` |
246
+ | `[forSelectTrigger]` | `<button>` |
247
+ | `[forSelectValue]` | `<span>` |
248
+ | `[forSelectContent]` | `<div>` |
249
+ | `[forSelectOption]` | `<div>` |
250
+ | `[forSelectIndicator]` | `<span>` |
251
+ | `[forSelectGroup]` | `<div>` |
252
+ | `[forSelectGroupLabel]` | `<div>` |
253
+ | `[forSelectSeparator]` | `<div>` |
254
+
255
+ ### Separator
256
+
257
+ | Selector | Host |
258
+ | ---------------- | --------------------------------------------------- |
259
+ | `[forSeparator]` | `<div>` (or `<hr>` for the static, decorative case) |
260
+
261
+ ### Slider
262
+
263
+ | Selector | Host |
264
+ | ------------------ | ------- |
265
+ | `[forSlider]` | `<div>` |
266
+ | `[forSliderTrack]` | `<div>` |
267
+ | `[forSliderRange]` | `<div>` |
268
+ | `[forSliderThumb]` | `<div>` |
269
+
270
+ ### Switch
271
+
272
+ | Selector | Host |
273
+ | ------------- | --------------------------------- |
274
+ | `[forSwitch]` | `<button type="button">` (forced) |
275
+
276
+ ### Tabs
277
+
278
+ | Selector | Host |
279
+ | ------------------ | ---------- |
280
+ | `[forTabs]` | `<div>` |
281
+ | `[forTabsList]` | `<div>` |
282
+ | `[forTabsTrigger]` | `<button>` |
283
+ | `[forTabsContent]` | `<div>` |
284
+
285
+ ### Toast
286
+
287
+ | Selector | Host |
288
+ | ------------------------------------------------------ | ---------- |
289
+ | `for-toast-viewport` (element) or `[forToastViewport]` | `<div>` |
290
+ | `[forToast]` | `<div>` |
291
+ | `[forToastTitle]` | `<div>` |
292
+ | `[forToastDescription]` | `<div>` |
293
+ | `[forToastAction]` | `<button>` |
294
+ | `[forToastClose]` | `<button>` |
295
+
296
+ ### Toggle
297
+
298
+ | Selector | Host |
299
+ | ---------------------- | --------------------------------- |
300
+ | `[forToggle]` | `<button type="button">` (forced) |
301
+ | `[forToggleGroup]` | `<div>` |
302
+ | `[forToggleGroupItem]` | `<button type="button">` (forced) |
303
+
304
+ ### Toolbar
305
+
306
+ | Selector | Host |
307
+ | ----------------------- | ---------- |
308
+ | `[forToolbar]` | `<div>` |
309
+ | `[forToolbarButton]` | `<button>` |
310
+ | `[forToolbarLink]` | `<a>` |
311
+ | `[forToolbarSeparator]` | `<div>` |
312
+
313
+ ### Tooltip
314
+
315
+ | Selector | Host |
316
+ | --------------------- | ----------- |
317
+ | `[forTooltip]` | `<div>` |
318
+ | `[forTooltipTrigger]` | any element |
319
+ | `[forTooltipContent]` | `<div>` |
320
+ | `[forTooltipArrow]` | `<div>` |
321
+
322
+ ## Building
323
+
324
+ ```bash
325
+ ng build forty-cdk
326
+ ```
327
+
328
+ Build artifacts land in `dist/forty-cdk` (consumed locally via the `forty-cdk` path alias in the root `tsconfig.json`).
329
+
330
+ ## Testing
331
+
332
+ Tests run on Vitest via the Angular CLI builder `@angular/build:unit-test`:
333
+
334
+ ```bash
335
+ pnpm test # all specs, single pass
336
+ pnpm exec ng test forty-cdk --watch # watch mode
337
+ pnpm exec ng test forty-cdk --include "projects/forty-cdk/src/lib/accordion/accordion.spec.ts" # single file
338
+ pnpm exec ng test forty-cdk --filter "Enter and Space select" # tests by name (regex)
339
+ ```
340
+
341
+ The `-- <path>` / `-- -t "<name>"` passthrough forms do **not** work on this setup (pnpm mangles the quoted `--`, so `ng` rejects it) — use the builder's own `--include` (repeatable) and `--filter` (regex) flags instead.
342
+
343
+ Every primitive's test suite includes a case running under `provideZonelessChangeDetection()` to keep reactivity working without Zone.js.
@@ -0,0 +1,232 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable } from '@angular/core';
3
+ import { today, getLocalTimeZone, CalendarDate, isSameDay, toCalendarDateTime, CalendarDateTime } from '@internationalized/date';
4
+ import { FOR_DATE_ADAPTER } from 'forty-cdk';
5
+
6
+ /**
7
+ * {@link DateAdapter} over `@internationalized/date`'s immutable `CalendarDate`.
8
+ * This is the recommended adapter: it is the same date primitive React Aria and
9
+ * Ark UI build on, it works in every browser today with no polyfill, and its
10
+ * reference-equality-on-mutation makes it signal-friendly.
11
+ *
12
+ * **Gregorian only.** `createDate` always builds a Gregorian `CalendarDate`, so
13
+ * the calendar grid is Gregorian regardless of the runtime locale. True
14
+ * non-Gregorian calendar systems are deferred to the planned Temporal adapter
15
+ * track (#354).
16
+ *
17
+ * Ships in the `forty-cdk/internationalized-date` secondary entry point so the
18
+ * main `forty-cdk` bundle never references `@internationalized/date` — the
19
+ * package is an **optional peer dependency**, required only by consumers who
20
+ * import this entry point. A consumer relying solely on
21
+ * `provideNativeDateAdapter()` never resolves it at all.
22
+ */
23
+ class InternationalizedDateAdapter {
24
+ /**
25
+ * Today as a `CalendarDate` in the runtime time zone (`getLocalTimeZone()`).
26
+ * Subject to the SSR/hydration caveat on {@link DateAdapter.today}.
27
+ */
28
+ today() {
29
+ return today(getLocalTimeZone());
30
+ }
31
+ createDate(year, month, day) {
32
+ return new CalendarDate(year, month, day);
33
+ }
34
+ getYear(date) {
35
+ return date.year;
36
+ }
37
+ getMonth(date) {
38
+ return date.month;
39
+ }
40
+ getDate(date) {
41
+ return date.day;
42
+ }
43
+ getDayOfWeek(date) {
44
+ return date.toDate(getLocalTimeZone()).getDay();
45
+ }
46
+ getDaysInMonth(date) {
47
+ return date.calendar.getDaysInMonth(date);
48
+ }
49
+ getFirstDayOfWeek() {
50
+ return 0;
51
+ }
52
+ addDays(date, n) {
53
+ return date.add({ days: n });
54
+ }
55
+ addMonths(date, n) {
56
+ return date.add({ months: n });
57
+ }
58
+ addYears(date, n) {
59
+ return date.add({ years: n });
60
+ }
61
+ compare(a, b) {
62
+ return a.compare(b);
63
+ }
64
+ isSameDay(a, b) {
65
+ return isSameDay(a, b);
66
+ }
67
+ isValid(date) {
68
+ return date instanceof CalendarDate;
69
+ }
70
+ /**
71
+ * Formats through the runtime's default locale and time zone. Subject to the
72
+ * SSR/hydration caveat on {@link DateAdapter.format}.
73
+ */
74
+ format(date, options) {
75
+ return new Intl.DateTimeFormat(undefined, options).format(date.toDate(getLocalTimeZone()));
76
+ }
77
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: InternationalizedDateAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
78
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: InternationalizedDateAdapter });
79
+ }
80
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: InternationalizedDateAdapter, decorators: [{
81
+ type: Injectable
82
+ }] });
83
+ /**
84
+ * Provides the {@link InternationalizedDateAdapter} as the active
85
+ * {@link DateAdapter}, making `ForCalendar` operate on `CalendarDate` values
86
+ * from `@internationalized/date`.
87
+ *
88
+ * Requires `@internationalized/date` to be installed (optional peer
89
+ * dependency).
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * bootstrapApplication(App, {
94
+ * providers: [provideInternationalizedDateAdapter()],
95
+ * });
96
+ * ```
97
+ */
98
+ function provideInternationalizedDateAdapter() {
99
+ return [{ provide: FOR_DATE_ADAPTER, useClass: InternationalizedDateAdapter }];
100
+ }
101
+
102
+ /**
103
+ * Time-capable {@link DateAdapter} over `@internationalized/date`'s immutable
104
+ * `CalendarDateTime`. It mirrors {@link InternationalizedDateAdapter} for all
105
+ * day operations but adds a wall-clock time component (hour / minute / second),
106
+ * so it backs `ForTimeField` and the time granularity of the date primitives.
107
+ * Use it when you want the `@internationalized/date` types *and* a time.
108
+ *
109
+ * **Gregorian only.** Like {@link InternationalizedDateAdapter}, `createDate`
110
+ * builds a Gregorian `CalendarDateTime`; non-Gregorian calendar systems are
111
+ * deferred to the planned Temporal adapter track (#354).
112
+ *
113
+ * Ships in the `forty-cdk/internationalized-date` secondary entry point so the
114
+ * main `forty-cdk` bundle never references `@internationalized/date` — the
115
+ * package is an **optional peer dependency**, required only by consumers who
116
+ * import this entry point. A consumer relying solely on
117
+ * `provideNativeDateAdapter()` never resolves it at all.
118
+ *
119
+ * `compare` orders by the full date-time (day *and* time); `compareDate`
120
+ * ignores the time and orders by calendar day, so the calendar grid stays
121
+ * day-granular even when `min`/`max` carry a time.
122
+ */
123
+ class InternationalizedDateTimeAdapter {
124
+ /**
125
+ * Today as a `CalendarDateTime` in the runtime time zone
126
+ * (`getLocalTimeZone()`). Subject to the SSR/hydration caveat on
127
+ * {@link DateAdapter.today}.
128
+ */
129
+ today() {
130
+ return toCalendarDateTime(today(getLocalTimeZone()));
131
+ }
132
+ createDate(year, month, day) {
133
+ return new CalendarDateTime(year, month, day);
134
+ }
135
+ getYear(date) {
136
+ return date.year;
137
+ }
138
+ getMonth(date) {
139
+ return date.month;
140
+ }
141
+ getDate(date) {
142
+ return date.day;
143
+ }
144
+ getDayOfWeek(date) {
145
+ return date.toDate(getLocalTimeZone()).getDay();
146
+ }
147
+ getDaysInMonth(date) {
148
+ return date.calendar.getDaysInMonth(date);
149
+ }
150
+ getFirstDayOfWeek() {
151
+ return 0;
152
+ }
153
+ addDays(date, n) {
154
+ return date.add({ days: n });
155
+ }
156
+ addMonths(date, n) {
157
+ return date.add({ months: n });
158
+ }
159
+ addYears(date, n) {
160
+ return date.add({ years: n });
161
+ }
162
+ compare(a, b) {
163
+ return a.compare(b);
164
+ }
165
+ compareDate(a, b) {
166
+ if (a.year !== b.year) {
167
+ return a.year - b.year;
168
+ }
169
+ if (a.month !== b.month) {
170
+ return a.month - b.month;
171
+ }
172
+ return a.day - b.day;
173
+ }
174
+ isSameDay(a, b) {
175
+ return isSameDay(a, b);
176
+ }
177
+ isValid(date) {
178
+ return date instanceof CalendarDateTime;
179
+ }
180
+ /**
181
+ * Formats through the runtime's default locale and time zone. Subject to the
182
+ * SSR/hydration caveat on {@link DateAdapter.format}.
183
+ */
184
+ format(date, options) {
185
+ return new Intl.DateTimeFormat(undefined, options).format(date.toDate(getLocalTimeZone()));
186
+ }
187
+ supportsTime() {
188
+ return true;
189
+ }
190
+ getHours(date) {
191
+ return date.hour;
192
+ }
193
+ getMinutes(date) {
194
+ return date.minute;
195
+ }
196
+ getSeconds(date) {
197
+ return date.second;
198
+ }
199
+ setTime(date, hours, minutes, seconds) {
200
+ return date.set({ hour: hours, minute: minutes, second: seconds, millisecond: 0 });
201
+ }
202
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: InternationalizedDateTimeAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
203
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: InternationalizedDateTimeAdapter });
204
+ }
205
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: InternationalizedDateTimeAdapter, decorators: [{
206
+ type: Injectable
207
+ }] });
208
+ /**
209
+ * Provides the {@link InternationalizedDateTimeAdapter} as the active
210
+ * {@link DateAdapter}, making the time / date-time primitives operate on
211
+ * `CalendarDateTime` values from `@internationalized/date`.
212
+ *
213
+ * Requires `@internationalized/date` to be installed (optional peer
214
+ * dependency).
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * bootstrapApplication(App, {
219
+ * providers: [provideInternationalizedDateTimeAdapter()],
220
+ * });
221
+ * ```
222
+ */
223
+ function provideInternationalizedDateTimeAdapter() {
224
+ return [{ provide: FOR_DATE_ADAPTER, useClass: InternationalizedDateTimeAdapter }];
225
+ }
226
+
227
+ /**
228
+ * Generated bundle index. Do not edit.
229
+ */
230
+
231
+ export { InternationalizedDateAdapter, InternationalizedDateTimeAdapter, provideInternationalizedDateAdapter, provideInternationalizedDateTimeAdapter };
232
+ //# sourceMappingURL=forty-cdk-internationalized-date.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forty-cdk-internationalized-date.mjs","sources":["../../../projects/forty-cdk/internationalized-date/src/internationalized-date-adapter.ts","../../../projects/forty-cdk/internationalized-date/src/internationalized-date-time-adapter.ts","../../../projects/forty-cdk/internationalized-date/src/forty-cdk-internationalized-date.ts"],"sourcesContent":["import { Injectable, type Provider } from '@angular/core';\r\nimport { CalendarDate, getLocalTimeZone, isSameDay, today } from '@internationalized/date';\r\n\r\nimport { type DateAdapter, FOR_DATE_ADAPTER } from 'forty-cdk';\r\n\r\n/**\r\n * {@link DateAdapter} over `@internationalized/date`'s immutable `CalendarDate`.\r\n * This is the recommended adapter: it is the same date primitive React Aria and\r\n * Ark UI build on, it works in every browser today with no polyfill, and its\r\n * reference-equality-on-mutation makes it signal-friendly.\r\n *\r\n * **Gregorian only.** `createDate` always builds a Gregorian `CalendarDate`, so\r\n * the calendar grid is Gregorian regardless of the runtime locale. True\r\n * non-Gregorian calendar systems are deferred to the planned Temporal adapter\r\n * track (#354).\r\n *\r\n * Ships in the `forty-cdk/internationalized-date` secondary entry point so the\r\n * main `forty-cdk` bundle never references `@internationalized/date` — the\r\n * package is an **optional peer dependency**, required only by consumers who\r\n * import this entry point. A consumer relying solely on\r\n * `provideNativeDateAdapter()` never resolves it at all.\r\n */\r\n@Injectable()\r\nexport class InternationalizedDateAdapter implements DateAdapter<CalendarDate> {\r\n /**\r\n * Today as a `CalendarDate` in the runtime time zone (`getLocalTimeZone()`).\r\n * Subject to the SSR/hydration caveat on {@link DateAdapter.today}.\r\n */\r\n today(): CalendarDate {\r\n return today(getLocalTimeZone());\r\n }\r\n\r\n createDate(year: number, month: number, day: number): CalendarDate {\r\n return new CalendarDate(year, month, day);\r\n }\r\n\r\n getYear(date: CalendarDate): number {\r\n return date.year;\r\n }\r\n\r\n getMonth(date: CalendarDate): number {\r\n return date.month;\r\n }\r\n\r\n getDate(date: CalendarDate): number {\r\n return date.day;\r\n }\r\n\r\n getDayOfWeek(date: CalendarDate): number {\r\n return date.toDate(getLocalTimeZone()).getDay();\r\n }\r\n\r\n getDaysInMonth(date: CalendarDate): number {\r\n return date.calendar.getDaysInMonth(date);\r\n }\r\n\r\n getFirstDayOfWeek(): number {\r\n return 0;\r\n }\r\n\r\n addDays(date: CalendarDate, n: number): CalendarDate {\r\n return date.add({ days: n });\r\n }\r\n\r\n addMonths(date: CalendarDate, n: number): CalendarDate {\r\n return date.add({ months: n });\r\n }\r\n\r\n addYears(date: CalendarDate, n: number): CalendarDate {\r\n return date.add({ years: n });\r\n }\r\n\r\n compare(a: CalendarDate, b: CalendarDate): number {\r\n return a.compare(b);\r\n }\r\n\r\n isSameDay(a: CalendarDate, b: CalendarDate): boolean {\r\n return isSameDay(a, b);\r\n }\r\n\r\n isValid(date: CalendarDate): boolean {\r\n return date instanceof CalendarDate;\r\n }\r\n\r\n /**\r\n * Formats through the runtime's default locale and time zone. Subject to the\r\n * SSR/hydration caveat on {@link DateAdapter.format}.\r\n */\r\n format(date: CalendarDate, options: Intl.DateTimeFormatOptions): string {\r\n return new Intl.DateTimeFormat(undefined, options).format(date.toDate(getLocalTimeZone()));\r\n }\r\n}\r\n\r\n/**\r\n * Provides the {@link InternationalizedDateAdapter} as the active\r\n * {@link DateAdapter}, making `ForCalendar` operate on `CalendarDate` values\r\n * from `@internationalized/date`.\r\n *\r\n * Requires `@internationalized/date` to be installed (optional peer\r\n * dependency).\r\n *\r\n * @example\r\n * ```ts\r\n * bootstrapApplication(App, {\r\n * providers: [provideInternationalizedDateAdapter()],\r\n * });\r\n * ```\r\n */\r\nexport function provideInternationalizedDateAdapter(): Provider[] {\r\n return [{ provide: FOR_DATE_ADAPTER, useClass: InternationalizedDateAdapter }];\r\n}\r\n","import { Injectable, type Provider } from '@angular/core';\r\nimport {\r\n CalendarDateTime,\r\n getLocalTimeZone,\r\n isSameDay,\r\n toCalendarDateTime,\r\n today,\r\n} from '@internationalized/date';\r\n\r\nimport { type DateAdapter, FOR_DATE_ADAPTER } from 'forty-cdk';\r\n\r\n/**\r\n * Time-capable {@link DateAdapter} over `@internationalized/date`'s immutable\r\n * `CalendarDateTime`. It mirrors {@link InternationalizedDateAdapter} for all\r\n * day operations but adds a wall-clock time component (hour / minute / second),\r\n * so it backs `ForTimeField` and the time granularity of the date primitives.\r\n * Use it when you want the `@internationalized/date` types *and* a time.\r\n *\r\n * **Gregorian only.** Like {@link InternationalizedDateAdapter}, `createDate`\r\n * builds a Gregorian `CalendarDateTime`; non-Gregorian calendar systems are\r\n * deferred to the planned Temporal adapter track (#354).\r\n *\r\n * Ships in the `forty-cdk/internationalized-date` secondary entry point so the\r\n * main `forty-cdk` bundle never references `@internationalized/date` — the\r\n * package is an **optional peer dependency**, required only by consumers who\r\n * import this entry point. A consumer relying solely on\r\n * `provideNativeDateAdapter()` never resolves it at all.\r\n *\r\n * `compare` orders by the full date-time (day *and* time); `compareDate`\r\n * ignores the time and orders by calendar day, so the calendar grid stays\r\n * day-granular even when `min`/`max` carry a time.\r\n */\r\n@Injectable()\r\nexport class InternationalizedDateTimeAdapter implements DateAdapter<CalendarDateTime> {\r\n /**\r\n * Today as a `CalendarDateTime` in the runtime time zone\r\n * (`getLocalTimeZone()`). Subject to the SSR/hydration caveat on\r\n * {@link DateAdapter.today}.\r\n */\r\n today(): CalendarDateTime {\r\n return toCalendarDateTime(today(getLocalTimeZone()));\r\n }\r\n\r\n createDate(year: number, month: number, day: number): CalendarDateTime {\r\n return new CalendarDateTime(year, month, day);\r\n }\r\n\r\n getYear(date: CalendarDateTime): number {\r\n return date.year;\r\n }\r\n\r\n getMonth(date: CalendarDateTime): number {\r\n return date.month;\r\n }\r\n\r\n getDate(date: CalendarDateTime): number {\r\n return date.day;\r\n }\r\n\r\n getDayOfWeek(date: CalendarDateTime): number {\r\n return date.toDate(getLocalTimeZone()).getDay();\r\n }\r\n\r\n getDaysInMonth(date: CalendarDateTime): number {\r\n return date.calendar.getDaysInMonth(date);\r\n }\r\n\r\n getFirstDayOfWeek(): number {\r\n return 0;\r\n }\r\n\r\n addDays(date: CalendarDateTime, n: number): CalendarDateTime {\r\n return date.add({ days: n });\r\n }\r\n\r\n addMonths(date: CalendarDateTime, n: number): CalendarDateTime {\r\n return date.add({ months: n });\r\n }\r\n\r\n addYears(date: CalendarDateTime, n: number): CalendarDateTime {\r\n return date.add({ years: n });\r\n }\r\n\r\n compare(a: CalendarDateTime, b: CalendarDateTime): number {\r\n return a.compare(b);\r\n }\r\n\r\n compareDate(a: CalendarDateTime, b: CalendarDateTime): number {\r\n if (a.year !== b.year) {\r\n return a.year - b.year;\r\n }\r\n if (a.month !== b.month) {\r\n return a.month - b.month;\r\n }\r\n return a.day - b.day;\r\n }\r\n\r\n isSameDay(a: CalendarDateTime, b: CalendarDateTime): boolean {\r\n return isSameDay(a, b);\r\n }\r\n\r\n isValid(date: CalendarDateTime): boolean {\r\n return date instanceof CalendarDateTime;\r\n }\r\n\r\n /**\r\n * Formats through the runtime's default locale and time zone. Subject to the\r\n * SSR/hydration caveat on {@link DateAdapter.format}.\r\n */\r\n format(date: CalendarDateTime, options: Intl.DateTimeFormatOptions): string {\r\n return new Intl.DateTimeFormat(undefined, options).format(date.toDate(getLocalTimeZone()));\r\n }\r\n\r\n supportsTime(): boolean {\r\n return true;\r\n }\r\n\r\n getHours(date: CalendarDateTime): number {\r\n return date.hour;\r\n }\r\n\r\n getMinutes(date: CalendarDateTime): number {\r\n return date.minute;\r\n }\r\n\r\n getSeconds(date: CalendarDateTime): number {\r\n return date.second;\r\n }\r\n\r\n setTime(\r\n date: CalendarDateTime,\r\n hours: number,\r\n minutes: number,\r\n seconds: number,\r\n ): CalendarDateTime {\r\n return date.set({ hour: hours, minute: minutes, second: seconds, millisecond: 0 });\r\n }\r\n}\r\n\r\n/**\r\n * Provides the {@link InternationalizedDateTimeAdapter} as the active\r\n * {@link DateAdapter}, making the time / date-time primitives operate on\r\n * `CalendarDateTime` values from `@internationalized/date`.\r\n *\r\n * Requires `@internationalized/date` to be installed (optional peer\r\n * dependency).\r\n *\r\n * @example\r\n * ```ts\r\n * bootstrapApplication(App, {\r\n * providers: [provideInternationalizedDateTimeAdapter()],\r\n * });\r\n * ```\r\n */\r\nexport function provideInternationalizedDateTimeAdapter(): Provider[] {\r\n return [{ provide: FOR_DATE_ADAPTER, useClass: InternationalizedDateTimeAdapter }];\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAKA;;;;;;;;;;;;;;;;AAgBG;MAEU,4BAA4B,CAAA;AACvC;;;AAGG;IACH,KAAK,GAAA;AACH,QAAA,OAAO,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAClC;AAEA,IAAA,UAAU,C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