@@ -48,32 +48,64 @@ for (let i = latestMinor + 1; i > latestMinor - 4; i--) {
48
48
49
49
export interface Filter {
50
50
types: string[];
51
- version: string;
51
+ supported: string;
52
+ changed: string;
52
53
}
53
54
54
- let filter: Filter = {types: [], version: ""};
55
+ let filter: Filter = {
56
+ types: [],
57
+ supported: "",
58
+ changed: "",
59
+ };
55
60
56
61
function handleClick(button: HTMLButtonElement) {
57
62
const text = button.textContent!!.trim();
58
- const isType = button.getAttribute("data-type") === "type";
59
- if (isType) {
60
- toggle(filter.types, text);
61
- } else {
62
- if (text === filter.version) {
63
- filter.version = "";
64
- } else {
65
- filter.version = text;
66
- }
63
+ const attribute = button.getAttribute("data-type")!!;
64
+
65
+ switch (attribute) {
66
+ case "type":
67
+ toggle(filter.types, text);
68
+ break;
69
+ case "supported":
70
+ if (text === filter.supported) {
71
+ filter.supported = "";
72
+ filter.changed = "";
73
+ } else {
74
+ filter.supported = text;
75
+ filter.changed = "";
76
+ }
77
+ break;
78
+ case "changed":
79
+ if (text === filter.changed) {
80
+ filter.changed = "";
81
+ filter.supported = "";
82
+ } else {
83
+ filter.changed = text;
84
+ filter.supported = "";
85
+ }
86
+ break;
87
+ default:
88
+ console.warn(`Unknown filter type: ${button.getAttribute("data-type")}`);
89
+ return;
67
90
}
68
91
69
92
// update rest of buttons
70
93
const buttons = document.querySelectorAll("#filters button");
71
94
buttons.forEach(button => {
72
95
let match = false;
73
- if (button.getAttribute("data-type") === "type") {
74
- match = filter.types.includes(button.textContent!!.trim());
75
- } else {
76
- match = filter.version === button.textContent!!.trim();
96
+
97
+ switch (button.getAttribute("data-type")) {
98
+ case "type":
99
+ match = filter.types.includes(button.textContent!!.trim());
100
+ break;
101
+ case "supported":
102
+ match = filter.supported === button.textContent!!.trim();
103
+ break;
104
+ case "changed":
105
+ match = filter.changed === button.textContent!!.trim();
106
+ break;
107
+ default:
108
+ return;
77
109
}
78
110
79
111
if (match) {
@@ -92,46 +124,56 @@ for (let i = latestMinor + 1; i > latestMinor - 4; i--) {
92
124
return;
93
125
}
94
126
95
- if (isType) {
96
- if (filter.types.length === 0) {
97
- element.classList.remove("hidden-by-type");
98
- return;
99
- }
127
+ element.classList.remove("hidden-by-type", "hidden-by-changed", "hidden-by-supported");
100
128
101
- for (const t of filter.types ) {
102
- if (element.getAttribute("data- type")?.includes(types[t])) {
103
- element.classList.remove("hidden-by-type");
129
+ switch (attribute ) {
130
+ case " type":
131
+ if (filter.types.length === 0) {
104
132
return;
105
133
}
106
- }
107
134
108
- element.classList.add("hidden-by-type");
109
- } else {
110
- if (filter.version === "") {
111
- element.classList.remove("hidden-by-version");
112
- return;
113
- }
135
+ for (const t of filter.types) {
136
+ if (element.getAttribute("data-type")?.includes(types[t])) {
137
+ return;
138
+ }
139
+ }
114
140
115
- if (filter.version.includes("New") && element.getAttribute("data-new") === "true") {
116
- element.classList.remove("hidden-by-version");
117
- return;
118
- }
141
+ element.classList.add("hidden-by-type");
142
+ break;
143
+ case "supported":
144
+ if (filter.supported === "") {
145
+ return;
146
+ }
119
147
120
- const since = element.getAttribute("data-since");
121
- if (since === null) {
122
- element.classList.remove("hidden-by-version");
123
- return;
124
- }
148
+ const since1 = element.getAttribute("data-since");
149
+ if (since1 === null) {
150
+ return;
151
+ }
125
152
126
- const minor = parseInt(filter.version.match(/\d+\.(\d+)/)!![1], 10);
127
- since.matchAll(/\d+\.(\d+)/g).forEach((match) => {
128
- const otherMinor = parseInt(match[1], 10);
129
-
130
- if (otherMinor > minor) {
131
- element.classList.add("hidden-by-version");
153
+ const minor1 = parseInt(filter.supported.match(/\d+\.(\d+)/)!![1], 10);
154
+ since1.matchAll(/\d+\.(\d+)/g).forEach((match) => {
155
+ const otherMinor = parseInt(match[1], 10);
156
+
157
+ if (otherMinor > minor1) {
158
+ element.classList.add("hidden-by-supported");
159
+ return;
160
+ }
161
+ });
162
+ break;
163
+ case "changed":
164
+ const since = element.getAttribute("data-since");
165
+ if (since === null) {
132
166
return;
133
167
}
134
- });
168
+
169
+ if (!since.includes(filter.changed)) {
170
+ element.classList.add("hidden-by-changed");
171
+ return;
172
+ }
173
+ break;
174
+ default:
175
+ console.warn(`Unknown filter type: ${button.getAttribute("data-type")}`);
176
+ return;
135
177
}
136
178
});
137
179
}
@@ -213,7 +255,7 @@ for (let i = latestMinor + 1; i > latestMinor - 4; i--) {
213
255
</button >
214
256
</div >
215
257
<div id =" filter-expand-area" class =" hidden flex-col gap-2 transition" >
216
- <h3 >Type </h3 >
258
+ <h3 >Syntax type </h3 >
217
259
218
260
<div class =" w-fit flex flex-row flex-wrap gap-2" >
219
261
{ rtTypes .map (x =>
@@ -225,15 +267,21 @@ for (let i = latestMinor + 1; i > latestMinor - 4; i--) {
225
267
)}
226
268
</div >
227
269
228
- <h3 >Supported in</h3 >
270
+ <h3 >Syntax is supported in</h3 >
229
271
<div class =" flex flex-wrap gap-2" >
230
- <button data-type =" version" class =" filter-button p-2 rounded-md text-center
231
- bg-skript text-white font-bold
272
+ { versions .map (x =>
273
+ <button data-type = " supported" class = " filter-button p-2 rounded-md text-center
274
+ bg-l-bg-secondary dark:bg-d-bg-secondary
232
275
hover:cursor-pointer hover:opacity-80 transition" >
233
- { versions [ 0 ] }
276
+ { x }
234
277
</button >
235
- { versions .slice (1 ).map (x =>
236
- <button data-type = " version" class = " filter-button p-2 rounded-md text-center
278
+ )}
279
+ </div >
280
+
281
+ <h3 >Syntax was changed in</h3 >
282
+ <div class =" flex flex-wrap gap-2" >
283
+ { versions .map (x =>
284
+ <button data-type = " changed" class = " filter-button p-2 rounded-md text-center
237
285
bg-l-bg-secondary dark:bg-d-bg-secondary
238
286
hover:cursor-pointer hover:opacity-80 transition" >
239
287
{ x }
0 commit comments