@italia/globals 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/AUTHORS +3 -0
  2. package/LICENSE +11 -0
  3. package/README.md +129 -0
  4. package/custom-elements.json +566 -0
  5. package/dist/src/base-component/base-component.d.ts +373 -0
  6. package/dist/src/base-component/base-component.d.ts.map +1 -0
  7. package/dist/src/base-component/base-component.js +48 -0
  8. package/dist/src/base-component/base-component.js.map +1 -0
  9. package/dist/src/directives/setAttributes.d.ts +8 -0
  10. package/dist/src/directives/setAttributes.d.ts.map +1 -0
  11. package/dist/src/directives/setAttributes.js +24 -0
  12. package/dist/src/directives/setAttributes.js.map +1 -0
  13. package/dist/src/index.d.ts +10 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +9 -0
  16. package/dist/src/index.js.map +1 -0
  17. package/dist/src/mixins/form.d.ts +363 -0
  18. package/dist/src/mixins/form.d.ts.map +1 -0
  19. package/dist/src/mixins/form.js +36 -0
  20. package/dist/src/mixins/form.js.map +1 -0
  21. package/dist/src/mixins/validity.d.ts +414 -0
  22. package/dist/src/mixins/validity.d.ts.map +1 -0
  23. package/dist/src/mixins/validity.js +90 -0
  24. package/dist/src/mixins/validity.js.map +1 -0
  25. package/dist/src/utils/cookies.d.ts +14 -0
  26. package/dist/src/utils/cookies.d.ts.map +1 -0
  27. package/dist/src/utils/cookies.js +31 -0
  28. package/dist/src/utils/cookies.js.map +1 -0
  29. package/dist/src/utils/logger.d.ts +9 -0
  30. package/dist/src/utils/logger.d.ts.map +1 -0
  31. package/dist/src/utils/logger.js +19 -0
  32. package/dist/src/utils/logger.js.map +1 -0
  33. package/dist/src/utils/track-focus.d.ts +15 -0
  34. package/dist/src/utils/track-focus.d.ts.map +1 -0
  35. package/dist/src/utils/track-focus.js +41 -0
  36. package/dist/src/utils/track-focus.js.map +1 -0
  37. package/package.json +58 -0
package/AUTHORS ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2022 - 2025 Presidenza del Consiglio dei Ministri
2
+
3
+ The version control system provides attribution for specific lines of code.
package/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2025, the respective contributors, as shown by the AUTHORS file.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # Globals
2
+
3
+ This package contains extendable BaseComponent and BaseLocalizedComponent, utils and mixins, reusable in all web-components packages.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i globals
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@italia/globals';
16
+ </script>
17
+ ```
18
+
19
+ ### BaseComponent
20
+
21
+ Base web-component
22
+
23
+ Example:
24
+
25
+ ```js
26
+ import { BaseComponent } from '@italia/globals';
27
+
28
+ @customElement('my-element')
29
+ export class MyElement extends BaseComponent {
30
+ render() {
31
+ return html`<div>Your html</div>`;
32
+ }
33
+ }
34
+ ```
35
+
36
+ ### BaseLocalizedComponent
37
+
38
+ Base localized component, to be used when you need translations in your component.
39
+
40
+ ```js
41
+ import { registerTranslation } from '@italia/i18n';
42
+ import { BaseLocalizedComponent } from '@italia/globals';
43
+ import en from '../translations/en';
44
+ import es from '../translations/es';
45
+
46
+ registerTranslation(en, es);
47
+
48
+ @customElement('my-element')
49
+ export class MyElement extends BaseLocalizedComponent {
50
+ render() {
51
+ return html` <div>
52
+ <h2>Lang</h2>
53
+ ${this.$localize.lang()}
54
+ </div>
55
+ <div>
56
+ <h2>Direction</h2>
57
+ ${this.$localize.dir()}
58
+ </div>
59
+ <div>
60
+ <h2>Translate string</h2>
61
+ ${this.$t('hello_world')}
62
+ </div>
63
+ <div>
64
+ <h2>Date</h2>
65
+ ${this.$d('2021-09-15 14:00:00 ET', { year: 'numeric', month: 'long', day: 'numeric' })}
66
+ </div>
67
+ <div>
68
+ <h2>Number</h2>
69
+ ${this.$n(1234.56, { style: 'currency', currency: 'USD' })}
70
+ </div>`;
71
+ }
72
+ }
73
+ ```
74
+
75
+ ## Linting and formatting
76
+
77
+ To scan the project for linting and formatting errors, run
78
+
79
+ ```bash
80
+ npm run lint
81
+ ```
82
+
83
+ To automatically fix linting and formatting errors, run
84
+
85
+ ```bash
86
+ npm run format
87
+ ```
88
+
89
+ ## Testing with Web Test Runner
90
+
91
+ To execute a single test run:
92
+
93
+ ```bash
94
+ npm run test
95
+ ```
96
+
97
+ To run the tests in interactive watch mode run:
98
+
99
+ ```bash
100
+ npm run test:watch
101
+ ```
102
+
103
+ ## Demoing with Storybook
104
+
105
+ To run a local instance of Storybook for your component, run
106
+
107
+ ```bash
108
+ npm run storybook
109
+ ```
110
+
111
+ To build a production version of Storybook, run
112
+
113
+ ```bash
114
+ npm run storybook:build
115
+ ```
116
+
117
+ ## Tooling configs
118
+
119
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
120
+
121
+ If you customize the configuration a lot, you can consider moving them to individual files.
122
+
123
+ ## Local Demo with `web-dev-server`
124
+
125
+ ```bash
126
+ npm start
127
+ ```
128
+
129
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,566 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/index.ts",
8
+ "declarations": [],
9
+ "exports": [
10
+ {
11
+ "kind": "js",
12
+ "name": "TrackFocus",
13
+ "declaration": {
14
+ "name": "TrackFocus",
15
+ "module": "src/index.ts"
16
+ }
17
+ },
18
+ {
19
+ "kind": "js",
20
+ "name": "FormMixin",
21
+ "declaration": {
22
+ "name": "FormMixin",
23
+ "module": "src/index.ts"
24
+ }
25
+ },
26
+ {
27
+ "kind": "js",
28
+ "name": "ValidityMixin",
29
+ "declaration": {
30
+ "name": "ValidityMixin",
31
+ "module": "src/index.ts"
32
+ }
33
+ },
34
+ {
35
+ "kind": "js",
36
+ "name": "setAttributes",
37
+ "declaration": {
38
+ "name": "setAttributes",
39
+ "module": "src/index.ts"
40
+ }
41
+ },
42
+ {
43
+ "kind": "js",
44
+ "name": "BaseComponent",
45
+ "declaration": {
46
+ "name": "BaseComponent",
47
+ "module": "./base-component/base-component.js"
48
+ }
49
+ },
50
+ {
51
+ "kind": "js",
52
+ "name": "BaseComponentInterface",
53
+ "declaration": {
54
+ "name": "BaseComponentInterface",
55
+ "module": "./base-component/base-component.js"
56
+ }
57
+ },
58
+ {
59
+ "kind": "js",
60
+ "name": "BaseComponentType",
61
+ "declaration": {
62
+ "name": "BaseComponentType",
63
+ "module": "./base-component/base-component.js"
64
+ }
65
+ },
66
+ {
67
+ "kind": "js",
68
+ "name": "BaseLocalizedComponent",
69
+ "declaration": {
70
+ "name": "BaseLocalizedComponent",
71
+ "module": "./base-component/base-component.js"
72
+ }
73
+ },
74
+ {
75
+ "kind": "js",
76
+ "name": "VALIDATION_STATUS",
77
+ "declaration": {
78
+ "name": "VALIDATION_STATUS",
79
+ "module": "./mixins/validity.js"
80
+ }
81
+ },
82
+ {
83
+ "kind": "js",
84
+ "name": "cookies",
85
+ "declaration": {
86
+ "name": "cookies",
87
+ "module": "./utils/cookies.js"
88
+ }
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ "kind": "javascript-module",
94
+ "path": "src/base-component/base-component.ts",
95
+ "declarations": [
96
+ {
97
+ "kind": "class",
98
+ "description": "Factory function per creare una base class estendibile\ncon stili personalizzati.",
99
+ "name": "BaseComponent",
100
+ "members": [
101
+ {
102
+ "kind": "field",
103
+ "name": "logger",
104
+ "type": {
105
+ "text": "Logger"
106
+ },
107
+ "privacy": "protected",
108
+ "default": "new Logger(this.tagName.toLowerCase())"
109
+ },
110
+ {
111
+ "kind": "field",
112
+ "name": "_ariaAttributes",
113
+ "type": {
114
+ "text": "Record<string, string>"
115
+ },
116
+ "privacy": "protected",
117
+ "default": "{}"
118
+ },
119
+ {
120
+ "kind": "field",
121
+ "name": "_id",
122
+ "type": {
123
+ "text": "string | undefined"
124
+ },
125
+ "privacy": "protected"
126
+ },
127
+ {
128
+ "kind": "method",
129
+ "name": "generateId",
130
+ "parameters": [
131
+ {
132
+ "name": "prefix",
133
+ "type": {
134
+ "text": "string"
135
+ }
136
+ }
137
+ ]
138
+ },
139
+ {
140
+ "kind": "method",
141
+ "name": "addFocus",
142
+ "parameters": [
143
+ {
144
+ "name": "element",
145
+ "type": {
146
+ "text": "HTMLElement"
147
+ }
148
+ }
149
+ ]
150
+ },
151
+ {
152
+ "kind": "method",
153
+ "name": "composeClass",
154
+ "parameters": [
155
+ {
156
+ "name": "classes",
157
+ "type": {
158
+ "text": "any"
159
+ }
160
+ }
161
+ ]
162
+ },
163
+ {
164
+ "kind": "method",
165
+ "name": "getAriaAttributes"
166
+ }
167
+ ],
168
+ "superclass": {
169
+ "name": "LitElement",
170
+ "package": "lit"
171
+ },
172
+ "customElement": true
173
+ },
174
+ {
175
+ "kind": "variable",
176
+ "name": "BaseLocalizedComponent"
177
+ }
178
+ ],
179
+ "exports": [
180
+ {
181
+ "kind": "js",
182
+ "name": "BaseComponent",
183
+ "declaration": {
184
+ "name": "BaseComponent",
185
+ "module": "src/base-component/base-component.ts"
186
+ }
187
+ },
188
+ {
189
+ "kind": "js",
190
+ "name": "BaseLocalizedComponent",
191
+ "declaration": {
192
+ "name": "BaseLocalizedComponent",
193
+ "module": "src/base-component/base-component.ts"
194
+ }
195
+ }
196
+ ]
197
+ },
198
+ {
199
+ "kind": "javascript-module",
200
+ "path": "src/directives/setAttributes.ts",
201
+ "declarations": [
202
+ {
203
+ "kind": "variable",
204
+ "name": "setAttributes"
205
+ }
206
+ ],
207
+ "exports": [
208
+ {
209
+ "kind": "js",
210
+ "name": "default",
211
+ "declaration": {
212
+ "name": "setAttributes",
213
+ "module": "src/directives/setAttributes.ts"
214
+ }
215
+ }
216
+ ]
217
+ },
218
+ {
219
+ "kind": "javascript-module",
220
+ "path": "src/mixins/form.ts",
221
+ "declarations": [
222
+ {
223
+ "kind": "mixin",
224
+ "description": "",
225
+ "name": "FormMixin",
226
+ "members": [
227
+ {
228
+ "kind": "method",
229
+ "name": "_handleFormdata",
230
+ "return": {
231
+ "type": {
232
+ "text": "void"
233
+ }
234
+ },
235
+ "parameters": [
236
+ {
237
+ "name": "event",
238
+ "type": {
239
+ "text": "Event"
240
+ },
241
+ "description": "The event."
242
+ }
243
+ ],
244
+ "description": "Handles `formdata` event."
245
+ }
246
+ ],
247
+ "parameters": [
248
+ {
249
+ "name": "Base",
250
+ "type": {
251
+ "text": "TBase"
252
+ },
253
+ "description": "The base class."
254
+ }
255
+ ]
256
+ }
257
+ ],
258
+ "exports": [
259
+ {
260
+ "kind": "js",
261
+ "name": "default",
262
+ "declaration": {
263
+ "name": "FormMixin",
264
+ "module": "src/mixins/form.ts"
265
+ }
266
+ }
267
+ ]
268
+ },
269
+ {
270
+ "kind": "javascript-module",
271
+ "path": "src/mixins/validity.ts",
272
+ "declarations": [
273
+ {
274
+ "kind": "mixin",
275
+ "description": "",
276
+ "name": "ValidityMixin",
277
+ "members": [
278
+ {
279
+ "kind": "method",
280
+ "name": "_getValidityMessage",
281
+ "parameters": [
282
+ {
283
+ "name": "state",
284
+ "type": {
285
+ "text": "string"
286
+ },
287
+ "description": "The form validation status."
288
+ }
289
+ ],
290
+ "return": {
291
+ "type": {
292
+ "text": ""
293
+ }
294
+ },
295
+ "privacy": "protected"
296
+ },
297
+ {
298
+ "kind": "method",
299
+ "name": "_testValidity",
300
+ "return": {
301
+ "type": {
302
+ "text": ""
303
+ }
304
+ },
305
+ "description": "Checks if the value meets the constraints.",
306
+ "privacy": "protected"
307
+ },
308
+ {
309
+ "kind": "field",
310
+ "name": "invalid",
311
+ "type": {
312
+ "text": "boolean"
313
+ },
314
+ "description": "`true` to show the UI of the invalid state."
315
+ },
316
+ {
317
+ "kind": "field",
318
+ "name": "required",
319
+ "type": {
320
+ "text": "boolean"
321
+ },
322
+ "description": "`true` if the value is required."
323
+ },
324
+ {
325
+ "kind": "field",
326
+ "name": "requiredValidityMessage",
327
+ "type": {
328
+ "text": "string"
329
+ },
330
+ "description": "The special validity message for `required`."
331
+ },
332
+ {
333
+ "kind": "field",
334
+ "name": "validityMessage",
335
+ "type": {
336
+ "text": "string"
337
+ },
338
+ "description": "The validity message."
339
+ },
340
+ {
341
+ "kind": "field",
342
+ "name": "value",
343
+ "type": {
344
+ "text": "string"
345
+ },
346
+ "description": "The value."
347
+ },
348
+ {
349
+ "kind": "method",
350
+ "name": "checkValidity",
351
+ "description": "Checks if the value meets the constraints.\nFires cancelable `invalid` event if it doesn't.",
352
+ "return": {
353
+ "type": {
354
+ "text": ""
355
+ }
356
+ }
357
+ },
358
+ {
359
+ "kind": "method",
360
+ "name": "setCustomValidity",
361
+ "parameters": [
362
+ {
363
+ "name": "validityMessage",
364
+ "type": {
365
+ "text": "string"
366
+ },
367
+ "description": "The custom validity message"
368
+ }
369
+ ],
370
+ "description": "Sets the given custom validity message."
371
+ }
372
+ ],
373
+ "events": [
374
+ {
375
+ "name": "invalid",
376
+ "type": {
377
+ "text": "CustomEvent"
378
+ }
379
+ }
380
+ ],
381
+ "parameters": [
382
+ {
383
+ "name": "Base",
384
+ "type": {
385
+ "text": "T"
386
+ },
387
+ "description": "The base class."
388
+ }
389
+ ]
390
+ }
391
+ ],
392
+ "exports": [
393
+ {
394
+ "kind": "js",
395
+ "name": "default",
396
+ "declaration": {
397
+ "name": "ValidityMixin",
398
+ "module": "src/mixins/validity.ts"
399
+ }
400
+ }
401
+ ]
402
+ },
403
+ {
404
+ "kind": "javascript-module",
405
+ "path": "src/utils/cookies.ts",
406
+ "declarations": [
407
+ {
408
+ "kind": "variable",
409
+ "name": "cookies",
410
+ "type": {
411
+ "text": "object"
412
+ },
413
+ "default": "{ rememberChoice, isChoiceRemembered, clearAllRememberedChoices, }"
414
+ }
415
+ ],
416
+ "exports": [
417
+ {
418
+ "kind": "js",
419
+ "name": "cookies",
420
+ "declaration": {
421
+ "name": "cookies",
422
+ "module": "src/utils/cookies.ts"
423
+ }
424
+ }
425
+ ]
426
+ },
427
+ {
428
+ "kind": "javascript-module",
429
+ "path": "src/utils/logger.ts",
430
+ "declarations": [
431
+ {
432
+ "kind": "class",
433
+ "description": "",
434
+ "name": "Logger",
435
+ "members": [
436
+ {
437
+ "kind": "field",
438
+ "name": "tag",
439
+ "type": {
440
+ "text": "string"
441
+ },
442
+ "privacy": "private",
443
+ "readonly": true,
444
+ "default": "tag"
445
+ },
446
+ {
447
+ "kind": "method",
448
+ "name": "format",
449
+ "privacy": "private",
450
+ "return": {
451
+ "type": {
452
+ "text": "[string, ...any[]]"
453
+ }
454
+ },
455
+ "parameters": [
456
+ {
457
+ "name": "level",
458
+ "type": {
459
+ "text": "string"
460
+ }
461
+ },
462
+ {
463
+ "name": "msg",
464
+ "type": {
465
+ "text": "string"
466
+ }
467
+ }
468
+ ]
469
+ },
470
+ {
471
+ "kind": "method",
472
+ "name": "warn",
473
+ "parameters": [
474
+ {
475
+ "name": "msg",
476
+ "type": {
477
+ "text": "string"
478
+ }
479
+ }
480
+ ]
481
+ },
482
+ {
483
+ "kind": "method",
484
+ "name": "error",
485
+ "parameters": [
486
+ {
487
+ "name": "msg",
488
+ "type": {
489
+ "text": "string"
490
+ }
491
+ }
492
+ ]
493
+ },
494
+ {
495
+ "kind": "method",
496
+ "name": "info",
497
+ "parameters": [
498
+ {
499
+ "name": "msg",
500
+ "type": {
501
+ "text": "string"
502
+ }
503
+ }
504
+ ]
505
+ }
506
+ ]
507
+ }
508
+ ],
509
+ "exports": [
510
+ {
511
+ "kind": "js",
512
+ "name": "Logger",
513
+ "declaration": {
514
+ "name": "Logger",
515
+ "module": "src/utils/logger.ts"
516
+ }
517
+ }
518
+ ]
519
+ },
520
+ {
521
+ "kind": "javascript-module",
522
+ "path": "src/utils/track-focus.ts",
523
+ "declarations": [
524
+ {
525
+ "kind": "class",
526
+ "description": "",
527
+ "name": "TrackFocus",
528
+ "members": [
529
+ {
530
+ "kind": "field",
531
+ "name": "_usingMouse",
532
+ "type": {
533
+ "text": "boolean"
534
+ },
535
+ "privacy": "private",
536
+ "default": "false"
537
+ },
538
+ {
539
+ "kind": "field",
540
+ "name": "_element",
541
+ "type": {
542
+ "text": "HTMLElement"
543
+ },
544
+ "privacy": "private",
545
+ "default": "element"
546
+ },
547
+ {
548
+ "kind": "method",
549
+ "name": "_bindEvents"
550
+ }
551
+ ]
552
+ }
553
+ ],
554
+ "exports": [
555
+ {
556
+ "kind": "js",
557
+ "name": "default",
558
+ "declaration": {
559
+ "name": "TrackFocus",
560
+ "module": "src/utils/track-focus.ts"
561
+ }
562
+ }
563
+ ]
564
+ }
565
+ ]
566
+ }