@italia/globals 1.0.0-alpha.18 → 1.0.0-alpha.19
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/custom-elements.json +140 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/dispatch-cancelable.d.ts +31 -0
- package/dist/src/utils/dispatch-cancelable.d.ts.map +1 -0
- package/dist/src/utils/dispatch-cancelable.js +43 -0
- package/dist/src/utils/dispatch-cancelable.js.map +1 -0
- package/dist/src/utils/focus-fallback.d.ts +27 -0
- package/dist/src/utils/focus-fallback.d.ts.map +1 -0
- package/dist/src/utils/focus-fallback.js +63 -0
- package/dist/src/utils/focus-fallback.js.map +1 -0
- package/package.json +2 -2
package/custom-elements.json
CHANGED
|
@@ -167,6 +167,30 @@
|
|
|
167
167
|
"module": "./utils/cookies.js"
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
|
+
{
|
|
171
|
+
"kind": "js",
|
|
172
|
+
"name": "dispatchCancelable",
|
|
173
|
+
"declaration": {
|
|
174
|
+
"name": "dispatchCancelable",
|
|
175
|
+
"module": "./utils/dispatch-cancelable.js"
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"kind": "js",
|
|
180
|
+
"name": "focusableFallbackAncestor",
|
|
181
|
+
"declaration": {
|
|
182
|
+
"name": "focusableFallbackAncestor",
|
|
183
|
+
"module": "./utils/focus-fallback.js"
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"kind": "js",
|
|
188
|
+
"name": "nearestFocusableInDocument",
|
|
189
|
+
"declaration": {
|
|
190
|
+
"name": "nearestFocusableInDocument",
|
|
191
|
+
"module": "./utils/focus-fallback.js"
|
|
192
|
+
}
|
|
193
|
+
},
|
|
170
194
|
{
|
|
171
195
|
"kind": "js",
|
|
172
196
|
"name": "WindowManager",
|
|
@@ -2444,6 +2468,122 @@
|
|
|
2444
2468
|
}
|
|
2445
2469
|
]
|
|
2446
2470
|
},
|
|
2471
|
+
{
|
|
2472
|
+
"kind": "javascript-module",
|
|
2473
|
+
"path": "src/utils/dispatch-cancelable.ts",
|
|
2474
|
+
"declarations": [
|
|
2475
|
+
{
|
|
2476
|
+
"kind": "function",
|
|
2477
|
+
"name": "dispatchCancelable",
|
|
2478
|
+
"return": {
|
|
2479
|
+
"type": {
|
|
2480
|
+
"text": ""
|
|
2481
|
+
}
|
|
2482
|
+
},
|
|
2483
|
+
"parameters": [
|
|
2484
|
+
{
|
|
2485
|
+
"name": "host",
|
|
2486
|
+
"type": {
|
|
2487
|
+
"text": "HTMLElement"
|
|
2488
|
+
},
|
|
2489
|
+
"description": "the element dispatching the event"
|
|
2490
|
+
},
|
|
2491
|
+
{
|
|
2492
|
+
"name": "name",
|
|
2493
|
+
"type": {
|
|
2494
|
+
"text": "string"
|
|
2495
|
+
},
|
|
2496
|
+
"description": "the event name (kebab-case, `it-` prefixed)"
|
|
2497
|
+
},
|
|
2498
|
+
{
|
|
2499
|
+
"name": "detail",
|
|
2500
|
+
"type": {
|
|
2501
|
+
"text": "T"
|
|
2502
|
+
},
|
|
2503
|
+
"description": "the event `detail` payload"
|
|
2504
|
+
},
|
|
2505
|
+
{
|
|
2506
|
+
"name": "defaultAction",
|
|
2507
|
+
"type": {
|
|
2508
|
+
"text": "() => void"
|
|
2509
|
+
},
|
|
2510
|
+
"description": "the behavior executed when the event is not prevented"
|
|
2511
|
+
}
|
|
2512
|
+
],
|
|
2513
|
+
"description": "Dispatches a cancelable custom event and runs the provided default action\nonly if the consumer did not call `event.preventDefault()`.\n\nThis is the shared convention used across components (Tabs, Modal, Chip, Alert,\nForward, Back) to provide a sensible default JavaScript behavior out of the box\nwhile letting consumers intercept and override it. Notification deliberately does\nNOT use this: its show/close are always caller-initiated (no default markup-driven\ntrigger to override), so there was no real use case for blocking them — see\nit-notification.ts for the plain (non-cancelable) events it fires instead.\n\n```js\nel.addEventListener('it-alert-close', (e) => {\n e.preventDefault(); // block the default removal\n fetchConfirmation().then((ok) => { // async logic runs after prevention\n if (ok) e.target.close();\n });\n});\n```\n\nNote: `preventDefault()` must be called synchronously inside the listener.\nAsync code can run afterward; call the component's public method when ready."
|
|
2514
|
+
}
|
|
2515
|
+
],
|
|
2516
|
+
"exports": [
|
|
2517
|
+
{
|
|
2518
|
+
"kind": "js",
|
|
2519
|
+
"name": "dispatchCancelable",
|
|
2520
|
+
"declaration": {
|
|
2521
|
+
"name": "dispatchCancelable",
|
|
2522
|
+
"module": "src/utils/dispatch-cancelable.ts"
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
]
|
|
2526
|
+
},
|
|
2527
|
+
{
|
|
2528
|
+
"kind": "javascript-module",
|
|
2529
|
+
"path": "src/utils/focus-fallback.ts",
|
|
2530
|
+
"declarations": [
|
|
2531
|
+
{
|
|
2532
|
+
"kind": "function",
|
|
2533
|
+
"name": "focusableFallbackAncestor",
|
|
2534
|
+
"return": {
|
|
2535
|
+
"type": {
|
|
2536
|
+
"text": "HTMLElement | null"
|
|
2537
|
+
}
|
|
2538
|
+
},
|
|
2539
|
+
"parameters": [
|
|
2540
|
+
{
|
|
2541
|
+
"name": "el",
|
|
2542
|
+
"type": {
|
|
2543
|
+
"text": "HTMLElement"
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
],
|
|
2547
|
+
"description": "Returns the nearest focusable ancestor of `el` by walking up parentElement.\nUsed as the last-resort fallback when a self-removing component (chip, alert)\nhas no adjacent sibling of the same type to shift focus to.\n\n\"Focusable ancestor\" means an element with tabindex >= 0. The container that\nwraps a chip group or alert list is the expected target; authors following the\nWAI-ARIA pattern should give it tabindex=\"0\"."
|
|
2548
|
+
},
|
|
2549
|
+
{
|
|
2550
|
+
"kind": "function",
|
|
2551
|
+
"name": "nearestFocusableInDocument",
|
|
2552
|
+
"return": {
|
|
2553
|
+
"type": {
|
|
2554
|
+
"text": "HTMLElement | null"
|
|
2555
|
+
}
|
|
2556
|
+
},
|
|
2557
|
+
"parameters": [
|
|
2558
|
+
{
|
|
2559
|
+
"name": "el",
|
|
2560
|
+
"type": {
|
|
2561
|
+
"text": "HTMLElement"
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
],
|
|
2565
|
+
"description": "True last-resort fallback for when a self-removing component (alert, chip,\nnotification) has neither an adjacent sibling of the same type nor a\n`focusableFallbackAncestor` (i.e. no author-provided `tabindex=\"0\"` wrapper) —\nthe common case in practice, since most real usages don't add that wrapper.\nWithout this, focus silently drops to `<body>` with no way for a keyboard/AT\nuser to tell where they ended up.\n\nFinds the closest focusable element to `el` anywhere in the document, walking\noutward in document order: the nearest one that comes before `el` (closer to\nwhere the user's attention already was), falling back to the nearest one after.\nThis is a coarse, page-wide search — it may land focus on something not\nvisually adjacent — but it is deterministic and strictly better than silently\nlosing focus."
|
|
2566
|
+
}
|
|
2567
|
+
],
|
|
2568
|
+
"exports": [
|
|
2569
|
+
{
|
|
2570
|
+
"kind": "js",
|
|
2571
|
+
"name": "focusableFallbackAncestor",
|
|
2572
|
+
"declaration": {
|
|
2573
|
+
"name": "focusableFallbackAncestor",
|
|
2574
|
+
"module": "src/utils/focus-fallback.ts"
|
|
2575
|
+
}
|
|
2576
|
+
},
|
|
2577
|
+
{
|
|
2578
|
+
"kind": "js",
|
|
2579
|
+
"name": "nearestFocusableInDocument",
|
|
2580
|
+
"declaration": {
|
|
2581
|
+
"name": "nearestFocusableInDocument",
|
|
2582
|
+
"module": "src/utils/focus-fallback.ts"
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
]
|
|
2586
|
+
},
|
|
2447
2587
|
{
|
|
2448
2588
|
"kind": "javascript-module",
|
|
2449
2589
|
"path": "src/utils/logger.ts",
|
package/dist/src/index.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export { FocusTrapController, type FocusTrapConfig } from './controllers/focus-t
|
|
|
20
20
|
export { FormControl } from './form/form-control.js';
|
|
21
21
|
export { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';
|
|
22
22
|
export { cookies } from './utils/cookies.js';
|
|
23
|
+
export { dispatchCancelable } from './utils/dispatch-cancelable.js';
|
|
24
|
+
export { focusableFallbackAncestor, nearestFocusableInDocument } from './utils/focus-fallback.js';
|
|
23
25
|
export type Constructor<T = {}> = new (...args: any[]) => T;
|
|
24
26
|
export { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';
|
|
25
27
|
export { StoryFormControlMethodAndProps };
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAEzF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,EAAE;YACZ,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH;CACF;AAUD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,YAAY,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,EAC/B,KAAK,2BAA2B,GACjC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAEzF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,EAAE;YACZ,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH;CACF;AAUD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,YAAY,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,EAC/B,KAAK,2BAA2B,GACjC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAClG,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@ if (typeof window !== 'undefined') {
|
|
|
6
6
|
window._itAnalytics = window._itAnalytics || {};
|
|
7
7
|
window._itAnalytics = {
|
|
8
8
|
...window._itAnalytics,
|
|
9
|
-
version: '1.0.0-alpha.
|
|
9
|
+
version: '1.0.0-alpha.19',
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
export { TrackFocus, setAttributes, AriaKeyboardListController };
|
|
@@ -18,6 +18,8 @@ export { FocusTrapController } from './controllers/focus-trap-controller.js';
|
|
|
18
18
|
export { FormControl } from './form/form-control.js';
|
|
19
19
|
export { formCollections, FormControlController } from './form/form-controller.js';
|
|
20
20
|
export { cookies } from './utils/cookies.js';
|
|
21
|
+
export { dispatchCancelable } from './utils/dispatch-cancelable.js';
|
|
22
|
+
export { focusableFallbackAncestor, nearestFocusableInDocument } from './utils/focus-fallback.js';
|
|
21
23
|
export { WindowManager } from './window-manager.js';
|
|
22
24
|
export { StoryFormControlMethodAndProps };
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAUzF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,gBAAgB;KAC1B,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAUzF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,gBAAgB;KAC1B,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAElG,OAAO,EAAE,aAAa,EAAyC,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["import TrackFocus from './utils/track-focus.js';\n\nimport setAttributes from './directives/setAttributes.js';\nimport AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';\nimport { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';\n\ndeclare global {\n interface Window {\n _itAnalytics: {\n version: string;\n };\n }\n}\n\nif (typeof window !== 'undefined') {\n window._itAnalytics = window._itAnalytics || {};\n window._itAnalytics = {\n ...window._itAnalytics,\n version: '1.0.0-alpha.19',\n };\n}\n\nexport { TrackFocus, setAttributes, AriaKeyboardListController };\nexport type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';\nexport { RovingTabindexController } from './controllers/roving-tabindex-controller.js';\nexport type { RovingTabindexConfig } from './controllers/roving-tabindex-controller.js';\nexport {\n BaseComponent,\n BaseComponentInterface,\n BaseComponentType,\n BaseLocalizedComponent,\n} from './base-component/base-component.js';\nexport {\n AriaKeyboardAccordionController,\n type AriaKeyboardAccordionConfig,\n} from './controllers/aria-keyboard-accordion-controller.js';\nexport { CollapseAnimationController } from './controllers/collapse-controller.js';\nexport { FocusTrapController, type FocusTrapConfig } from './controllers/focus-trap-controller.js';\n\nexport { FormControl } from './form/form-control.js';\nexport { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';\nexport { cookies } from './utils/cookies.js';\nexport { dispatchCancelable } from './utils/dispatch-cancelable.js';\nexport { focusableFallbackAncestor, nearestFocusableInDocument } from './utils/focus-fallback.js';\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';\n\nexport { StoryFormControlMethodAndProps };\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatches a cancelable custom event and runs the provided default action
|
|
3
|
+
* only if the consumer did not call `event.preventDefault()`.
|
|
4
|
+
*
|
|
5
|
+
* This is the shared convention used across components (Tabs, Modal, Chip, Alert,
|
|
6
|
+
* Forward, Back) to provide a sensible default JavaScript behavior out of the box
|
|
7
|
+
* while letting consumers intercept and override it. Notification deliberately does
|
|
8
|
+
* NOT use this: its show/close are always caller-initiated (no default markup-driven
|
|
9
|
+
* trigger to override), so there was no real use case for blocking them — see
|
|
10
|
+
* it-notification.ts for the plain (non-cancelable) events it fires instead.
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
* el.addEventListener('it-alert-close', (e) => {
|
|
14
|
+
* e.preventDefault(); // block the default removal
|
|
15
|
+
* fetchConfirmation().then((ok) => { // async logic runs after prevention
|
|
16
|
+
* if (ok) e.target.close();
|
|
17
|
+
* });
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Note: `preventDefault()` must be called synchronously inside the listener.
|
|
22
|
+
* Async code can run afterward; call the component's public method when ready.
|
|
23
|
+
*
|
|
24
|
+
* @param host the element dispatching the event
|
|
25
|
+
* @param name the event name (kebab-case, `it-` prefixed)
|
|
26
|
+
* @param detail the event `detail` payload
|
|
27
|
+
* @param defaultAction the behavior executed when the event is not prevented
|
|
28
|
+
* @returns the dispatched event (inspect `defaultPrevented` if needed)
|
|
29
|
+
*/
|
|
30
|
+
export declare function dispatchCancelable<T>(host: HTMLElement, name: string, detail: T, defaultAction: () => void): CustomEvent<T>;
|
|
31
|
+
//# sourceMappingURL=dispatch-cancelable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-cancelable.d.ts","sourceRoot":"","sources":["../../../src/utils/dispatch-cancelable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,EACT,aAAa,EAAE,MAAM,IAAI,GACxB,WAAW,CAAC,CAAC,CAAC,CAYhB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatches a cancelable custom event and runs the provided default action
|
|
3
|
+
* only if the consumer did not call `event.preventDefault()`.
|
|
4
|
+
*
|
|
5
|
+
* This is the shared convention used across components (Tabs, Modal, Chip, Alert,
|
|
6
|
+
* Forward, Back) to provide a sensible default JavaScript behavior out of the box
|
|
7
|
+
* while letting consumers intercept and override it. Notification deliberately does
|
|
8
|
+
* NOT use this: its show/close are always caller-initiated (no default markup-driven
|
|
9
|
+
* trigger to override), so there was no real use case for blocking them — see
|
|
10
|
+
* it-notification.ts for the plain (non-cancelable) events it fires instead.
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
* el.addEventListener('it-alert-close', (e) => {
|
|
14
|
+
* e.preventDefault(); // block the default removal
|
|
15
|
+
* fetchConfirmation().then((ok) => { // async logic runs after prevention
|
|
16
|
+
* if (ok) e.target.close();
|
|
17
|
+
* });
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Note: `preventDefault()` must be called synchronously inside the listener.
|
|
22
|
+
* Async code can run afterward; call the component's public method when ready.
|
|
23
|
+
*
|
|
24
|
+
* @param host the element dispatching the event
|
|
25
|
+
* @param name the event name (kebab-case, `it-` prefixed)
|
|
26
|
+
* @param detail the event `detail` payload
|
|
27
|
+
* @param defaultAction the behavior executed when the event is not prevented
|
|
28
|
+
* @returns the dispatched event (inspect `defaultPrevented` if needed)
|
|
29
|
+
*/
|
|
30
|
+
export function dispatchCancelable(host, name, detail, defaultAction) {
|
|
31
|
+
const event = new CustomEvent(name, {
|
|
32
|
+
bubbles: true,
|
|
33
|
+
composed: true,
|
|
34
|
+
cancelable: true,
|
|
35
|
+
detail,
|
|
36
|
+
});
|
|
37
|
+
host.dispatchEvent(event);
|
|
38
|
+
if (!event.defaultPrevented) {
|
|
39
|
+
defaultAction();
|
|
40
|
+
}
|
|
41
|
+
return event;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=dispatch-cancelable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-cancelable.js","sourceRoot":"","sources":["../../../src/utils/dispatch-cancelable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAiB,EACjB,IAAY,EACZ,MAAS,EACT,aAAyB;IAEzB,MAAM,KAAK,GAAG,IAAI,WAAW,CAAI,IAAI,EAAE;QACrC,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,MAAM;KACP,CAAC,CAAC;IACH,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC5B,aAAa,EAAE,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Dispatches a cancelable custom event and runs the provided default action\n * only if the consumer did not call `event.preventDefault()`.\n *\n * This is the shared convention used across components (Tabs, Modal, Chip, Alert,\n * Forward, Back) to provide a sensible default JavaScript behavior out of the box\n * while letting consumers intercept and override it. Notification deliberately does\n * NOT use this: its show/close are always caller-initiated (no default markup-driven\n * trigger to override), so there was no real use case for blocking them — see\n * it-notification.ts for the plain (non-cancelable) events it fires instead.\n *\n * ```js\n * el.addEventListener('it-alert-close', (e) => {\n * e.preventDefault(); // block the default removal\n * fetchConfirmation().then((ok) => { // async logic runs after prevention\n * if (ok) e.target.close();\n * });\n * });\n * ```\n *\n * Note: `preventDefault()` must be called synchronously inside the listener.\n * Async code can run afterward; call the component's public method when ready.\n *\n * @param host the element dispatching the event\n * @param name the event name (kebab-case, `it-` prefixed)\n * @param detail the event `detail` payload\n * @param defaultAction the behavior executed when the event is not prevented\n * @returns the dispatched event (inspect `defaultPrevented` if needed)\n */\nexport function dispatchCancelable<T>(\n host: HTMLElement,\n name: string,\n detail: T,\n defaultAction: () => void,\n): CustomEvent<T> {\n const event = new CustomEvent<T>(name, {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail,\n });\n host.dispatchEvent(event);\n if (!event.defaultPrevented) {\n defaultAction();\n }\n return event;\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the nearest focusable ancestor of `el` by walking up parentElement.
|
|
3
|
+
* Used as the last-resort fallback when a self-removing component (chip, alert)
|
|
4
|
+
* has no adjacent sibling of the same type to shift focus to.
|
|
5
|
+
*
|
|
6
|
+
* "Focusable ancestor" means an element with tabindex >= 0. The container that
|
|
7
|
+
* wraps a chip group or alert list is the expected target; authors following the
|
|
8
|
+
* WAI-ARIA pattern should give it tabindex="0".
|
|
9
|
+
*/
|
|
10
|
+
export declare function focusableFallbackAncestor(el: HTMLElement): HTMLElement | null;
|
|
11
|
+
/**
|
|
12
|
+
* True last-resort fallback for when a self-removing component (alert, chip,
|
|
13
|
+
* notification) has neither an adjacent sibling of the same type nor a
|
|
14
|
+
* `focusableFallbackAncestor` (i.e. no author-provided `tabindex="0"` wrapper) —
|
|
15
|
+
* the common case in practice, since most real usages don't add that wrapper.
|
|
16
|
+
* Without this, focus silently drops to `<body>` with no way for a keyboard/AT
|
|
17
|
+
* user to tell where they ended up.
|
|
18
|
+
*
|
|
19
|
+
* Finds the closest focusable element to `el` anywhere in the document, walking
|
|
20
|
+
* outward in document order: the nearest one that comes before `el` (closer to
|
|
21
|
+
* where the user's attention already was), falling back to the nearest one after.
|
|
22
|
+
* This is a coarse, page-wide search — it may land focus on something not
|
|
23
|
+
* visually adjacent — but it is deterministic and strictly better than silently
|
|
24
|
+
* losing focus.
|
|
25
|
+
*/
|
|
26
|
+
export declare function nearestFocusableInDocument(el: HTMLElement): HTMLElement | null;
|
|
27
|
+
//# sourceMappingURL=focus-fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus-fallback.d.ts","sourceRoot":"","sources":["../../../src/utils/focus-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAQ7E;AAcD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAiB9E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the nearest focusable ancestor of `el` by walking up parentElement.
|
|
3
|
+
* Used as the last-resort fallback when a self-removing component (chip, alert)
|
|
4
|
+
* has no adjacent sibling of the same type to shift focus to.
|
|
5
|
+
*
|
|
6
|
+
* "Focusable ancestor" means an element with tabindex >= 0. The container that
|
|
7
|
+
* wraps a chip group or alert list is the expected target; authors following the
|
|
8
|
+
* WAI-ARIA pattern should give it tabindex="0".
|
|
9
|
+
*/
|
|
10
|
+
export function focusableFallbackAncestor(el) {
|
|
11
|
+
let current = el.parentElement;
|
|
12
|
+
while (current) {
|
|
13
|
+
const tab = current.getAttribute('tabindex');
|
|
14
|
+
if (tab !== null && parseInt(tab, 10) >= 0)
|
|
15
|
+
return current;
|
|
16
|
+
current = current.parentElement;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
/** Mirrors FocusTrapController's notion of "focusable", scoped to the handful of
|
|
21
|
+
* interactive elements consumers actually place next to alert/chip/notification. */
|
|
22
|
+
const FOCUSABLE_SELECTORS = [
|
|
23
|
+
'a[href]',
|
|
24
|
+
'button:not([disabled])',
|
|
25
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
26
|
+
'select:not([disabled])',
|
|
27
|
+
'textarea:not([disabled])',
|
|
28
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
29
|
+
'it-button:not([disabled])',
|
|
30
|
+
].join(',');
|
|
31
|
+
/**
|
|
32
|
+
* True last-resort fallback for when a self-removing component (alert, chip,
|
|
33
|
+
* notification) has neither an adjacent sibling of the same type nor a
|
|
34
|
+
* `focusableFallbackAncestor` (i.e. no author-provided `tabindex="0"` wrapper) —
|
|
35
|
+
* the common case in practice, since most real usages don't add that wrapper.
|
|
36
|
+
* Without this, focus silently drops to `<body>` with no way for a keyboard/AT
|
|
37
|
+
* user to tell where they ended up.
|
|
38
|
+
*
|
|
39
|
+
* Finds the closest focusable element to `el` anywhere in the document, walking
|
|
40
|
+
* outward in document order: the nearest one that comes before `el` (closer to
|
|
41
|
+
* where the user's attention already was), falling back to the nearest one after.
|
|
42
|
+
* This is a coarse, page-wide search — it may land focus on something not
|
|
43
|
+
* visually adjacent — but it is deterministic and strictly better than silently
|
|
44
|
+
* losing focus.
|
|
45
|
+
*/
|
|
46
|
+
export function nearestFocusableInDocument(el) {
|
|
47
|
+
const candidates = Array.from(document.querySelectorAll(FOCUSABLE_SELECTORS)).filter((candidate) => candidate !== el && !el.contains(candidate));
|
|
48
|
+
if (!candidates.length)
|
|
49
|
+
return null;
|
|
50
|
+
let closestBefore = null;
|
|
51
|
+
let closestAfter = null;
|
|
52
|
+
candidates.forEach((candidate) => {
|
|
53
|
+
// eslint-disable-next-line no-bitwise
|
|
54
|
+
if (el.compareDocumentPosition(candidate) & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
55
|
+
closestBefore = candidate; // querySelectorAll returns document order, so the last match wins
|
|
56
|
+
}
|
|
57
|
+
else if (!closestAfter) {
|
|
58
|
+
closestAfter = candidate; // first match after `el` in document order
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return closestBefore ?? closestAfter;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=focus-fallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus-fallback.js","sourceRoot":"","sources":["../../../src/utils/focus-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CAAC,EAAe;IACvD,IAAI,OAAO,GAAuB,EAAE,CAAC,aAAa,CAAC;IACnD,OAAO,OAAO,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAI,GAAG,KAAK,IAAI,IAAI,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC;YAAE,OAAO,OAAO,CAAC;QAC3D,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;qFACqF;AACrF,MAAM,mBAAmB,GAAG;IAC1B,SAAS;IACT,wBAAwB;IACxB,4CAA4C;IAC5C,wBAAwB;IACxB,0BAA0B;IAC1B,iCAAiC;IACjC,2BAA2B;CAC5B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0BAA0B,CAAC,EAAe;IACxD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAc,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAC/F,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC3D,CAAC;IACF,IAAI,CAAC,UAAU,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEpC,IAAI,aAAa,GAAuB,IAAI,CAAC;IAC7C,IAAI,YAAY,GAAuB,IAAI,CAAC;IAC5C,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC/B,sCAAsC;QACtC,IAAI,EAAE,CAAC,uBAAuB,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,2BAA2B,EAAE,CAAC;YAC7E,aAAa,GAAG,SAAS,CAAC,CAAC,kEAAkE;QAC/F,CAAC;aAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YACzB,YAAY,GAAG,SAAS,CAAC,CAAC,2CAA2C;QACvE,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,IAAI,YAAY,CAAC;AACvC,CAAC","sourcesContent":["/**\n * Returns the nearest focusable ancestor of `el` by walking up parentElement.\n * Used as the last-resort fallback when a self-removing component (chip, alert)\n * has no adjacent sibling of the same type to shift focus to.\n *\n * \"Focusable ancestor\" means an element with tabindex >= 0. The container that\n * wraps a chip group or alert list is the expected target; authors following the\n * WAI-ARIA pattern should give it tabindex=\"0\".\n */\nexport function focusableFallbackAncestor(el: HTMLElement): HTMLElement | null {\n let current: HTMLElement | null = el.parentElement;\n while (current) {\n const tab = current.getAttribute('tabindex');\n if (tab !== null && parseInt(tab, 10) >= 0) return current;\n current = current.parentElement;\n }\n return null;\n}\n\n/** Mirrors FocusTrapController's notion of \"focusable\", scoped to the handful of\n * interactive elements consumers actually place next to alert/chip/notification. */\nconst FOCUSABLE_SELECTORS = [\n 'a[href]',\n 'button:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n '[tabindex]:not([tabindex=\"-1\"])',\n 'it-button:not([disabled])',\n].join(',');\n\n/**\n * True last-resort fallback for when a self-removing component (alert, chip,\n * notification) has neither an adjacent sibling of the same type nor a\n * `focusableFallbackAncestor` (i.e. no author-provided `tabindex=\"0\"` wrapper) —\n * the common case in practice, since most real usages don't add that wrapper.\n * Without this, focus silently drops to `<body>` with no way for a keyboard/AT\n * user to tell where they ended up.\n *\n * Finds the closest focusable element to `el` anywhere in the document, walking\n * outward in document order: the nearest one that comes before `el` (closer to\n * where the user's attention already was), falling back to the nearest one after.\n * This is a coarse, page-wide search — it may land focus on something not\n * visually adjacent — but it is deterministic and strictly better than silently\n * losing focus.\n */\nexport function nearestFocusableInDocument(el: HTMLElement): HTMLElement | null {\n const candidates = Array.from(document.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTORS)).filter(\n (candidate) => candidate !== el && !el.contains(candidate),\n );\n if (!candidates.length) return null;\n\n let closestBefore: HTMLElement | null = null;\n let closestAfter: HTMLElement | null = null;\n candidates.forEach((candidate) => {\n // eslint-disable-next-line no-bitwise\n if (el.compareDocumentPosition(candidate) & Node.DOCUMENT_POSITION_PRECEDING) {\n closestBefore = candidate; // querySelectorAll returns document order, so the last match wins\n } else if (!closestAfter) {\n closestAfter = candidate; // first match after `el` in document order\n }\n });\n return closestBefore ?? closestAfter;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@italia/globals",
|
|
3
3
|
"description": "Utilities per i Web components del Design System .italia",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.19",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@floating-ui/dom": "^1.7.1",
|
|
36
36
|
"clsx": "^2.1.1",
|
|
37
37
|
"lit": "^3.3.0",
|
|
38
|
-
"@italia/i18n": "^1.0.0-alpha.
|
|
38
|
+
"@italia/i18n": "^1.0.0-alpha.19"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|