@bbki.ng/bb-msg-history 0.11.2 → 0.12.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/component.js +21 -5
- package/dist/const/styles.js +5 -0
- package/package.json +1 -1
- package/src/component.ts +29 -6
- package/src/const/styles.ts +5 -0
package/dist/component.js
CHANGED
|
@@ -6,7 +6,7 @@ import { buildMessageRowHtml, setupTooltipForElement } from './utils/message-bui
|
|
|
6
6
|
import { buildScrollButtonHtml } from './utils/scroll-button.js';
|
|
7
7
|
export class BBMsgHistory extends HTMLElement {
|
|
8
8
|
static get observedAttributes() {
|
|
9
|
-
return ['theme', 'loading', 'hide-scroll-bar', 'infinite'];
|
|
9
|
+
return ['theme', 'loading', 'hide-scroll-bar', 'infinite', 'hide-scroll-button'];
|
|
10
10
|
}
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
@@ -19,7 +19,7 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
19
19
|
this.attachShadow({ mode: 'open' });
|
|
20
20
|
}
|
|
21
21
|
attributeChangedCallback(name) {
|
|
22
|
-
if (name === 'theme' || name === 'loading' || name === 'hide-scroll-bar' || name === 'infinite') {
|
|
22
|
+
if (name === 'theme' || name === 'loading' || name === 'hide-scroll-bar' || name === 'infinite' || name === 'hide-scroll-button') {
|
|
23
23
|
this.render();
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -133,6 +133,12 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
133
133
|
if (scrollButton && this._scrollButtonVisible) {
|
|
134
134
|
this._scrollButtonVisible = false;
|
|
135
135
|
scrollButton.classList.remove('visible');
|
|
136
|
+
// Dispatch hide event
|
|
137
|
+
this.dispatchEvent(new CustomEvent('bb-scrollbuttonhide', {
|
|
138
|
+
bubbles: true,
|
|
139
|
+
composed: true,
|
|
140
|
+
detail: { visible: false }
|
|
141
|
+
}));
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
}
|
|
@@ -233,12 +239,13 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
233
239
|
<div class="loading-spinner"></div>
|
|
234
240
|
</div>`
|
|
235
241
|
: '';
|
|
242
|
+
const hideScrollButton = this.hasAttribute('hide-scroll-button');
|
|
236
243
|
this.shadowRoot.innerHTML = `
|
|
237
244
|
<style>${MAIN_STYLES}${LOADING_STYLES}</style>
|
|
238
245
|
<div class="history" role="log" aria-live="polite" aria-label="Message history">
|
|
239
246
|
${messagesHtml}
|
|
240
247
|
</div>
|
|
241
|
-
${buildScrollButtonHtml()}
|
|
248
|
+
${hideScrollButton ? '' : buildScrollButtonHtml()}
|
|
242
249
|
${loadingOverlay}
|
|
243
250
|
`;
|
|
244
251
|
this._setupAfterRender();
|
|
@@ -276,9 +283,12 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
276
283
|
_setupAfterRender() {
|
|
277
284
|
requestAnimationFrame(() => {
|
|
278
285
|
const container = this.shadowRoot.querySelector('.history');
|
|
279
|
-
const
|
|
286
|
+
const hideScrollButton = this.hasAttribute('hide-scroll-button');
|
|
287
|
+
const scrollButton = hideScrollButton
|
|
288
|
+
? null
|
|
289
|
+
: this.shadowRoot.querySelector('.scroll-to-bottom');
|
|
280
290
|
const isInfinite = this.hasAttribute('infinite');
|
|
281
|
-
if (container && !isInfinite) {
|
|
291
|
+
if (container && !isInfinite && !hideScrollButton) {
|
|
282
292
|
// Mark as programmatic scroll to prevent triggering user scroll detection
|
|
283
293
|
this._isProgrammaticScroll = true;
|
|
284
294
|
container.scrollTop = container.scrollHeight;
|
|
@@ -338,6 +348,12 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
338
348
|
if (shouldShow !== this._scrollButtonVisible) {
|
|
339
349
|
this._scrollButtonVisible = shouldShow;
|
|
340
350
|
button.classList.toggle('visible', shouldShow);
|
|
351
|
+
// Dispatch custom event
|
|
352
|
+
this.dispatchEvent(new CustomEvent(shouldShow ? 'bb-scrollbuttonshow' : 'bb-scrollbuttonhide', {
|
|
353
|
+
bubbles: true,
|
|
354
|
+
composed: true,
|
|
355
|
+
detail: { visible: shouldShow }
|
|
356
|
+
}));
|
|
341
357
|
}
|
|
342
358
|
};
|
|
343
359
|
// Initialize last scroll position
|
package/dist/const/styles.js
CHANGED
|
@@ -71,6 +71,11 @@ export const MAIN_STYLES = `
|
|
|
71
71
|
display: none;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/* Hide scroll button when explicitly disabled */
|
|
75
|
+
:host([hide-scroll-button]) .scroll-to-bottom {
|
|
76
|
+
display: none;
|
|
77
|
+
}
|
|
78
|
+
|
|
74
79
|
/* Scroll to bottom button */
|
|
75
80
|
.scroll-to-bottom {
|
|
76
81
|
position: absolute;
|
package/package.json
CHANGED
package/src/component.ts
CHANGED
|
@@ -17,7 +17,7 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
17
17
|
private _lastScrollTop = 0;
|
|
18
18
|
|
|
19
19
|
static get observedAttributes() {
|
|
20
|
-
return ['theme', 'loading', 'hide-scroll-bar', 'infinite'];
|
|
20
|
+
return ['theme', 'loading', 'hide-scroll-bar', 'infinite', 'hide-scroll-button'];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
constructor() {
|
|
@@ -26,7 +26,7 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
attributeChangedCallback(name: string) {
|
|
29
|
-
if (name === 'theme' || name === 'loading' || name === 'hide-scroll-bar' || name === 'infinite') {
|
|
29
|
+
if (name === 'theme' || name === 'loading' || name === 'hide-scroll-bar' || name === 'infinite' || name === 'hide-scroll-button') {
|
|
30
30
|
this.render();
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -170,6 +170,15 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
170
170
|
if (scrollButton && this._scrollButtonVisible) {
|
|
171
171
|
this._scrollButtonVisible = false;
|
|
172
172
|
scrollButton.classList.remove('visible');
|
|
173
|
+
|
|
174
|
+
// Dispatch hide event
|
|
175
|
+
this.dispatchEvent(
|
|
176
|
+
new CustomEvent('bb-scrollbuttonhide', {
|
|
177
|
+
bubbles: true,
|
|
178
|
+
composed: true,
|
|
179
|
+
detail: { visible: false }
|
|
180
|
+
})
|
|
181
|
+
);
|
|
173
182
|
}
|
|
174
183
|
}
|
|
175
184
|
}
|
|
@@ -293,12 +302,14 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
293
302
|
</div>`
|
|
294
303
|
: '';
|
|
295
304
|
|
|
305
|
+
const hideScrollButton = this.hasAttribute('hide-scroll-button');
|
|
306
|
+
|
|
296
307
|
this.shadowRoot!.innerHTML = `
|
|
297
308
|
<style>${MAIN_STYLES}${LOADING_STYLES}</style>
|
|
298
309
|
<div class="history" role="log" aria-live="polite" aria-label="Message history">
|
|
299
310
|
${messagesHtml}
|
|
300
311
|
</div>
|
|
301
|
-
${buildScrollButtonHtml()}
|
|
312
|
+
${hideScrollButton ? '' : buildScrollButtonHtml()}
|
|
302
313
|
${loadingOverlay}
|
|
303
314
|
`;
|
|
304
315
|
|
|
@@ -345,17 +356,20 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
345
356
|
private _setupAfterRender(): void {
|
|
346
357
|
requestAnimationFrame(() => {
|
|
347
358
|
const container = this.shadowRoot!.querySelector('.history') as HTMLElement;
|
|
348
|
-
const
|
|
359
|
+
const hideScrollButton = this.hasAttribute('hide-scroll-button');
|
|
360
|
+
const scrollButton = hideScrollButton
|
|
361
|
+
? null
|
|
362
|
+
: (this.shadowRoot!.querySelector('.scroll-to-bottom') as HTMLButtonElement);
|
|
349
363
|
const isInfinite = this.hasAttribute('infinite');
|
|
350
364
|
|
|
351
|
-
if (container && !isInfinite) {
|
|
365
|
+
if (container && !isInfinite && !hideScrollButton) {
|
|
352
366
|
// Mark as programmatic scroll to prevent triggering user scroll detection
|
|
353
367
|
this._isProgrammaticScroll = true;
|
|
354
368
|
container.scrollTop = container.scrollHeight;
|
|
355
369
|
requestAnimationFrame(() => {
|
|
356
370
|
this._isProgrammaticScroll = false;
|
|
357
371
|
});
|
|
358
|
-
this._setupScrollTracking(container, scrollButton
|
|
372
|
+
this._setupScrollTracking(container, scrollButton!, { skipInitialCheck: true });
|
|
359
373
|
}
|
|
360
374
|
|
|
361
375
|
if (scrollButton && !isInfinite) {
|
|
@@ -420,6 +434,15 @@ export class BBMsgHistory extends HTMLElement {
|
|
|
420
434
|
if (shouldShow !== this._scrollButtonVisible) {
|
|
421
435
|
this._scrollButtonVisible = shouldShow;
|
|
422
436
|
button.classList.toggle('visible', shouldShow);
|
|
437
|
+
|
|
438
|
+
// Dispatch custom event
|
|
439
|
+
this.dispatchEvent(
|
|
440
|
+
new CustomEvent(shouldShow ? 'bb-scrollbuttonshow' : 'bb-scrollbuttonhide', {
|
|
441
|
+
bubbles: true,
|
|
442
|
+
composed: true,
|
|
443
|
+
detail: { visible: shouldShow }
|
|
444
|
+
})
|
|
445
|
+
);
|
|
423
446
|
}
|
|
424
447
|
};
|
|
425
448
|
|
package/src/const/styles.ts
CHANGED
|
@@ -72,6 +72,11 @@ export const MAIN_STYLES = `
|
|
|
72
72
|
display: none;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/* Hide scroll button when explicitly disabled */
|
|
76
|
+
:host([hide-scroll-button]) .scroll-to-bottom {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
75
80
|
/* Scroll to bottom button */
|
|
76
81
|
.scroll-to-bottom {
|
|
77
82
|
position: absolute;
|