mypgs 1.5.1 → 2.0.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.
- package/AGENTS.md +8 -5
- package/README.md +1 -1
- package/assets/javascript/_imports.js +4 -0
- package/assets/javascript/_pgs.js +58 -0
- package/assets/javascript/base/_darkmode.js +27 -105
- package/assets/javascript/base/_svg.js +103 -0
- package/assets/javascript/components/_accordion.js +2 -2
- package/assets/javascript/components/_menu.js +1 -3
- package/assets/javascript/components/_modals.js +159 -136
- package/assets/javascript/components/_notifications.js +19 -9
- package/assets/javascript/components/_search.js +391 -0
- package/assets/javascript/components/_slides.js +66 -32
- package/assets/javascript/components/_stepTabs.js +4 -4
- package/assets/javascript/components/_steps.js +2 -2
- package/assets/javascript/components/_summary.js +2 -2
- package/assets/javascript/functions/_formValidate.js +97 -53
- package/assets/javascript/functions/_scrollY.js +10 -10
- package/assets/javascript/index.js +2 -0
- package/assets/javascript/layout/_header.js +29 -7
- package/assets/scss/base/_color.scss +5 -5
- package/assets/scss/base/_html.scss +2 -2
- package/assets/scss/base/_variables.scss +4 -2
- package/assets/scss/components/_dropdown.scss +2 -1
- package/assets/scss/components/_form.scss +2 -2
- package/assets/scss/components/_logo.scss +2 -2
- package/assets/scss/components/_menu.scss +20 -27
- package/assets/scss/components/_modals.scss +11 -1
- package/assets/scss/components/_notification.scss +23 -30
- package/assets/scss/components/_search.scss +140 -0
- package/assets/scss/index.scss +2 -2
- package/assets/scss/layout/_header.scss +1 -1
- package/assets/scss/layout/_pageShell.scss +19 -15
- package/assets/scss/mixin/_mx-form.scss +7 -7
- package/{templates/html → demo}/demo.html +1 -1
- package/demo/demo.js +240 -0
- package/dist/css/index.css +188 -125
- package/dist/css/index.css.map +1 -1
- package/dist/css/index.min.css +1 -1
- package/dist/index.d.ts +70 -0
- package/dist/javascript/index.js +1038 -405
- package/dist/javascript/index.js.map +1 -1
- package/dist/javascript/index.min.js +1 -1
- package/docs/componenti-e-markup.md +62 -27
- package/docs/components/accordion.md +61 -0
- package/docs/components/badges.md +67 -0
- package/docs/components/breadcumbs.md +43 -0
- package/docs/components/button.md +59 -0
- package/docs/components/card.md +50 -0
- package/docs/components/dropdown.md +135 -0
- package/docs/components/form.md +113 -0
- package/docs/components/logo.md +36 -0
- package/docs/components/menu.md +90 -0
- package/docs/components/modal.md +131 -0
- package/docs/components/notification.md +81 -0
- package/docs/components/search.md +117 -0
- package/docs/components/slides.md +85 -0
- package/docs/components/stepTabs.md +93 -0
- package/docs/components/steps.md +56 -0
- package/docs/components/summary.md +49 -0
- package/docs/components/table.md +42 -0
- package/docs/components/tooltip.md +53 -0
- package/docs/helper-javascript.md +71 -3
- package/docs/layout/body.md +41 -0
- package/docs/layout/flex.md +116 -0
- package/docs/layout/footer.md +71 -0
- package/docs/layout/grid.md +116 -0
- package/docs/layout/header.md +116 -0
- package/docs/layout/pageShell.md +94 -0
- package/docs/layout/section.md +69 -0
- package/docs/patterns/cookieConsent.md +89 -0
- package/package.json +2 -1
- package/scripts/generate-component-docs.js +557 -0
- package/templates/html/components/accordion.html +33 -4
- package/templates/html/components/badges.html +23 -0
- package/templates/html/components/breadcumbs.html +14 -0
- package/templates/html/components/button.html +22 -0
- package/templates/html/components/card.html +20 -0
- package/templates/html/components/dropdown.html +34 -0
- package/templates/html/components/form.html +82 -4
- package/templates/html/components/logo.html +22 -1
- package/templates/html/components/menu.html +40 -1
- package/templates/html/components/modal.html +44 -0
- package/templates/html/components/notification.html +68 -32
- package/templates/html/components/search.html +107 -0
- package/templates/html/components/slides.html +43 -0
- package/templates/html/components/stepTabs.html +47 -0
- package/templates/html/components/steps.html +24 -0
- package/templates/html/components/summary.html +27 -0
- package/templates/html/components/table.html +12 -0
- package/templates/html/components/tooltip.html +35 -0
- package/templates/html/layout/body.html +20 -5
- package/templates/html/layout/flex.html +20 -0
- package/templates/html/layout/footer.html +29 -1
- package/templates/html/layout/grid.html +20 -0
- package/templates/html/layout/header.html +52 -5
- package/templates/html/layout/pageShell.html +19 -0
- package/templates/html/layout/section.html +32 -10
- package/templates/html/patterns/cookieConsent.html +31 -0
- package/templates/react/components/form.jsx +3 -3
- package/templates/react/components/logo.jsx +1 -1
- package/templates/react/components/notification.jsx +4 -4
- package/templates/react/components/{searchbar.jsx → search.jsx} +9 -7
- package/templates/react/patterns/footer.jsx +1 -1
- package/templates/react/patterns/header.jsx +16 -10
- package/assets/scss/components/_searchbar.scss +0 -70
- package/templates/html/components/searchbar.html +0 -29
- package/templates/html/demo.js +0 -137
- /package/{templates/html → demo}/demo.css +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
@use "../mixin/mixin" as *;
|
|
2
|
+
|
|
3
|
+
[pgs~="search"] {
|
|
4
|
+
--search-suggestions-background: var(--color-box);
|
|
5
|
+
--search-suggestions-color: var(--color-text);
|
|
6
|
+
--search-suggestions-border: var(--border-complete);
|
|
7
|
+
--search-suggestions-borderRadius: var(--border-radius-input);
|
|
8
|
+
--search-suggestions-boxShadow: var(--box-shadow);
|
|
9
|
+
--search-suggestions-gap: 0;
|
|
10
|
+
--search-suggestions-maxHeight: 32rem;
|
|
11
|
+
--search-suggestions-offset: .5rem;
|
|
12
|
+
--search-suggestions-padding: .5rem;
|
|
13
|
+
--search-suggestions-item-padding: 1rem;
|
|
14
|
+
--search-suggestions-item-selected-background: var(--color-primary);
|
|
15
|
+
--search-suggestions-item-selected-color: var(--color-whiteFixed);
|
|
16
|
+
position: relative;
|
|
17
|
+
@include flexRow(nowrap);
|
|
18
|
+
@include button_header();
|
|
19
|
+
flex: 1;
|
|
20
|
+
width: 100%;
|
|
21
|
+
overflow: visible;
|
|
22
|
+
margin-inline: auto;
|
|
23
|
+
padding: 0;
|
|
24
|
+
|
|
25
|
+
@media (min-width: $mobile) {
|
|
26
|
+
min-width: 21.4rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
button {
|
|
30
|
+
height: 100%;
|
|
31
|
+
padding-left: var(--button-size);
|
|
32
|
+
border: none;
|
|
33
|
+
border-radius: var(--border-radius-input);
|
|
34
|
+
outline: none;
|
|
35
|
+
background: none;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
input {
|
|
40
|
+
width: 100%;
|
|
41
|
+
min-width: 21.4rem;
|
|
42
|
+
height: 100%;
|
|
43
|
+
padding: var(--button-size);
|
|
44
|
+
padding-left: 0;
|
|
45
|
+
margin: 2px;
|
|
46
|
+
margin-left: 0;
|
|
47
|
+
border: 0;
|
|
48
|
+
border-radius: var(--border-radius-input);
|
|
49
|
+
background-color: transparent;
|
|
50
|
+
color: contrast-color(color-mix(in srgb, var(--button-background) 77%, black));
|
|
51
|
+
font-family: var(--font);
|
|
52
|
+
font-size: 1.6rem;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
cursor: text !important;
|
|
55
|
+
|
|
56
|
+
&::placeholder {
|
|
57
|
+
color: contrast-color(color-mix(in srgb, var(--button-background) 77%, black));
|
|
58
|
+
opacity: .6;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&:focus-visible {
|
|
62
|
+
outline: unset;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&:has(input:focus-visible) {
|
|
67
|
+
outline: var(--focus-visible);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@mixin _color($varColor) {
|
|
71
|
+
background: var(#{$varColor}-background);
|
|
72
|
+
color: var(#{$varColor}-color);
|
|
73
|
+
|
|
74
|
+
i {
|
|
75
|
+
color: var(#{$varColor}-color);
|
|
76
|
+
--fa-primary-color: var(#{$varColor}-color);
|
|
77
|
+
--fa-secondary-color: var(#{$varColor}-color);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[pgs~="search-suggestions"] {
|
|
82
|
+
display: none;
|
|
83
|
+
position: absolute;
|
|
84
|
+
inset: calc(100% + var(--search-suggestions-offset)) 0 auto;
|
|
85
|
+
z-index: 1000;
|
|
86
|
+
flex-direction: column;
|
|
87
|
+
gap: var(--search-suggestions-gap);
|
|
88
|
+
max-height: var(--search-suggestions-maxHeight);
|
|
89
|
+
overflow-y: auto;
|
|
90
|
+
padding: var(--search-suggestions-padding);
|
|
91
|
+
margin: 0;
|
|
92
|
+
list-style: none;
|
|
93
|
+
border: var(--search-suggestions-border);
|
|
94
|
+
border-radius: calc(var(--search-suggestions-borderRadius) + var(--search-suggestions-padding));
|
|
95
|
+
box-shadow: var(--search-suggestions-boxShadow);
|
|
96
|
+
@include _color(--search-suggestions);
|
|
97
|
+
|
|
98
|
+
[pgs~="search-suggestions-item"] {
|
|
99
|
+
padding: var(--search-suggestions-item-padding);
|
|
100
|
+
border-radius: var(--search-suggestions-borderRadius);
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
flex-wrap: nowrap;
|
|
103
|
+
|
|
104
|
+
&[aria-selected="true"],
|
|
105
|
+
&:hover {
|
|
106
|
+
@include _color(--search-suggestions-item-selected);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&[aria-disabled="true"] {
|
|
110
|
+
cursor: not-allowed;
|
|
111
|
+
opacity: .5;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&:has([pgs~="search-suggestions-item"]:hover) {
|
|
116
|
+
[pgs~="search-suggestions-item"][aria-selected="true"] {
|
|
117
|
+
@include _color(--search-suggestions);
|
|
118
|
+
|
|
119
|
+
&:hover {
|
|
120
|
+
@include _color(--search-suggestions-item-selected);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
&[pgs-state~="open"] [pgs~="search-suggestions"] {
|
|
127
|
+
display: flex;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@at-root dialog #{&} {
|
|
131
|
+
max-width: calc(100% - var(--padding-page) * 2);
|
|
132
|
+
height: max-content;
|
|
133
|
+
margin-inline: auto;
|
|
134
|
+
background-color: var(--color-white);
|
|
135
|
+
|
|
136
|
+
input {
|
|
137
|
+
padding-block: 20px;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
package/assets/scss/index.scss
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
@include meta.load-css("components/badges");
|
|
53
53
|
@include meta.load-css("components/notification");
|
|
54
54
|
@include meta.load-css("components/tooltip");
|
|
55
|
-
@include meta.load-css("components/
|
|
55
|
+
@include meta.load-css("components/search");
|
|
56
56
|
@include meta.load-css("components/logo");
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -63,4 +63,4 @@
|
|
|
63
63
|
*/
|
|
64
64
|
[pgs~=initP] {
|
|
65
65
|
@include meta.load-css("patterns/cookieConsent");
|
|
66
|
-
}
|
|
66
|
+
}
|
|
@@ -18,9 +18,12 @@ $pageShell-test-gap: 4rem;
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
[pgs~="pageShell"] {
|
|
21
|
-
--pageShell-
|
|
21
|
+
--pageShell-width: calc(var(--pageShell-content-width) + (var(--padding-page) * 2));
|
|
22
|
+
--pageShell-content-width: var(--page-width);
|
|
22
23
|
--pageShell-aside-width: #{$aside-size};
|
|
23
|
-
--pageShell-
|
|
24
|
+
--pageShell-aside-sticky-top: 0;
|
|
25
|
+
--pageShell-paddingInline: var(--padding-page);
|
|
26
|
+
--pageShell-paddingTop: var(--page-top);
|
|
24
27
|
--pageShell-gap: var(--gap-elements);
|
|
25
28
|
display: flex;
|
|
26
29
|
flex-wrap: wrap;
|
|
@@ -29,17 +32,17 @@ $pageShell-test-gap: 4rem;
|
|
|
29
32
|
align-items: start;
|
|
30
33
|
justify-content: center;
|
|
31
34
|
width: 100%;
|
|
32
|
-
max-width:
|
|
33
|
-
padding-inline: var(--
|
|
35
|
+
max-width: var(--pageShell-width);
|
|
36
|
+
padding-inline: var(--pageShell-paddingInline);
|
|
34
37
|
container-type: inline-size;
|
|
35
38
|
|
|
36
39
|
[pgs~="pageShell-content"] {
|
|
37
40
|
grid-area: content;
|
|
38
|
-
flex: 999 1
|
|
39
|
-
min-width: min(100%,
|
|
40
|
-
width: min(100%, var(--
|
|
41
|
-
max-width: var(--
|
|
42
|
-
padding-top: var(--
|
|
41
|
+
flex: 999 1 $content-size;
|
|
42
|
+
min-width: min(100%, $content-size);
|
|
43
|
+
width: min(100%, var(--pageShell-content-width));
|
|
44
|
+
max-width: var(--pageShell-content-width);
|
|
45
|
+
padding-top: var(--pageShell-paddingTop);
|
|
43
46
|
padding-bottom: var(--gap-elements);
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -49,13 +52,14 @@ $pageShell-test-gap: 4rem;
|
|
|
49
52
|
isolation: isolate;
|
|
50
53
|
position: sticky;
|
|
51
54
|
top: var(--pageShell-aside-sticky-top);
|
|
55
|
+
transition: top 0.3s ease;
|
|
52
56
|
width: 100%;
|
|
53
57
|
max-height: 100svh;
|
|
54
58
|
overflow-y: auto;
|
|
55
59
|
overscroll-behavior: contain;
|
|
56
60
|
scrollbar-gutter: stable;
|
|
57
61
|
scrollbar-width: none;
|
|
58
|
-
padding-top: var(--
|
|
62
|
+
padding-top: var(--pageShell-paddingTop);
|
|
59
63
|
padding-bottom: var(--gap-elements);
|
|
60
64
|
flex: 1 1 var(--pageShell-aside-width);
|
|
61
65
|
min-width: min(100%, var(--pageShell-aside-width));
|
|
@@ -81,7 +85,7 @@ $pageShell-test-gap: 4rem;
|
|
|
81
85
|
overscroll-behavior: contain;
|
|
82
86
|
scrollbar-gutter: stable;
|
|
83
87
|
scrollbar-width: none;
|
|
84
|
-
padding-top: var(--
|
|
88
|
+
padding-top: var(--pageShell-paddingTop);
|
|
85
89
|
padding-bottom: calc(var(--gap-elements)*2);
|
|
86
90
|
|
|
87
91
|
&::-webkit-scrollbar {
|
|
@@ -115,11 +119,11 @@ $pageShell-test-gap: 4rem;
|
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
&:has(> [pgs~="pageShell-aside"]) {
|
|
118
|
-
|
|
122
|
+
--pageShell-width: calc(var(--pageShell-content-width) + var(--pageShell-aside-width) + var(--pageShell-gap) + (var(--padding-page) * 2));
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
&:has(> [pgs~="pageShell-aside"] ~ [pgs~="pageShell-aside"]) {
|
|
122
|
-
|
|
126
|
+
--pageShell-width: calc(var(--pageShell-content-width) + (var(--pageShell-aside-width) * 2) + (var(--pageShell-gap) * 2) + (var(--padding-page) * 2));
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
//== RESPONSIVE ==//
|
|
@@ -149,7 +153,7 @@ $pageShell-test-gap: 4rem;
|
|
|
149
153
|
&:has(> [pgs~="pageShell-aside"]):has(> [pgs~="pageShell-content"] + [pgs~="pageShell-aside"]) {
|
|
150
154
|
@container (max-width: calc(#{$aside-size} + #{$content-size} + #{$aside-size} + (#{$pageShell-test-gap} * 2))) {
|
|
151
155
|
display: grid;
|
|
152
|
-
grid-template-columns: var(--pageShell-aside-width) minmax(0, var(--
|
|
156
|
+
grid-template-columns: var(--pageShell-aside-width) minmax(0, var(--pageShell-content-width));
|
|
153
157
|
grid-template-areas:
|
|
154
158
|
"asideLeft content"
|
|
155
159
|
"asideLeft asideRight";
|
|
@@ -178,7 +182,7 @@ $pageShell-test-gap: 4rem;
|
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
@container (max-width: #{$content-size}) {
|
|
181
|
-
padding-top: var(--
|
|
185
|
+
padding-top: var(--pageShell-paddingTop);
|
|
182
186
|
|
|
183
187
|
[pgs~="pageShell-content"],
|
|
184
188
|
[pgs~="pageShell-aside"] {
|
|
@@ -486,17 +486,17 @@
|
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
-
//==
|
|
490
|
-
@mixin
|
|
489
|
+
//== formValidate
|
|
490
|
+
@mixin formValidate() {
|
|
491
491
|
|
|
492
492
|
//=== ERROR
|
|
493
|
-
&[
|
|
494
|
-
[
|
|
493
|
+
&[pgs-option~="error"] {
|
|
494
|
+
[pgs-option~="error"] {
|
|
495
495
|
&:not([type=checkbox], [type=radio]) {
|
|
496
496
|
outline: solid 3px var(--color-error) !important;
|
|
497
497
|
|
|
498
498
|
&::before {
|
|
499
|
-
content: "
|
|
499
|
+
content: "This field is required";
|
|
500
500
|
color: var(--color-error);
|
|
501
501
|
font-weight: 500;
|
|
502
502
|
font-size: 1.7rem;
|
|
@@ -507,7 +507,7 @@
|
|
|
507
507
|
// button[type=submit] {
|
|
508
508
|
// --button-background: var(--color-error);
|
|
509
509
|
// }
|
|
510
|
-
label:has(+[
|
|
510
|
+
label:has(+[pgs-option~="error"], [pgs-option~="error"]) {
|
|
511
511
|
&:has(input[type=checkbox]) {
|
|
512
512
|
background-color: var(--color-error) !important;
|
|
513
513
|
padding: 6px;
|
|
@@ -516,7 +516,7 @@
|
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
-
fieldset:has(input[type=radio][
|
|
519
|
+
fieldset:has(input[type=radio][pgs-option~="error"]) {
|
|
520
520
|
legend {
|
|
521
521
|
--label-background: var(--color-error) !important;
|
|
522
522
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
10
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Urbanist:ital,wght@0,100..900;1,100..900&display=swap">
|
|
11
11
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
|
|
12
|
-
<link rel="stylesheet" href="
|
|
12
|
+
<link rel="stylesheet" href="../dist/css/index.css">
|
|
13
13
|
<link rel="stylesheet" href="demo.css">
|
|
14
14
|
</head>
|
|
15
15
|
|
package/demo/demo.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
//# DEMO PAGE
|
|
2
|
+
|
|
3
|
+
//= demo Renderer HTML
|
|
4
|
+
const demoRenderer = {
|
|
5
|
+
templateFiles: [
|
|
6
|
+
"components/form.html",
|
|
7
|
+
"components/search.html",
|
|
8
|
+
"components/summary.html",
|
|
9
|
+
"components/menu.html",
|
|
10
|
+
"components/tooltip.html",
|
|
11
|
+
"components/modal.html",
|
|
12
|
+
"components/stepTabs.html",
|
|
13
|
+
"components/accordion.html",
|
|
14
|
+
"components/badges.html",
|
|
15
|
+
"components/breadcumbs.html",
|
|
16
|
+
"components/button.html",
|
|
17
|
+
"components/card.html",
|
|
18
|
+
"components/dropdown.html",
|
|
19
|
+
"components/tooltip.html",
|
|
20
|
+
"components/logo.html",
|
|
21
|
+
"components/slides.html",
|
|
22
|
+
"components/steps.html",
|
|
23
|
+
"components/table.html",
|
|
24
|
+
"components/notification.html",
|
|
25
|
+
"patterns/cookieConsent.html",
|
|
26
|
+
"layout/body.html",
|
|
27
|
+
"layout/flex.html",
|
|
28
|
+
"layout/grid.html",
|
|
29
|
+
"layout/footer.html",
|
|
30
|
+
"layout/header.html",
|
|
31
|
+
"layout/section.html",
|
|
32
|
+
"layout/pageShell.html",
|
|
33
|
+
],
|
|
34
|
+
|
|
35
|
+
getTemplateTitle(path) {
|
|
36
|
+
return path.replace(".html", "").replace("/", " / ");
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
stripTemplateDocumentation(html) {
|
|
40
|
+
return html.replace(/^\uFEFF?<!--[\t\r\n ]*\/\*\*[\s\S]*?\*\/[\t\r\n ]*-->[\t\r\n ]*/, "");
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
renderSourceTemplate(section, html) {
|
|
44
|
+
const pre = document.createElement("pre");
|
|
45
|
+
const code = document.createElement("code");
|
|
46
|
+
code.textContent = html.trim();
|
|
47
|
+
pre.append(code);
|
|
48
|
+
section.append(pre);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
renderTemplate(section, path, html) {
|
|
52
|
+
const content = document.createElement("div");
|
|
53
|
+
content.setAttribute("pgs", "container flexColumnElements");
|
|
54
|
+
content.innerHTML = html;
|
|
55
|
+
section.append(content);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
renderLayout(root, path, html) {
|
|
59
|
+
const template = document.createElement("template");
|
|
60
|
+
template.innerHTML = html.trim();
|
|
61
|
+
root.append(template.content.cloneNode(true));
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
renderTitle(section, path) {
|
|
65
|
+
const title = document.createElement("p");
|
|
66
|
+
title.classList.add("template-title");
|
|
67
|
+
title.innerHTML = "<strong>" + this.getTemplateTitle(path) + "</strong>";
|
|
68
|
+
section.append(title);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
async loadTemplate(path) {
|
|
72
|
+
const response = await fetch(`../templates/html/${path}`);
|
|
73
|
+
if (!response.ok) throw new Error(`${path}: ${response.status}`);
|
|
74
|
+
return this.stripTemplateDocumentation(await response.text());
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
loadPgsJavascript() {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const script = document.createElement("script");
|
|
80
|
+
script.src = "../dist/javascript/index.js";
|
|
81
|
+
script.addEventListener("load", resolve, { once: true });
|
|
82
|
+
script.addEventListener("error", () => reject(new Error("Bundle PGS non caricato")), { once: true });
|
|
83
|
+
document.body.append(script);
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async boot() {
|
|
88
|
+
const BEEFORE = document.getElementById("templates-demo-before");
|
|
89
|
+
const MAIN = document.getElementById("templates-demo-main");
|
|
90
|
+
const AFTER = document.getElementById("templates-demo-after");
|
|
91
|
+
|
|
92
|
+
for (const path of this.templateFiles) {
|
|
93
|
+
const isHeader = path === "layout/header.html";
|
|
94
|
+
const isfooter = path === "layout/footer.html";
|
|
95
|
+
const isBody = path === "layout/body.html";
|
|
96
|
+
|
|
97
|
+
if (isHeader || isfooter) {
|
|
98
|
+
try {
|
|
99
|
+
const html = await this.loadTemplate(path);
|
|
100
|
+
this.renderLayout(isHeader ? BEEFORE : AFTER, path, html);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const message = document.createElement("p");
|
|
103
|
+
message.textContent = `Template non caricato: ${error.message}`;
|
|
104
|
+
(isHeader ? BEEFORE : AFTER).append(message);
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let section;
|
|
110
|
+
const isSection = path !== "layout/section.html" && path !== "layout/pageShell.html"
|
|
111
|
+
isSection ? section = document.createElement("section") : section = document.createElement("div");
|
|
112
|
+
|
|
113
|
+
if (isSection) section.setAttribute("pgs", "section flexColumnElements");
|
|
114
|
+
|
|
115
|
+
section.dataset.template = path;
|
|
116
|
+
this.renderTitle(section, path);
|
|
117
|
+
|
|
118
|
+
if (isBody) {
|
|
119
|
+
const html = await this.loadTemplate(path);
|
|
120
|
+
this.renderSourceTemplate(section, html);
|
|
121
|
+
MAIN.append(section);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const html = await this.loadTemplate(path);
|
|
127
|
+
this.renderTemplate(section, path, html);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
const message = document.createElement("p");
|
|
130
|
+
message.textContent = `Template non caricato: ${error.message}`;
|
|
131
|
+
section.append(message);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
MAIN.append(section);
|
|
135
|
+
if (!isSection) {
|
|
136
|
+
section.style.display = "contents";
|
|
137
|
+
Array.from(section.children).forEach(child => child.style.width = "100%");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
//+ ADD FUNCTION
|
|
143
|
+
await this.loadPgsJavascript();
|
|
144
|
+
configureSearchDemo();
|
|
145
|
+
configureFormDemo();
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error("Demo PGS non inizializzata.", error);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
//= Search Demo
|
|
153
|
+
function configureSearchDemo() {
|
|
154
|
+
const pgsApi = globalThis.pgs;
|
|
155
|
+
const section = document.querySelector('[data-template="components/search.html"]');
|
|
156
|
+
if (!pgsApi?.search || !section) return;
|
|
157
|
+
|
|
158
|
+
pgsApi(section).querySelectorAll("search").forEach(search => {
|
|
159
|
+
pgsApi.search.api(search)?.configure({
|
|
160
|
+
minLength: 2,
|
|
161
|
+
debounce: 250,
|
|
162
|
+
source: async ({ query, signal, limit }) => {
|
|
163
|
+
const url = new URL("https://it.wikipedia.org/w/api.php");
|
|
164
|
+
url.search = new URLSearchParams({
|
|
165
|
+
action: "opensearch",
|
|
166
|
+
search: query,
|
|
167
|
+
limit: String(limit),
|
|
168
|
+
namespace: "0",
|
|
169
|
+
format: "json",
|
|
170
|
+
origin: "*",
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const response = await fetch(url, { signal });
|
|
174
|
+
if (!response.ok) throw new Error(`Wikipedia HTTP ${response.status}`);
|
|
175
|
+
|
|
176
|
+
const payload = await response.json();
|
|
177
|
+
const suggestions = Array.isArray(payload?.[1]) ? payload[1] : [];
|
|
178
|
+
const descriptions = Array.isArray(payload?.[2]) ? payload[2] : [];
|
|
179
|
+
const links = Array.isArray(payload?.[3]) ? payload[3] : [];
|
|
180
|
+
|
|
181
|
+
return suggestions.map((suggestion, index) => ({
|
|
182
|
+
label: suggestion,
|
|
183
|
+
value: suggestion,
|
|
184
|
+
data: {
|
|
185
|
+
description: descriptions[index] ?? "",
|
|
186
|
+
url: links[index] ?? "",
|
|
187
|
+
},
|
|
188
|
+
}));
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const note = document.createElement("small");
|
|
194
|
+
note.append("Suggerimenti dimostrativi forniti da ");
|
|
195
|
+
const link = document.createElement("a");
|
|
196
|
+
link.href = "https://www.mediawiki.org/wiki/API:Opensearch/it";
|
|
197
|
+
link.target = "_blank";
|
|
198
|
+
link.rel = "noopener noreferrer";
|
|
199
|
+
link.textContent = "Wikipedia OpenSearch";
|
|
200
|
+
note.append(link, ". Prova a scrivere prodotti di o come fare.");
|
|
201
|
+
section.append(note);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//= Form Demo
|
|
205
|
+
function configureFormDemo() {
|
|
206
|
+
const pgsApi = globalThis.pgs;
|
|
207
|
+
const section = document.querySelector('[data-template="components/form.html"]');
|
|
208
|
+
const form = section?.querySelector('[pgs~="form"]');
|
|
209
|
+
if (!form) return;
|
|
210
|
+
|
|
211
|
+
const password = form.querySelector('input[name="password"]');
|
|
212
|
+
const confirmPassword = form.querySelector('input[name="confirmPassword"]');
|
|
213
|
+
if (!password || !confirmPassword) return;
|
|
214
|
+
|
|
215
|
+
const formValidate = new pgsApi.formValidate(form, {
|
|
216
|
+
message: {
|
|
217
|
+
fieldError: "Completa questo campo",
|
|
218
|
+
fieldsError: "Completa tutti i campi obbligatori",
|
|
219
|
+
success: "Inviato con successo"
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
//== new roules
|
|
224
|
+
formValidate.addNewRule(() => {
|
|
225
|
+
if (password.value && confirmPassword.value && password.value !== confirmPassword.value) {
|
|
226
|
+
pgsApi(confirmPassword).option.setValueBrackets("message", "Le password non coincidono");
|
|
227
|
+
return [confirmPassword, password];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
//== validate
|
|
232
|
+
formValidate.validator(event => {
|
|
233
|
+
const values = Object.fromEntries(new FormData(form));
|
|
234
|
+
|
|
235
|
+
//// Sostituisci questo log con l'invio dei dati al tuo backend.
|
|
236
|
+
console.log(values);
|
|
237
|
+
}, "submit");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
demoRenderer.boot();
|