@cloudflare/realtimekit-ui 1.1.0-staging.6 → 1.1.0-staging.7
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/browser.js +1 -1
- package/dist/cjs/rtk-avatar_24.cjs.entry.js +193 -195
- package/dist/cjs/rtk-chat-toggle.cjs.entry.js +1 -1
- package/dist/cjs/rtk-notifications.cjs.entry.js +4 -1
- package/dist/collection/components/rtk-chat-messages-ui-paginated/rtk-chat-messages-ui-paginated.js +2 -2
- package/dist/collection/components/rtk-chat-toggle/rtk-chat-toggle.js +1 -1
- package/dist/collection/components/rtk-notifications/rtk-notifications.js +4 -1
- package/dist/collection/components/rtk-paginated-list/rtk-paginated-list.js +191 -193
- package/dist/components/{p-85872241.js → p-1d16490e.js} +2 -2
- package/dist/components/{p-b6781e91.js → p-7be71567.js} +3 -3
- package/dist/components/{p-e7e2156a.js → p-7f8d9afc.js} +191 -193
- package/dist/components/rtk-chat-messages-ui-paginated.js +1 -1
- package/dist/components/rtk-chat-search-results.js +1 -1
- package/dist/components/rtk-chat-toggle.js +1 -1
- package/dist/components/rtk-chat.js +1 -1
- package/dist/components/rtk-meeting.js +3 -3
- package/dist/components/rtk-notifications.js +4 -1
- package/dist/components/rtk-paginated-list.js +1 -1
- package/dist/docs/docs-components.json +1 -1
- package/dist/esm/loader.js +197 -196
- package/dist/esm/rtk-avatar_24.entry.js +193 -195
- package/dist/esm/rtk-chat-toggle.entry.js +1 -1
- package/dist/esm/rtk-notifications.entry.js +4 -1
- package/dist/realtimekit-ui/p-25c13ff8.entry.js +1 -0
- package/dist/realtimekit-ui/p-342b4926.entry.js +1 -0
- package/dist/realtimekit-ui/{p-421e4c6f.entry.js → p-ec5ed8a4.entry.js} +1 -1
- package/dist/realtimekit-ui/realtimekit-ui.esm.js +1 -1
- package/dist/types/components/rtk-paginated-list/rtk-paginated-list.d.ts +32 -46
- package/package.json +1 -1
- package/dist/realtimekit-ui/p-19587963.entry.js +0 -1
- package/dist/realtimekit-ui/p-a859d883.entry.js +0 -1
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* NOTE(ikabra): INFINITE SCROLL IMPLEMENTATION:
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Uses scrollend listener for 2way scrolling.
|
|
5
|
+
* Empty divs ($topRef, $bottomRef) act as scroll triggers to fetch new messages.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* UPWARD SCROLLING:
|
|
8
|
+
* - Fetch top anchor (element currently visible to the user near top)
|
|
9
|
+
* - Fetch older messages, push to end of 2D array
|
|
10
|
+
* - When exceeding pagesAllowed, delete pages and scroll back to anchor
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* DOWNWARD SCROLLING:
|
|
13
|
+
* - Fetch bottom anchor (element currently visible to the user near bottom)
|
|
14
|
+
* - Fetch new page, insert at the start
|
|
15
|
+
* - Update timestamps & firstEmptyIndex, then rerender
|
|
16
|
+
* - When exceeding pagesAllowed, delete pages and scroll back to anchor
|
|
13
17
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* if length exceeds pagesAllowed, we free up the pages and keep the first empty index in memory (firstEmptyIndex).
|
|
18
|
+
* ADDING NEW NODES:
|
|
19
|
+
* - If no pages exist, load old page
|
|
20
|
+
* - If on 1st page, append messages till page size is full and then load new page
|
|
18
21
|
*
|
|
19
|
-
*
|
|
20
|
-
* If
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* If we have exceeded our page allowance we delete old pages.
|
|
24
|
-
*
|
|
25
|
-
* In this case deleting pages is okay as we are not relying on the index of dom elements to detect page end.
|
|
26
|
-
*
|
|
27
|
-
* This also simplifies the code because when a user scrolls up we do not need to manage a lastEmptyIndex.
|
|
22
|
+
* DELETE NODE:
|
|
23
|
+
* - If deleting the only available node, reset to initial state
|
|
24
|
+
* - If page is empty, delete it
|
|
25
|
+
* - Update timestamp curors
|
|
28
26
|
*/
|
|
29
27
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
30
28
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -36,50 +34,34 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
36
34
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
37
35
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
38
36
|
};
|
|
39
|
-
import { Host, h
|
|
37
|
+
import { Host, h } from "@stencil/core";
|
|
40
38
|
import { defaultIconPack } from "../../lib/icons";
|
|
41
39
|
import { useLanguage } from "../../lib/lang";
|
|
42
40
|
import { SyncWithStore } from "../../utils/sync-with-store";
|
|
43
41
|
import { debounce } from "lodash-es";
|
|
44
42
|
export class RtkPaginatedList {
|
|
45
43
|
constructor() {
|
|
46
|
-
/**
|
|
47
|
-
* when scrolling up, we can't remove pages as intersectionObserver relies on
|
|
48
|
-
* the index of dom elements to stay stable.
|
|
49
|
-
* So, instead we free up the pages and keep the last empty index in memory.
|
|
50
|
-
*/
|
|
51
|
-
this.firstEmptyIndex = -1;
|
|
52
|
-
this.maxTS = 0;
|
|
53
44
|
// the length of pages will always be pageSize + 2
|
|
54
45
|
this.pages = [];
|
|
46
|
+
// Controls whether to keep auto-scrolling when a new page load.
|
|
47
|
+
this.shouldScrollToBottom = false;
|
|
48
|
+
// Shows "scroll to bottom" button when new nodes arrive and autoscroll is off.
|
|
49
|
+
this.showNewMessagesCTR = false;
|
|
55
50
|
/** label to show when empty */
|
|
56
51
|
this.emptyListLabel = null;
|
|
57
|
-
this.rerenderBoolean = false;
|
|
58
|
-
this.showEmptyListLabel = false;
|
|
59
52
|
/** Icon pack */
|
|
60
53
|
this.iconPack = defaultIconPack;
|
|
61
54
|
/** Language */
|
|
62
55
|
this.t = useLanguage();
|
|
56
|
+
this.rerenderBoolean = false;
|
|
57
|
+
this.showEmptyListLabel = false;
|
|
63
58
|
this.isLoading = false;
|
|
64
59
|
this.isLoadingTop = false;
|
|
65
60
|
this.isLoadingBottom = false;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* */
|
|
71
|
-
this.shouldScrollToBottom = false;
|
|
72
|
-
/** UI Indicator for the "scroll to bottom" button.
|
|
73
|
-
* Toggles on when a new node is added and autoscroll is disabled.
|
|
74
|
-
* Toggles off when all nodes are loaded */
|
|
75
|
-
this.showNewMessagesCTR = false;
|
|
76
|
-
this.observe = (el) => {
|
|
77
|
-
if (!el)
|
|
78
|
-
return;
|
|
79
|
-
this.intersectionObserver.observe(el);
|
|
80
|
-
};
|
|
81
|
-
this.isAtBottom = () => {
|
|
82
|
-
const rect = this.$bottomRef.getBoundingClientRect();
|
|
61
|
+
// Tells us if we need to scroll to a specific anchor after a rerender
|
|
62
|
+
this.pendingScrollAnchor = null;
|
|
63
|
+
this.isInView = (el) => {
|
|
64
|
+
const rect = el.getBoundingClientRect();
|
|
83
65
|
return rect.top >= 0 && rect.bottom <= window.innerHeight;
|
|
84
66
|
};
|
|
85
67
|
}
|
|
@@ -88,77 +70,57 @@ export class RtkPaginatedList {
|
|
|
88
70
|
* @param {DataNode} node - The data node to add to the beginning of the list
|
|
89
71
|
*/
|
|
90
72
|
async onNewNode(node) {
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.
|
|
73
|
+
// if there are no pages, load the first page
|
|
74
|
+
if (this.pages.length < 1) {
|
|
75
|
+
this.oldTS = node.timeMs + 1;
|
|
76
|
+
this.loadPrevPage();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// append messages to the page if page has not reached full capacity
|
|
80
|
+
if (this.pages[0].length < this.pageSize) {
|
|
81
|
+
this.pages[0].unshift(node);
|
|
82
|
+
this.newTS = node.timeMs;
|
|
83
|
+
this.rerender();
|
|
100
84
|
}
|
|
101
85
|
else {
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
this.pages[0].unshift(node);
|
|
105
|
-
this.newTS = node.timeMs;
|
|
106
|
-
this.rerender();
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
// if page is at full capacity, load next page
|
|
110
|
-
this.loadNextPage();
|
|
111
|
-
}
|
|
86
|
+
// if page is at full capacity, load next page
|
|
87
|
+
this.loadNextPage();
|
|
112
88
|
}
|
|
113
89
|
}
|
|
114
|
-
// If autoscroll is enabled,
|
|
90
|
+
// If autoscroll is enabled, scroll to the bottom
|
|
115
91
|
if (this.autoScroll) {
|
|
116
92
|
this.shouldScrollToBottom = true;
|
|
117
93
|
this.scrollToBottom();
|
|
118
94
|
}
|
|
119
|
-
else {
|
|
120
|
-
this.showNewMessagesCTR = true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// this method is called recursively based on shouldScrollToBottom (see scrollEnd listener)
|
|
124
|
-
scrollToBottom() {
|
|
125
|
-
this.$bottomRef.scrollIntoView({ behavior: 'smooth' });
|
|
126
95
|
}
|
|
127
96
|
/**
|
|
128
97
|
* Deletes a node anywhere from the list
|
|
129
98
|
* @param {string} id - The id of the node to delete
|
|
130
99
|
* */
|
|
131
100
|
async onNodeDelete(id) {
|
|
132
|
-
|
|
133
|
-
|
|
101
|
+
var _a, _b;
|
|
102
|
+
let didDelete = false;
|
|
103
|
+
for (let i = this.pages.length - 1; i >= 0; i--) {
|
|
134
104
|
const index = this.pages[i].findIndex((node) => node.id === id);
|
|
135
|
-
// message
|
|
136
|
-
if (index
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// if newest page is empty, update first empty index
|
|
146
|
-
if (this.pages[i].length === 0)
|
|
147
|
-
this.firstEmptyIndex++;
|
|
148
|
-
// update timestamp, first empty index could be -1, so we need to cap it at 0
|
|
149
|
-
this.newTS = this.pages[Math.max(this.firstEmptyIndex, 0)][0].timeMs;
|
|
150
|
-
}
|
|
151
|
-
else if (i === this.firstEmptyIndex + this.pagesAllowed) {
|
|
152
|
-
// if oldest page is empty, remove it
|
|
153
|
-
if (this.pages[i].length === 0)
|
|
154
|
-
this.pages.pop();
|
|
155
|
-
// update timestamp
|
|
156
|
-
const lastPage = this.pages[this.firstEmptyIndex + this.pagesAllowed];
|
|
157
|
-
this.oldTS = lastPage[lastPage.length - 1].timeMs;
|
|
158
|
-
}
|
|
159
|
-
this.rerender();
|
|
160
|
-
}
|
|
105
|
+
// if message not found, move on
|
|
106
|
+
if (index === -1)
|
|
107
|
+
continue;
|
|
108
|
+
// delete message
|
|
109
|
+
this.pages[i].splice(index, 1);
|
|
110
|
+
// if page is empty, delete it
|
|
111
|
+
if (this.pages[i].length === 0)
|
|
112
|
+
this.pages.splice(i, 1);
|
|
113
|
+
didDelete = true;
|
|
114
|
+
break;
|
|
161
115
|
}
|
|
116
|
+
if (!didDelete)
|
|
117
|
+
return;
|
|
118
|
+
// update timestamps
|
|
119
|
+
const firstPage = this.pages[0];
|
|
120
|
+
const lastPage = this.pages[this.pages.length - 1];
|
|
121
|
+
this.newTS = (_a = firstPage === null || firstPage === void 0 ? void 0 : firstPage[0]) === null || _a === void 0 ? void 0 : _a.timeMs;
|
|
122
|
+
this.oldTS = (_b = lastPage === null || lastPage === void 0 ? void 0 : lastPage[lastPage.length - 1]) === null || _b === void 0 ? void 0 : _b.timeMs;
|
|
123
|
+
this.rerender();
|
|
162
124
|
}
|
|
163
125
|
/**
|
|
164
126
|
* Updates a new node anywhere in the list
|
|
@@ -166,146 +128,182 @@ export class RtkPaginatedList {
|
|
|
166
128
|
* @param {DataNode} _node - The updated data node
|
|
167
129
|
* */
|
|
168
130
|
async onNodeUpdate(_id, _node) { }
|
|
169
|
-
rerender() {
|
|
170
|
-
this.rerenderBoolean = !this.rerenderBoolean;
|
|
171
|
-
}
|
|
172
131
|
connectedCallback() {
|
|
173
132
|
this.rerender = debounce(this.rerender.bind(this), 50, { maxWait: 200 });
|
|
174
|
-
this.intersectionObserver = new IntersectionObserver((entries) => {
|
|
175
|
-
writeTask(async () => {
|
|
176
|
-
for (const entry of entries) {
|
|
177
|
-
if (entry.target.id === 'top-scroll' && entry.isIntersecting) {
|
|
178
|
-
this.isLoadingTop = true;
|
|
179
|
-
await this.loadPrevPage();
|
|
180
|
-
this.isLoadingTop = false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
133
|
}
|
|
186
134
|
componentDidLoad() {
|
|
187
|
-
|
|
135
|
+
// initial load
|
|
136
|
+
this.loadPrevPage();
|
|
188
137
|
if (this.$containerRef) {
|
|
189
138
|
this.$containerRef.onscrollend = async () => {
|
|
190
|
-
|
|
191
|
-
* Load new page if:
|
|
192
|
-
* if there are nodes to load at the bottom (maxTS > newTS)
|
|
193
|
-
* or if there are pages to fill at the bottom (firstEmptyIndex > -1)
|
|
194
|
-
*/
|
|
195
|
-
if (this.isAtBottom() && (this.maxTS > this.newTS || this.firstEmptyIndex > -1)) {
|
|
196
|
-
this.isLoadingBottom = true;
|
|
139
|
+
if (this.isInView(this.$bottomRef)) {
|
|
197
140
|
await this.loadNextPage();
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
141
|
+
}
|
|
142
|
+
else if (this.isInView(this.$topRef)) {
|
|
143
|
+
this.showNewMessagesCTR = true;
|
|
144
|
+
await this.loadPrevPage();
|
|
201
145
|
}
|
|
202
146
|
};
|
|
203
147
|
}
|
|
204
148
|
}
|
|
149
|
+
componentDidRender() {
|
|
150
|
+
if (!this.pendingScrollAnchor)
|
|
151
|
+
return;
|
|
152
|
+
const anchor = this.pendingScrollAnchor;
|
|
153
|
+
this.pendingScrollAnchor = null;
|
|
154
|
+
this.restoreScrollToAnchor(anchor);
|
|
155
|
+
}
|
|
205
156
|
async loadPrevPage() {
|
|
206
157
|
if (this.isLoading)
|
|
207
158
|
return;
|
|
208
|
-
|
|
209
|
-
* NOTE(ikabra): this case also runs on initial load
|
|
210
|
-
* if scrolling up ->
|
|
211
|
-
* fetch older messages and push to the end of the array
|
|
212
|
-
* cleanup 1st non empty page from the array if length exceeds pagesAllowed
|
|
213
|
-
*/
|
|
159
|
+
const scrollAnchor = this.getScrollAnchor('top');
|
|
214
160
|
// if no old timestamp, it means we are at initial state
|
|
215
161
|
if (!this.oldTS)
|
|
216
162
|
this.oldTS = new Date().getTime();
|
|
217
163
|
// load data
|
|
218
164
|
this.isLoading = true;
|
|
165
|
+
this.isLoadingTop = true;
|
|
219
166
|
const data = await this.fetchData(this.oldTS - 1, this.pageSize, true);
|
|
220
167
|
this.isLoading = false;
|
|
168
|
+
this.isLoadingTop = false;
|
|
221
169
|
// no more old messages to show, we are at the top of the page
|
|
222
170
|
if (!data.length)
|
|
223
171
|
return;
|
|
224
172
|
// add old data to the end of the array
|
|
225
173
|
this.pages.push(data);
|
|
226
174
|
// clear old pages when we reach the limit
|
|
227
|
-
if (this.pages.length > this.pagesAllowed)
|
|
228
|
-
this.pages
|
|
229
|
-
|
|
230
|
-
* find last non empty page in range (this.pages.length, this.firstEmptyIndex)
|
|
231
|
-
* we are doing this because any of the middle pages in the currently rendered pages
|
|
232
|
-
* could be empty as we allow deleting messages.
|
|
233
|
-
* This helps us set the first empty index correctly.
|
|
234
|
-
*/
|
|
235
|
-
for (let i = this.firstEmptyIndex + 1; i < this.pages.length; i++) {
|
|
236
|
-
if (this.pages[i].length > 0)
|
|
237
|
-
break;
|
|
238
|
-
this.firstEmptyIndex = i;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// update the old timestamp
|
|
175
|
+
if (this.pages.length > this.pagesAllowed)
|
|
176
|
+
this.pages.shift();
|
|
177
|
+
// update timestamps
|
|
242
178
|
const lastPage = this.pages[this.pages.length - 1];
|
|
243
179
|
this.oldTS = lastPage[lastPage.length - 1].timeMs;
|
|
244
|
-
|
|
245
|
-
this.newTS = this.pages[this.firstEmptyIndex + 1][0].timeMs;
|
|
180
|
+
this.newTS = this.pages[0][0].timeMs;
|
|
246
181
|
this.rerender();
|
|
182
|
+
// fix scroll position
|
|
183
|
+
if (scrollAnchor)
|
|
184
|
+
this.pendingScrollAnchor = scrollAnchor;
|
|
247
185
|
}
|
|
248
186
|
async loadNextPage() {
|
|
249
187
|
if (this.isLoading)
|
|
250
188
|
return;
|
|
251
|
-
//
|
|
189
|
+
// Do nothing. New timestamp needs to be assigned by loadPrevPage method
|
|
252
190
|
if (!this.newTS) {
|
|
253
191
|
this.showNewMessagesCTR = false;
|
|
254
192
|
this.shouldScrollToBottom = false;
|
|
255
193
|
return;
|
|
256
194
|
}
|
|
257
|
-
//
|
|
195
|
+
// for autoscroll or scroll to bottom button
|
|
196
|
+
const maxAutoLoads = 200;
|
|
197
|
+
let loads = 0;
|
|
198
|
+
let prevNewTS = this.newTS;
|
|
258
199
|
this.isLoading = true;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.
|
|
264
|
-
this.
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
this.pages[this.firstEmptyIndex] = data.reverse();
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
// when already at the bottom and loading messages in realtime
|
|
200
|
+
this.isLoadingBottom = true;
|
|
201
|
+
while (loads < maxAutoLoads) {
|
|
202
|
+
const scrollAnchor = this.getScrollAnchor('bottom');
|
|
203
|
+
const data = await this.fetchData(this.newTS + 1, this.pageSize, false);
|
|
204
|
+
this.isLoading = false;
|
|
205
|
+
this.isLoadingBottom = false;
|
|
206
|
+
// no more new messages to load
|
|
207
|
+
if (!data.length) {
|
|
208
|
+
this.showNewMessagesCTR = false;
|
|
209
|
+
this.shouldScrollToBottom = false;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
// load new messages and append to the start
|
|
276
213
|
this.pages.unshift(data.reverse());
|
|
214
|
+
// remove pages if out of bounds
|
|
215
|
+
if (this.pages.length > this.pagesAllowed)
|
|
216
|
+
this.pages.pop();
|
|
217
|
+
// update timestamps
|
|
218
|
+
const lastPage = this.pages[this.pages.length - 1];
|
|
219
|
+
this.oldTS = lastPage[lastPage.length - 1].timeMs;
|
|
220
|
+
this.newTS = this.pages[0][0].timeMs;
|
|
221
|
+
this.rerender();
|
|
222
|
+
this.pendingScrollAnchor = scrollAnchor;
|
|
223
|
+
if (!this.shouldScrollToBottom)
|
|
224
|
+
break;
|
|
225
|
+
// if should scroll to bottom then retrigger
|
|
226
|
+
await this.waitForNextFrame();
|
|
227
|
+
this.scrollToBottom();
|
|
228
|
+
await this.waitForNextFrame();
|
|
229
|
+
// if no new messages, break
|
|
230
|
+
if (this.newTS === prevNewTS)
|
|
231
|
+
break;
|
|
232
|
+
prevNewTS = this.newTS;
|
|
233
|
+
loads++;
|
|
277
234
|
}
|
|
278
|
-
|
|
279
|
-
|
|
235
|
+
}
|
|
236
|
+
// Find the element that is closest to the top/bottom of the container
|
|
237
|
+
getScrollAnchor(edge = 'top') {
|
|
238
|
+
if (!this.$containerRef)
|
|
239
|
+
return null;
|
|
240
|
+
const containerRect = this.$containerRef.getBoundingClientRect();
|
|
241
|
+
const candidates = Array.from(this.$containerRef.querySelectorAll('[id]')).filter((el) => el.id !== 'top-scroll' && el.id !== 'bottom-scroll');
|
|
242
|
+
let best = null;
|
|
243
|
+
for (const el of candidates) {
|
|
244
|
+
const rect = el.getBoundingClientRect();
|
|
245
|
+
const isVisibleInContainer = rect.bottom > containerRect.top && rect.top < containerRect.bottom;
|
|
246
|
+
if (!isVisibleInContainer)
|
|
247
|
+
continue;
|
|
248
|
+
if (edge === 'top') {
|
|
249
|
+
const offsetTop = rect.top - containerRect.top;
|
|
250
|
+
if (best == null || (best.edge === 'top' && offsetTop < best.offsetTop)) {
|
|
251
|
+
best = { id: el.id, edge: 'top', offsetTop };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const offsetBottom = containerRect.bottom - rect.bottom;
|
|
256
|
+
if (best == null || (best.edge === 'bottom' && offsetBottom < best.offsetBottom)) {
|
|
257
|
+
best = { id: el.id, edge: 'bottom', offsetBottom };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
280
260
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
261
|
+
return best;
|
|
262
|
+
}
|
|
263
|
+
//instant scroll to anchor to make sure we are at the same position after a rerender
|
|
264
|
+
restoreScrollToAnchor(anchor) {
|
|
265
|
+
if (!this.$containerRef)
|
|
266
|
+
return;
|
|
267
|
+
// make element id safe to use inside a CSS selector
|
|
268
|
+
const escapeId = (id) => {
|
|
269
|
+
var _a;
|
|
270
|
+
const cssEscape = (_a = globalThis.CSS) === null || _a === void 0 ? void 0 : _a.escape;
|
|
271
|
+
return typeof cssEscape === 'function'
|
|
272
|
+
? cssEscape(id)
|
|
273
|
+
: id.replace(/[^a-zA-Z0-9_-]/g, '\\$&');
|
|
274
|
+
};
|
|
275
|
+
const el = this.$containerRef.querySelector(`#${escapeId(anchor.id)}`);
|
|
276
|
+
if (!el)
|
|
277
|
+
return;
|
|
278
|
+
const containerRect = this.$containerRef.getBoundingClientRect();
|
|
279
|
+
const rect = el.getBoundingClientRect();
|
|
280
|
+
if (anchor.edge === 'top') {
|
|
281
|
+
const newOffsetTop = rect.top - containerRect.top;
|
|
282
|
+
this.$containerRef.scrollTop += newOffsetTop - anchor.offsetTop;
|
|
289
283
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this.
|
|
298
|
-
|
|
284
|
+
else {
|
|
285
|
+
const newOffsetBottom = containerRect.bottom - rect.bottom;
|
|
286
|
+
this.$containerRef.scrollTop += anchor.offsetBottom - newOffsetBottom;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// this method is called recursively based on shouldScrollToBottom (see loadNextPage)
|
|
290
|
+
scrollToBottom() {
|
|
291
|
+
this.$bottomRef.scrollIntoView({ behavior: 'smooth' });
|
|
292
|
+
}
|
|
293
|
+
waitForNextFrame() {
|
|
294
|
+
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
295
|
+
}
|
|
296
|
+
rerender() {
|
|
297
|
+
this.rerenderBoolean = !this.rerenderBoolean;
|
|
299
298
|
}
|
|
300
299
|
render() {
|
|
301
300
|
/**
|
|
302
|
-
* div.container is flex=column-
|
|
303
|
-
* which is why div#bottom-scroll comes before div#top-scroll
|
|
301
|
+
* div.container is flex=column-reversewhich is why div#bottom-scroll comes before div#top-scroll
|
|
304
302
|
*/
|
|
305
|
-
return (h(Host, { key: '
|
|
303
|
+
return (h(Host, { key: 'e0f806cccdcba162d0c834476863b34630cb1a1e' }, h("div", { key: '6d54d50ed703a59df8d26399499533e3cb0d70fe', class: "scrollbar container", part: "container", ref: (el) => (this.$containerRef = el) }, h("div", { key: '4e9fcbed725fb55d9fbb67eca94b0e770662d51b', class: { 'show-new-messages-ctr': true, active: this.showNewMessagesCTR } }, h("rtk-button", { key: '7db0236d35db3fb9856fea7a4f62c1fbd421829e', class: "show-new-messages", kind: "icon", variant: "secondary", part: "show-new-messages", onClick: () => {
|
|
306
304
|
this.shouldScrollToBottom = true;
|
|
307
305
|
this.scrollToBottom();
|
|
308
|
-
} }, h("rtk-icon", { key: '
|
|
306
|
+
} }, h("rtk-icon", { key: '6e247e86029560601080e0b4d6dcfccbd90fcdd6', icon: this.iconPack.chevron_down }))), h("div", { key: '01d1ba7eacc67ece70b805fb2dfb493cdf1c9d23', class: "smallest-dom-element", id: "bottom-scroll", ref: (el) => (this.$bottomRef = el) }), this.isLoadingBottom && this.pages.length > 0 && h("rtk-spinner", { key: '24391bfc34914675cbfd0c287332bfdf3f5f5000', size: "sm" }), this.isLoading && this.pages.length < 1 && h("rtk-spinner", { key: 'e6c2cb44fce52ca54c9f1e543d91a29648745408', size: "lg" }), !this.isLoading && this.pages.flat().length === 0 ? (h("div", { class: "empty-list" }, this.t('list.empty'))) : (h("div", { class: "page-wrapper" }, this.pages.map((page, pageIndex) => (h("div", { class: "page", "data-page-index": pageIndex }, this.createNodes([...page].reverse())))))), this.isLoadingTop && this.pages.length > 0 && h("rtk-spinner", { key: 'd90a15494bcd7ec6c9c7ffc5e9a55054252a4258', size: "sm" }), h("div", { key: '2a65f98c3c4e6f2510c6cf1b4e2bcf1e607a7552', class: "smallest-dom-element", id: "top-scroll", ref: (el) => (this.$topRef = el) }))));
|
|
309
307
|
}
|
|
310
308
|
static get is() { return "rtk-paginated-list"; }
|
|
311
309
|
static get encapsulation() { return "shadow"; }
|
|
@@ -7,7 +7,7 @@ import { d as defineCustomElement$m } from './p-241a8245.js';
|
|
|
7
7
|
import { d as defineCustomElement$l } from './p-1391bef0.js';
|
|
8
8
|
import { d as defineCustomElement$k } from './p-a73665b4.js';
|
|
9
9
|
import { d as defineCustomElement$j } from './p-28170a8d.js';
|
|
10
|
-
import { d as defineCustomElement$i } from './p-
|
|
10
|
+
import { d as defineCustomElement$i } from './p-7be71567.js';
|
|
11
11
|
import { d as defineCustomElement$h } from './p-1f5a4682.js';
|
|
12
12
|
import { d as defineCustomElement$g } from './p-598dc3f2.js';
|
|
13
13
|
import { d as defineCustomElement$f } from './p-0e5cc539.js';
|
|
@@ -20,7 +20,7 @@ import { d as defineCustomElement$9 } from './p-2447a26f.js';
|
|
|
20
20
|
import { d as defineCustomElement$8 } from './p-819cb785.js';
|
|
21
21
|
import { d as defineCustomElement$7 } from './p-7148ec6a.js';
|
|
22
22
|
import { d as defineCustomElement$6 } from './p-0f2de0f8.js';
|
|
23
|
-
import { d as defineCustomElement$5 } from './p-
|
|
23
|
+
import { d as defineCustomElement$5 } from './p-7f8d9afc.js';
|
|
24
24
|
import { d as defineCustomElement$4 } from './p-4ebf9684.js';
|
|
25
25
|
import { d as defineCustomElement$3 } from './p-4902c5cf.js';
|
|
26
26
|
import { d as defineCustomElement$2 } from './p-6739a399.js';
|
|
@@ -11,7 +11,7 @@ import { d as defineCustomElement$7 } from './p-2447a26f.js';
|
|
|
11
11
|
import { d as defineCustomElement$6 } from './p-819cb785.js';
|
|
12
12
|
import { d as defineCustomElement$5 } from './p-7148ec6a.js';
|
|
13
13
|
import { d as defineCustomElement$4 } from './p-0f2de0f8.js';
|
|
14
|
-
import { d as defineCustomElement$3 } from './p-
|
|
14
|
+
import { d as defineCustomElement$3 } from './p-7f8d9afc.js';
|
|
15
15
|
import { d as defineCustomElement$2 } from './p-4ebf9684.js';
|
|
16
16
|
import { d as defineCustomElement$1 } from './p-6739a399.js';
|
|
17
17
|
|
|
@@ -142,7 +142,7 @@ const RtkChatMessagesUiPaginated = /*@__PURE__*/ proxyCustomElement(class RtkCha
|
|
|
142
142
|
}
|
|
143
143
|
const isSelf = message.userId === this.meeting.self.userId;
|
|
144
144
|
const viewType = isSelf ? 'outgoing' : 'incoming';
|
|
145
|
-
return (h("div", null, h("div", { class: "message-wrapper" }, h("rtk-message-view", { pinned: message.pinned, time: message.time, actions: this.getMessageActions(message), authorName: message.displayName, isSelf: isSelf, avatarUrl: displayPicture, hideAuthorName: isContinued, viewType: viewType, variant: "bubble", onAction: (event) => this.onMessageActionHandler(event.detail, message) }, h("div", null, h("div", { class: "body" }, message.type === 'text' && (h("rtk-text-message-view", { text: message.message, isMarkdown: true })), message.type === 'file' && (h("rtk-file-message-view", { name: message.name, url: message.link, size: message.size })), message.type === 'image' && (h("rtk-image-message-view", { url: message.link, onPreview: () => {
|
|
145
|
+
return (h("div", null, h("div", { class: "message-wrapper", id: message.id }, h("rtk-message-view", { pinned: message.pinned, time: message.time, actions: this.getMessageActions(message), authorName: message.displayName, isSelf: isSelf, avatarUrl: displayPicture, hideAuthorName: isContinued, viewType: viewType, variant: "bubble", onAction: (event) => this.onMessageActionHandler(event.detail, message) }, h("div", null, h("div", { class: "body" }, message.type === 'text' && (h("rtk-text-message-view", { text: message.message, isMarkdown: true })), message.type === 'file' && (h("rtk-file-message-view", { name: message.name, url: message.link, size: message.size })), message.type === 'image' && (h("rtk-image-message-view", { url: message.link, onPreview: () => {
|
|
146
146
|
this.stateUpdate.emit({ image: message });
|
|
147
147
|
} }))))))));
|
|
148
148
|
};
|
|
@@ -190,7 +190,7 @@ const RtkChatMessagesUiPaginated = /*@__PURE__*/ proxyCustomElement(class RtkCha
|
|
|
190
190
|
this.lastReadMessageIndex = -1;
|
|
191
191
|
}
|
|
192
192
|
render() {
|
|
193
|
-
return (h(Host, { key: '
|
|
193
|
+
return (h(Host, { key: 'c710da6e2fda420146905a2ed75d3444dd6d2c0b' }, h("rtk-paginated-list", { key: '51a36437e38e9c0242cca34bfda39f6d8309bee3', ref: (el) => (this.$paginatedListRef = el), pageSize: this.pageSize, pagesAllowed: 3, fetchData: this.getChatMessages, createNodes: this.createChatNodes, selectedItemId: this.selectedChannelId, emptyListLabel: this.t('chat.empty_channel') }, h("slot", { key: '69b54a41263510b425ce3e39af055321c4e2deb8' }))));
|
|
194
194
|
}
|
|
195
195
|
get host() { return this; }
|
|
196
196
|
static get watchers() { return {
|