fubi 0.1.2 → 0.1.4

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.
@@ -0,0 +1,31 @@
1
+ import { b as n, l as a, i as d, h as c, e as r } from "./index-Ckde0azm.js";
2
+ const s = "keys";
3
+ class l {
4
+ init() {
5
+ return this.handleKeyDown = this.handleKeyDown.bind(this), n.on("auth", "authenticated", () => u.listenForKeys()), a.ok(s, "initialized"), this;
6
+ }
7
+ listenForKeys() {
8
+ document.addEventListener("keydown", this.handleKeyDown);
9
+ }
10
+ removeKeyListener() {
11
+ document.removeEventListener("keydown", this.handleKeyDown);
12
+ }
13
+ handleKeyDown(i) {
14
+ const { key: t } = i, o = d();
15
+ if (t === "Escape") {
16
+ const e = document.activeElement;
17
+ e && e !== document.body && e.blur(), n.emit(s, "pressed-esc", { isolation: c.current !== null });
18
+ return;
19
+ }
20
+ if (!o)
21
+ switch (t) {
22
+ case "c":
23
+ r.opened || n.emit(s, "pressed-c");
24
+ break;
25
+ }
26
+ }
27
+ }
28
+ const u = new l();
29
+ export {
30
+ u as keys
31
+ };
@@ -0,0 +1,116 @@
1
+ var $ = Object.defineProperty;
2
+ var w = (s) => {
3
+ throw TypeError(s);
4
+ };
5
+ var L = (s, t, e) => t in s ? $(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
6
+ var j = (s, t, e) => L(s, typeof t != "symbol" ? t + "" : t, e), k = (s, t, e) => t.has(s) || w("Cannot " + e);
7
+ var i = (s, t, e) => (k(s, t, "read from private field"), e ? e.call(s) : t.get(s)), c = (s, t, e) => t.has(s) ? w("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, e);
8
+ import { s as x, p as m, g as o, a as _, d as y, b as N, l as r, c as d, e as b, f as u } from "./index-Ckde0azm.js";
9
+ const n = "notifications";
10
+ var h, p, f, g, l;
11
+ class D {
12
+ constructor() {
13
+ c(this, h, x(m([])));
14
+ c(this, p, y(() => this.data.filter((t) => t.created_by === d.user.id && (t.updated_by === d.user.id || !t.updated_by) || t.updated_by === d.user.id && t.done === !0)));
15
+ c(this, f, y(() => this.data.filter((t) => t.created_by === d.user.id)));
16
+ c(this, g, y(() => this.data.filter((t) => t.updated_by === d.user.id)));
17
+ c(this, l, x(null));
18
+ j(this, "subscribed", !1);
19
+ }
20
+ get data() {
21
+ return o(i(this, h));
22
+ }
23
+ set data(t) {
24
+ _(i(this, h), m(t));
25
+ }
26
+ get mine() {
27
+ return o(i(this, p));
28
+ }
29
+ get created() {
30
+ return o(i(this, f));
31
+ }
32
+ get updated() {
33
+ return o(i(this, g));
34
+ }
35
+ get latest() {
36
+ return o(i(this, l));
37
+ }
38
+ set latest(t) {
39
+ _(i(this, l), m(t));
40
+ }
41
+ init() {
42
+ return N.on("app", "started", async () => !this.subscribed && await this.get()), r.ok(n, "initialized"), this;
43
+ }
44
+ crud(t, e) {
45
+ switch (t) {
46
+ case "create":
47
+ this.data.push(e);
48
+ break;
49
+ case "update":
50
+ this.data = this.data.map((a) => a.id === e.id ? e : a);
51
+ break;
52
+ case "delete":
53
+ this.data = this.data.filter((a) => a.id !== e.id);
54
+ break;
55
+ }
56
+ }
57
+ async createNotification() {
58
+ this.unsubscribe();
59
+ const t = {
60
+ project: b.project.id,
61
+ created_by: d.user.id
62
+ }, { result: e, error: a } = await u("notifications").create(t);
63
+ a ? r.error(n, "Error creating notification", a) : (r.ok(n, "Created notification", e), this.latest = e), this.subscribe();
64
+ }
65
+ async getLatestNotification() {
66
+ const { result: t, error: e } = await u("notifications").getList(-1, -1, {
67
+ filter: `created_by = "${d.user.id}" && project = "${b.project.id}"`,
68
+ sort: "-created"
69
+ });
70
+ e ? this.latest = null : this.latest = t.items[0];
71
+ }
72
+ async get() {
73
+ await this.getLatestNotification();
74
+ let t = `page.project = "${b.project.id}"`;
75
+ this.latest && (t += ` && (created >= "${this.latest.created}" || updated >= "${this.latest.created}")`);
76
+ const { result: e, error: a } = await u("threads").getList(-1, -1, {
77
+ filter: t,
78
+ sort: "-created",
79
+ expand: "page, comments(thread)"
80
+ });
81
+ if (a) {
82
+ r.error(n, "Error getting notifications", a);
83
+ return;
84
+ } else
85
+ this.data = e.items, this.subscribe();
86
+ }
87
+ async subscribe() {
88
+ this.subscribed = !0, r.info(n, "Subscribing to threads");
89
+ let t = `page.project = "${b.project.id}"`;
90
+ this.latest && (r.info(n, "Last time you notify the team: ", this.latest.created), t += ` && (created >= "${this.latest.created}" || updated >= "${this.latest.created}")`), u("threads").subscribe(
91
+ "*",
92
+ (e) => {
93
+ this.crud(e.action, e.record);
94
+ },
95
+ {
96
+ filter: t,
97
+ expand: "page,comments(thread)",
98
+ requestKey: "notifications"
99
+ }
100
+ );
101
+ }
102
+ reset() {
103
+ this.data = [], this.latest = null;
104
+ }
105
+ async unsubscribe() {
106
+ this.reset(), this.subscribed = !1, r.info(n, "Unsubscribing from threads"), u("threads").unsubscribe("*");
107
+ }
108
+ hasNewComments(t) {
109
+ return !t.expand || !t.expand["comments(thread)"] ? !1 : this.latest ? t.expand["comments(thread)"].some((e) => new Date(e.created) > new Date(this.latest.created)) : t.expand["comments(thread)"].length > 0;
110
+ }
111
+ }
112
+ h = new WeakMap(), p = new WeakMap(), f = new WeakMap(), g = new WeakMap(), l = new WeakMap();
113
+ const U = new D();
114
+ export {
115
+ U as notifications
116
+ };