@stackoverflow/stacks 2.6.0 → 2.7.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/dist/js/stacks.js CHANGED
@@ -2661,7 +2661,6 @@ class StacksApplication extends Application {
2661
2661
  }
2662
2662
  static start(element, schema) {
2663
2663
  const application = new StacksApplication(element, schema);
2664
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
2665
2664
  application.start();
2666
2665
  return application;
2667
2666
  }
@@ -2691,9 +2690,8 @@ class StacksController extends Controller {
2691
2690
  detail: detail,
2692
2691
  });
2693
2692
  }
2694
- catch (ex) {
2693
+ catch (_a) {
2695
2694
  // Internet Explorer
2696
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2697
2695
  event = document.createEvent("CustomEvent");
2698
2696
  event.initCustomEvent(namespacedName, true, true, detail);
2699
2697
  }
@@ -2862,7 +2860,7 @@ function globalChangeListener(e) {
2862
2860
  try {
2863
2861
  customEvent = new Event(RADIO_OFF_EVENT);
2864
2862
  }
2865
- catch (ex) {
2863
+ catch (_a) {
2866
2864
  // Internet Explorer
2867
2865
  customEvent = document.createEvent("Event");
2868
2866
  customEvent.initEvent(RADIO_OFF_EVENT, true, true);
@@ -6729,7 +6727,6 @@ class UploaderController extends StacksController {
6729
6727
  let thumbElement;
6730
6728
  if (file.type.match("image/*") && file.data) {
6731
6729
  thumbElement = document.createElement("img");
6732
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
6733
6730
  thumbElement.src = file.data.toString();
6734
6731
  thumbElement.alt = file.name;
6735
6732
  }
@@ -59,7 +59,6 @@
59
59
  .highcontrast-mode({
60
60
  --_bu-bc: currentColor;
61
61
  --_bu-outlined-bc: var(--_bu-bc);
62
- --_bu-bc-selected: var(--_bu-bc);
63
62
  --_bu-fc-selected: var(--white);
64
63
  --_bu-outlined-fc-selected: var(--white);
65
64
  --_bu-badge-o: 0.8;
@@ -236,6 +235,7 @@
236
235
 
237
236
  // VARIANTS
238
237
  &&__danger,
238
+ &&__featured,
239
239
  &&__muted {
240
240
  .highcontrast-mode({
241
241
  --_bu-filled-bc: transparent;
@@ -268,6 +268,32 @@
268
268
  --_bu-number-fc-filled: var(--black);
269
269
  }
270
270
 
271
+ &&__featured {
272
+ --_bu-bg-active: var(--purple-300);
273
+ --_bu-bg-hover: var(--purple-200);
274
+ --_bu-bg-selected: var(--purple-300);
275
+ --_bu-fc: var(--purple-500);
276
+ --_bu-fc-active: var(--_bu-fc);
277
+ --_bu-fc-hover: var(--purple-500);
278
+ --_bu-fc-selected: var(--purple-600);
279
+ --_bu-filled-bc: transparent;
280
+ --_bu-filled-bc-selected: var(--_bu-filled-bc);
281
+ --_bu-filled-bg: var(--purple-400);
282
+ --_bu-filled-bg-active: var(--purple-500);
283
+ --_bu-filled-bg-hover: var(--purple-500);
284
+ --_bu-filled-bg-selected: var(--purple-600);
285
+ --_bu-filled-fc: var(--white);
286
+ --_bu-filled-fc-active: var(--_bu-filled-fc);
287
+ --_bu-filled-fc-hover: var(--_bu-filled-fc);
288
+ --_bu-filled-fc-selected: var(--_bu-filled-fc);
289
+ --_bu-outlined-bc: var(--purple-400);
290
+ --_bu-outlined-bc-selected: var(--purple-500);
291
+ --_bu-outlined-bg-selected: var(--_bu-bg-selected);
292
+ --_bu-outlined-fc-selected: var(--_bu-fc-selected);
293
+ --_bu-number-fc: var(--white);
294
+ --_bu-number-fc-filled: var(--black);
295
+ }
296
+
271
297
  &&__muted {
272
298
  --_bu-bc-hover: var(--black-300);
273
299
  --_bu-bg-active: var(--black-150);
@@ -300,6 +326,7 @@
300
326
  --_bu-number-fc-focus: var(--black-500);
301
327
 
302
328
  .highcontrast-mode({
329
+ --_bu-bc-hover: currentColor;
303
330
  --_bu-bg-hover: var(--black-225);
304
331
  // // The filled modifier on the muted button is deprecated and is to be
305
332
  // // removed in Stacks Classic v2
@@ -309,6 +336,7 @@
309
336
  --_bu-filled-bg-selected: var(--black-500);
310
337
  --_bu-filled-fc: var(--white);
311
338
  --_bu-filled-fc-selected: var(--_bu-filled-fc);
339
+ --_bu-bc-selected: currentColor;
312
340
  --_bu-fc-selected: var(--black);
313
341
  --_bu-number-fc: var(--white);
314
342
  --_bu-number-fc-filled: var(--black);
@@ -408,7 +436,7 @@
408
436
  color: var(--_bu-filled-fc-hover);
409
437
  }
410
438
 
411
- &:not(.s-btn__outlined) {
439
+ &:not(.s-btn__outlined):not(.s-btn__filled) {
412
440
  border-color: var(--_bu-bc-hover);
413
441
  }
414
442
 
@@ -1,238 +1,238 @@
1
- import * as Stacks from "../../stacks";
2
-
3
- // Radio buttons only trigger a change event when they're *checked*, but not when
4
- // they're *unchecked*. Therefore, if we have an active `s-expandable-control` in
5
- // the document, we listen for change events on *all* radio buttons and find any
6
- // other radio buttons in the same `name` group, triggering a custom event on all
7
- // of them so the controller can re-evaluate.
8
- //
9
- // We're keeping a count of how many of these controllers are connected to the DOM,
10
- // so only have this global listener when we actually need it.
11
- const RADIO_OFF_EVENT = "s-expandable-control:radio-off";
12
-
13
- function globalChangeListener(e: UIEvent) {
14
- const target = e.target;
15
- if (
16
- !(target instanceof HTMLInputElement) ||
17
- target.nodeName !== "INPUT" ||
18
- target.type !== "radio"
19
- ) {
20
- return;
21
- }
22
- document
23
- .querySelectorAll('input[type="radio"][name="' + target.name + '"]')
24
- .forEach(function (other) {
25
- if (other === e.target) {
26
- return;
27
- }
28
- let customEvent;
29
- try {
30
- customEvent = new Event(RADIO_OFF_EVENT);
31
- } catch (ex) {
32
- // Internet Explorer
33
- customEvent = document.createEvent("Event");
34
- customEvent.initEvent(RADIO_OFF_EVENT, true, true);
35
- }
36
- other.dispatchEvent(customEvent);
37
- });
38
- }
39
-
40
- let refCount = 0;
41
- function globalChangeListenerRequired(required: boolean) {
42
- if (required) {
43
- refCount++;
44
- if (refCount === 1) {
45
- document.body.addEventListener(
46
- "change",
47
- globalChangeListener as EventListener
48
- );
49
- }
50
- } else {
51
- refCount--;
52
- if (refCount === 0) {
53
- document.body.removeEventListener(
54
- "change",
55
- globalChangeListener as EventListener
56
- );
57
- }
58
- }
59
- }
60
-
61
- export class ExpandableController extends Stacks.StacksController {
62
- private isCollapsed!: () => boolean;
63
- private events!: string[];
64
- private isCheckable!: boolean;
65
- private isRadio!: boolean;
66
- private lastKeydownClickTimestamp = 0;
67
-
68
- initialize() {
69
- if (
70
- this.element.nodeName === "INPUT" &&
71
- ["radio", "checkbox"].indexOf(
72
- (<HTMLInputElement>this.element).type
73
- ) >= 0
74
- ) {
75
- this.isCollapsed = this._isCollapsedForCheckable.bind(this);
76
- this.events = ["change", RADIO_OFF_EVENT];
77
- this.isCheckable = true;
78
- this.isRadio = (<HTMLInputElement>this.element).type === "radio";
79
- } else {
80
- this.isCollapsed = this._isCollapsedForClickable.bind(this);
81
- this.events = ["click", "keydown"];
82
- }
83
- this.listener = this.listener.bind(this);
84
- }
85
-
86
- // for non-checkable elements, the initial source of truth is the collapsed/expanded
87
- // state of the controlled element (unless the element doesn't exist)
88
- _isCollapsedForClickable() {
89
- const cc = this.controlledExpandables;
90
- // the element is considered collapsed if *any* target element is collapsed
91
- return cc.length > 0
92
- ? !cc.every((element) => element.classList.contains("is-expanded"))
93
- : this.element.getAttribute("aria-expanded") === "false";
94
- }
95
-
96
- // for checkable elements, the initial source of truth is the checked state
97
- _isCollapsedForCheckable() {
98
- return !(<HTMLInputElement>this.element).checked;
99
- }
100
-
101
- get controlledExpandables() {
102
- const attr = this.element.getAttribute("aria-controls");
103
- if (!attr) {
104
- throw `[aria-controls="targetId1 ... targetIdN"] attribute required`;
105
- }
106
- const result = attr
107
- .split(/\s+/g)
108
- .map((s) => document.getElementById(s))
109
- .filter((e): e is HTMLElement => !!e);
110
- if (!result.length) {
111
- throw "couldn't find controls";
112
- }
113
- return result;
114
- }
115
-
116
- _dispatchShowHideEvent(isShow: boolean) {
117
- this.triggerEvent(isShow ? "show" : "hide");
118
- }
119
-
120
- _toggleClass(doAdd: boolean) {
121
- if (!this.data.has("toggle-class")) {
122
- return;
123
- }
124
- const cl = this.element.classList;
125
- const toggleClass = this.data.get("toggle-class");
126
- if (!toggleClass) {
127
- throw "couldn't find toggle class";
128
- }
129
- toggleClass.split(/\s+/).forEach(function (cls) {
130
- cl.toggle(cls, !!doAdd);
131
- });
132
- }
133
-
134
- listener(e: Event) {
135
- let newCollapsed;
136
- if (this.isCheckable) {
137
- newCollapsed = !(<HTMLInputElement>this.element).checked;
138
- } else {
139
- if (
140
- e.type == "keydown" &&
141
- e instanceof KeyboardEvent &&
142
- e.keyCode != 13 &&
143
- e.keyCode != 32
144
- ) {
145
- return;
146
- }
147
- if (
148
- e.target !== e.currentTarget &&
149
- ["A", "BUTTON"].indexOf((<HTMLElement>e.target).nodeName) >= 0
150
- ) {
151
- return;
152
- }
153
-
154
- e.preventDefault();
155
-
156
- // Prevent "click" events from toggling the expandable within 300ms of "keydown".
157
- // e.preventDefault() should have done the same, but https://bugzilla.mozilla.org/show_bug.cgi?id=1487102
158
- // doesn't guarantee it.
159
- if (e.type == "keydown") {
160
- this.lastKeydownClickTimestamp = Date.now();
161
- } else if (
162
- e.type == "click" &&
163
- Date.now() - this.lastKeydownClickTimestamp < 300
164
- ) {
165
- return;
166
- }
167
- newCollapsed =
168
- this.element.getAttribute("aria-expanded") === "true";
169
- if (e.type === "click") {
170
- (<HTMLInputElement>this.element).blur();
171
- }
172
- }
173
- this.element.setAttribute(
174
- "aria-expanded",
175
- newCollapsed ? "false" : "true"
176
- );
177
- for (const controlledElement of this.controlledExpandables) {
178
- controlledElement.classList.toggle("is-expanded", !newCollapsed);
179
- }
180
- this._dispatchShowHideEvent(!newCollapsed);
181
- this._toggleClass(!newCollapsed);
182
- }
183
-
184
- connect() {
185
- this.events.forEach((e) => {
186
- this.element.addEventListener(e, this.listener.bind(this));
187
- }, this);
188
-
189
- if (this.isRadio) {
190
- globalChangeListenerRequired(true);
191
- }
192
-
193
- // synchronize state -- in all cases, this means setting the correct `aria-expanded`
194
- // attribute; for checkable controls this also means setting the `is-collapsed` class.
195
- // Note: aria-expanded is currently an invalid attribute on radio elements
196
- // Support for aria-expanded is being debated by the W3C https://github.com/w3c/aria/issues/1404 as recently as June 2022
197
- if (!this.isRadio) {
198
- this.element.setAttribute(
199
- "aria-expanded",
200
- this.isCollapsed() ? "false" : "true"
201
- );
202
- }
203
- if (this.isCheckable) {
204
- const cc = this.controlledExpandables;
205
- if (cc.length) {
206
- const expected = !this.isCollapsed();
207
- // if any element does not match the expected state, set them all to the expected state
208
- if (
209
- cc.some(
210
- (element) =>
211
- element.classList.contains("is-expanded") !==
212
- expected
213
- )
214
- ) {
215
- for (const controlledElement of this
216
- .controlledExpandables) {
217
- controlledElement.classList.toggle(
218
- "is-expanded",
219
- expected
220
- );
221
- }
222
- this._dispatchShowHideEvent(expected);
223
- this._toggleClass(expected);
224
- }
225
- }
226
- }
227
- }
228
-
229
- disconnect() {
230
- this.events.forEach((e) => {
231
- this.element.removeEventListener(e, this.listener.bind(this));
232
- }, this);
233
-
234
- if (this.isRadio) {
235
- globalChangeListenerRequired(false);
236
- }
237
- }
238
- }
1
+ import * as Stacks from "../../stacks";
2
+
3
+ // Radio buttons only trigger a change event when they're *checked*, but not when
4
+ // they're *unchecked*. Therefore, if we have an active `s-expandable-control` in
5
+ // the document, we listen for change events on *all* radio buttons and find any
6
+ // other radio buttons in the same `name` group, triggering a custom event on all
7
+ // of them so the controller can re-evaluate.
8
+ //
9
+ // We're keeping a count of how many of these controllers are connected to the DOM,
10
+ // so only have this global listener when we actually need it.
11
+ const RADIO_OFF_EVENT = "s-expandable-control:radio-off";
12
+
13
+ function globalChangeListener(e: UIEvent) {
14
+ const target = e.target;
15
+ if (
16
+ !(target instanceof HTMLInputElement) ||
17
+ target.nodeName !== "INPUT" ||
18
+ target.type !== "radio"
19
+ ) {
20
+ return;
21
+ }
22
+ document
23
+ .querySelectorAll('input[type="radio"][name="' + target.name + '"]')
24
+ .forEach(function (other) {
25
+ if (other === e.target) {
26
+ return;
27
+ }
28
+ let customEvent;
29
+ try {
30
+ customEvent = new Event(RADIO_OFF_EVENT);
31
+ } catch {
32
+ // Internet Explorer
33
+ customEvent = document.createEvent("Event");
34
+ customEvent.initEvent(RADIO_OFF_EVENT, true, true);
35
+ }
36
+ other.dispatchEvent(customEvent);
37
+ });
38
+ }
39
+
40
+ let refCount = 0;
41
+ function globalChangeListenerRequired(required: boolean) {
42
+ if (required) {
43
+ refCount++;
44
+ if (refCount === 1) {
45
+ document.body.addEventListener(
46
+ "change",
47
+ globalChangeListener as EventListener
48
+ );
49
+ }
50
+ } else {
51
+ refCount--;
52
+ if (refCount === 0) {
53
+ document.body.removeEventListener(
54
+ "change",
55
+ globalChangeListener as EventListener
56
+ );
57
+ }
58
+ }
59
+ }
60
+
61
+ export class ExpandableController extends Stacks.StacksController {
62
+ private isCollapsed!: () => boolean;
63
+ private events!: string[];
64
+ private isCheckable!: boolean;
65
+ private isRadio!: boolean;
66
+ private lastKeydownClickTimestamp = 0;
67
+
68
+ initialize() {
69
+ if (
70
+ this.element.nodeName === "INPUT" &&
71
+ ["radio", "checkbox"].indexOf(
72
+ (<HTMLInputElement>this.element).type
73
+ ) >= 0
74
+ ) {
75
+ this.isCollapsed = this._isCollapsedForCheckable.bind(this);
76
+ this.events = ["change", RADIO_OFF_EVENT];
77
+ this.isCheckable = true;
78
+ this.isRadio = (<HTMLInputElement>this.element).type === "radio";
79
+ } else {
80
+ this.isCollapsed = this._isCollapsedForClickable.bind(this);
81
+ this.events = ["click", "keydown"];
82
+ }
83
+ this.listener = this.listener.bind(this);
84
+ }
85
+
86
+ // for non-checkable elements, the initial source of truth is the collapsed/expanded
87
+ // state of the controlled element (unless the element doesn't exist)
88
+ _isCollapsedForClickable() {
89
+ const cc = this.controlledExpandables;
90
+ // the element is considered collapsed if *any* target element is collapsed
91
+ return cc.length > 0
92
+ ? !cc.every((element) => element.classList.contains("is-expanded"))
93
+ : this.element.getAttribute("aria-expanded") === "false";
94
+ }
95
+
96
+ // for checkable elements, the initial source of truth is the checked state
97
+ _isCollapsedForCheckable() {
98
+ return !(<HTMLInputElement>this.element).checked;
99
+ }
100
+
101
+ get controlledExpandables() {
102
+ const attr = this.element.getAttribute("aria-controls");
103
+ if (!attr) {
104
+ throw `[aria-controls="targetId1 ... targetIdN"] attribute required`;
105
+ }
106
+ const result = attr
107
+ .split(/\s+/g)
108
+ .map((s) => document.getElementById(s))
109
+ .filter((e): e is HTMLElement => !!e);
110
+ if (!result.length) {
111
+ throw "couldn't find controls";
112
+ }
113
+ return result;
114
+ }
115
+
116
+ _dispatchShowHideEvent(isShow: boolean) {
117
+ this.triggerEvent(isShow ? "show" : "hide");
118
+ }
119
+
120
+ _toggleClass(doAdd: boolean) {
121
+ if (!this.data.has("toggle-class")) {
122
+ return;
123
+ }
124
+ const cl = this.element.classList;
125
+ const toggleClass = this.data.get("toggle-class");
126
+ if (!toggleClass) {
127
+ throw "couldn't find toggle class";
128
+ }
129
+ toggleClass.split(/\s+/).forEach(function (cls) {
130
+ cl.toggle(cls, !!doAdd);
131
+ });
132
+ }
133
+
134
+ listener(e: Event) {
135
+ let newCollapsed;
136
+ if (this.isCheckable) {
137
+ newCollapsed = !(<HTMLInputElement>this.element).checked;
138
+ } else {
139
+ if (
140
+ e.type == "keydown" &&
141
+ e instanceof KeyboardEvent &&
142
+ e.keyCode != 13 &&
143
+ e.keyCode != 32
144
+ ) {
145
+ return;
146
+ }
147
+ if (
148
+ e.target !== e.currentTarget &&
149
+ ["A", "BUTTON"].indexOf((<HTMLElement>e.target).nodeName) >= 0
150
+ ) {
151
+ return;
152
+ }
153
+
154
+ e.preventDefault();
155
+
156
+ // Prevent "click" events from toggling the expandable within 300ms of "keydown".
157
+ // e.preventDefault() should have done the same, but https://bugzilla.mozilla.org/show_bug.cgi?id=1487102
158
+ // doesn't guarantee it.
159
+ if (e.type == "keydown") {
160
+ this.lastKeydownClickTimestamp = Date.now();
161
+ } else if (
162
+ e.type == "click" &&
163
+ Date.now() - this.lastKeydownClickTimestamp < 300
164
+ ) {
165
+ return;
166
+ }
167
+ newCollapsed =
168
+ this.element.getAttribute("aria-expanded") === "true";
169
+ if (e.type === "click") {
170
+ (<HTMLInputElement>this.element).blur();
171
+ }
172
+ }
173
+ this.element.setAttribute(
174
+ "aria-expanded",
175
+ newCollapsed ? "false" : "true"
176
+ );
177
+ for (const controlledElement of this.controlledExpandables) {
178
+ controlledElement.classList.toggle("is-expanded", !newCollapsed);
179
+ }
180
+ this._dispatchShowHideEvent(!newCollapsed);
181
+ this._toggleClass(!newCollapsed);
182
+ }
183
+
184
+ connect() {
185
+ this.events.forEach((e) => {
186
+ this.element.addEventListener(e, this.listener.bind(this));
187
+ }, this);
188
+
189
+ if (this.isRadio) {
190
+ globalChangeListenerRequired(true);
191
+ }
192
+
193
+ // synchronize state -- in all cases, this means setting the correct `aria-expanded`
194
+ // attribute; for checkable controls this also means setting the `is-collapsed` class.
195
+ // Note: aria-expanded is currently an invalid attribute on radio elements
196
+ // Support for aria-expanded is being debated by the W3C https://github.com/w3c/aria/issues/1404 as recently as June 2022
197
+ if (!this.isRadio) {
198
+ this.element.setAttribute(
199
+ "aria-expanded",
200
+ this.isCollapsed() ? "false" : "true"
201
+ );
202
+ }
203
+ if (this.isCheckable) {
204
+ const cc = this.controlledExpandables;
205
+ if (cc.length) {
206
+ const expected = !this.isCollapsed();
207
+ // if any element does not match the expected state, set them all to the expected state
208
+ if (
209
+ cc.some(
210
+ (element) =>
211
+ element.classList.contains("is-expanded") !==
212
+ expected
213
+ )
214
+ ) {
215
+ for (const controlledElement of this
216
+ .controlledExpandables) {
217
+ controlledElement.classList.toggle(
218
+ "is-expanded",
219
+ expected
220
+ );
221
+ }
222
+ this._dispatchShowHideEvent(expected);
223
+ this._toggleClass(expected);
224
+ }
225
+ }
226
+ }
227
+ }
228
+
229
+ disconnect() {
230
+ this.events.forEach((e) => {
231
+ this.element.removeEventListener(e, this.listener.bind(this));
232
+ }, this);
233
+
234
+ if (this.isRadio) {
235
+ globalChangeListenerRequired(false);
236
+ }
237
+ }
238
+ }