@fabriktor/fx 0.0.181 → 0.0.183

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/README.md CHANGED
@@ -14,15 +14,6 @@
14
14
  This package is designed exclusively for Fabriktor's frontend operational needs and is
15
15
  not intended for public usage.
16
16
 
17
- Notification inbox searches validate the owner and use shared pagination with
18
- optional read-state, category, and key filters. Marking a notification as read
19
- uses the Client CRUD update and publishes `NotificationsEvents.Read` through
20
- the shared event bus after success, allowing consumers to refresh their inbox.
21
-
22
- `NotificationInboxController` shares paginated results and global unread status,
23
- coalesces push refreshes, coordinates read updates, and discards requests when
24
- the owner changes. Consumers bind its state and supply browser lifecycle events.
25
-
26
17
  ---
27
18
 
28
19
  ## License
@@ -0,0 +1,23 @@
1
+ import type { Chat } from "@fabriktor/schema";
2
+ export type ChatScrollOptions = {
3
+ readonly owner_id: string;
4
+ readonly room_id: string;
5
+ readonly enabled: boolean;
6
+ readonly loading: boolean;
7
+ readonly chats: readonly Pick<Chat, "id" | "owner_id" | "created_at">[];
8
+ };
9
+ export type ChatScrollState = {
10
+ readonly away: boolean;
11
+ readonly has_new_messages: boolean;
12
+ };
13
+ /** Reading position belongs to the user; receipts and outgoing confirmations never reclaim it. */
14
+ export declare class ChatScrollController {
15
+ private context;
16
+ private ids;
17
+ private oldest;
18
+ private initialized;
19
+ private value;
20
+ get state(): ChatScrollState;
21
+ update(opts: ChatScrollOptions): boolean;
22
+ setAway(away: boolean): void;
23
+ }
@@ -0,0 +1,52 @@
1
+ import { isOptimisticChat } from "./optimistic.js";
2
+ /** Reading position belongs to the user; receipts and outgoing confirmations never reclaim it. */
3
+ export class ChatScrollController {
4
+ context;
5
+ ids = new Set();
6
+ oldest = Infinity;
7
+ initialized = false;
8
+ value = { away: false, has_new_messages: false };
9
+ get state() {
10
+ return this.value;
11
+ }
12
+ update(opts) {
13
+ const reset = opts.owner_id !== this.context?.owner_id ||
14
+ opts.room_id !== this.context?.room_id ||
15
+ opts.enabled !== this.context?.enabled;
16
+ this.context = opts;
17
+ if (reset) {
18
+ this.ids.clear();
19
+ this.oldest = Infinity;
20
+ this.initialized = false;
21
+ this.value = { away: false, has_new_messages: false };
22
+ }
23
+ if (!opts.enabled || opts.loading || !opts.room_id || !opts.owner_id)
24
+ return reset;
25
+ const oldest = this.oldest;
26
+ for (const chat of opts.chats) {
27
+ if (isOptimisticChat(chat))
28
+ continue;
29
+ const created = Date.parse(chat.created_at);
30
+ if (this.initialized &&
31
+ this.value.away &&
32
+ chat.owner_id !== opts.owner_id &&
33
+ !this.ids.has(chat.id) &&
34
+ Number.isFinite(created) &&
35
+ (oldest === Infinity || created >= oldest)) {
36
+ this.value = { away: true, has_new_messages: true };
37
+ }
38
+ this.ids.add(chat.id);
39
+ // Pagination precedes the loaded window; a delayed live message can land inside it.
40
+ if (Number.isFinite(created))
41
+ this.oldest = Math.min(this.oldest, created);
42
+ }
43
+ this.initialized = true;
44
+ return reset;
45
+ }
46
+ setAway(away) {
47
+ this.value = {
48
+ away,
49
+ has_new_messages: away && this.value.has_new_messages,
50
+ };
51
+ }
52
+ }
@@ -6,6 +6,7 @@ export * from "./chat/chat.js";
6
6
  export * from "./chat/data.js";
7
7
  export * from "./chat/forms.js";
8
8
  export * from "./chat/optimistic.js";
9
+ export * from "./chat/scroll.js";
9
10
  export * from "./chat/send-queue.js";
10
11
  export * from "./contacts/contacts.js";
11
12
  export * from "./contacts/scope.js";
package/dist/src/index.js CHANGED
@@ -6,6 +6,7 @@ export * from "./chat/chat.js";
6
6
  export * from "./chat/data.js";
7
7
  export * from "./chat/forms.js";
8
8
  export * from "./chat/optimistic.js";
9
+ export * from "./chat/scroll.js";
9
10
  export * from "./chat/send-queue.js";
10
11
  export * from "./contacts/contacts.js";
11
12
  export * from "./contacts/scope.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.181",
3
+ "version": "0.0.183",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {