@nylas/react 1.1.0-canary.9 → 1.1.1
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 +110 -2
- package/dist/add-circle-icon_2.entry-b14ecb5c.js +25 -0
- package/dist/add-circle-icon_2.entry-c6211866.cjs +1 -0
- package/dist/archive-icon_7.entry-3fe7721a.js +75 -0
- package/dist/archive-icon_7.entry-54fc1f03.cjs +1 -0
- package/dist/arrow-icon.entry-1dfee3bc.cjs +1 -0
- package/dist/arrow-icon.entry-cc936041.js +15 -0
- package/dist/bold-icon_3.entry-4b9de887.cjs +1 -0
- package/dist/bold-icon_3.entry-e2a1d434.js +35 -0
- package/dist/button-component_2.entry-3639ade6.js +26 -0
- package/dist/button-component_2.entry-5666fdfa.cjs +1 -0
- package/dist/calendar-agenda-fill-icon_48.entry-56e364cd.js +5256 -0
- package/dist/calendar-agenda-fill-icon_48.entry-bf278e34.cjs +7 -0
- package/dist/calendar-cancel-icon.entry-ac1cb5dd.cjs +1 -0
- package/dist/calendar-cancel-icon.entry-dcd777cd.js +15 -0
- package/dist/calendar-check-icon_2.entry-6330bd2d.js +25 -0
- package/dist/calendar-check-icon_2.entry-7ad1b2a0.cjs +1 -0
- package/dist/calendar-icon.entry-5849a547.cjs +1 -0
- package/dist/calendar-icon.entry-8559fa0d.js +15 -0
- package/dist/checkbox-component_2.entry-1474c465.js +79 -0
- package/dist/checkbox-component_2.entry-6cf5da6b.cjs +1 -0
- package/dist/chevron-icon_3.entry-41170718.cjs +1 -0
- package/dist/chevron-icon_3.entry-cb757aa3.js +132 -0
- package/dist/clock-icon_4.entry-36a33de5.cjs +1 -0
- package/dist/clock-icon_4.entry-642f4dc6.js +45 -0
- package/dist/constants-50c3e067-4e027da4.cjs +15 -0
- package/dist/constants-50c3e067-83f1d865.js +3883 -0
- package/dist/copy-icon.entry-60740516.js +15 -0
- package/dist/copy-icon.entry-fb63cf53.cjs +1 -0
- package/dist/core-js-38e53e34.cjs +4 -0
- package/dist/core-js-a9d3b6e1.js +3297 -0
- package/dist/delete-icon_2.entry-45851bc5.js +25 -0
- package/dist/delete-icon_2.entry-d1af0606.cjs +1 -0
- package/dist/document-refresh-icon.entry-1731d4d9.cjs +1 -0
- package/dist/document-refresh-icon.entry-5db0830a.js +15 -0
- package/dist/dom-68f08be9.cjs +15 -0
- package/dist/dom-86e17616.js +664 -0
- package/dist/{types/elements → elements}/index.d.ts +48 -1
- package/dist/elements-dc5b338e-3099ee02.js +28031 -0
- package/dist/elements-dc5b338e-ab9afb63.cjs +16516 -0
- package/dist/flow-40ff9cea-6f8c30e2.cjs +9 -0
- package/dist/flow-40ff9cea-ee70fdf5.js +505 -0
- package/dist/focus-visible-e8093c16-067a8f23.js +84 -0
- package/dist/focus-visible-e8093c16-811f50fa.cjs +1 -0
- package/dist/forward-icon_6.entry-4e9c9686.cjs +3 -0
- package/dist/forward-icon_6.entry-e7c5fa46.js +953 -0
- package/dist/globe-icon.entry-74f79652.cjs +1 -0
- package/dist/globe-icon.entry-aa3f3ea3.js +15 -0
- package/dist/google-logo-icon_4.entry-0332a181.cjs +1 -0
- package/dist/google-logo-icon_4.entry-3fe41d69.js +673 -0
- package/dist/index-2a53b6a8.cjs +82 -0
- package/dist/index-a134f625.js +12842 -0
- package/dist/index.es-79f5b771-64a1baf0.cjs +7 -0
- package/dist/index.es-79f5b771-ce07d6fc.js +3135 -0
- package/dist/info-icon_2.entry-a3f40027.cjs +1 -0
- package/dist/info-icon_2.entry-fed731f4.js +34 -0
- package/dist/input-color-picker.entry-37826630.js +48 -0
- package/dist/input-color-picker.entry-cbdce7a1.cjs +1 -0
- package/dist/input-component.entry-b83b7103.js +70 -0
- package/dist/input-component.entry-e71b7062.cjs +1 -0
- package/dist/input-dropdown.entry-150819cd.cjs +1 -0
- package/dist/input-dropdown.entry-db0dae5f.js +134 -0
- package/dist/mailbox-store-9c52a3fa-04f22f60.cjs +1 -0
- package/dist/mailbox-store-9c52a3fa-80fe343c.js +380 -0
- package/dist/multi-select-dropdown.entry-629329d7.cjs +1 -0
- package/dist/multi-select-dropdown.entry-6b429b39.js +95 -0
- package/dist/nylas-booked-event-card_12.entry-660af56a.cjs +1 -0
- package/dist/nylas-booked-event-card_12.entry-c22c02b4.js +1133 -0
- package/dist/nylas-form-card.entry-2ced5eef.cjs +1 -0
- package/dist/nylas-form-card.entry-f3d6a1e4.js +57 -0
- package/dist/nylas-if-state.entry-55c32c0c.cjs +1 -0
- package/dist/nylas-if-state.entry-862ad978.js +94 -0
- package/dist/nylas-list-folders.entry-544fd38d.js +120 -0
- package/dist/nylas-list-folders.entry-77e936f7.cjs +1 -0
- package/dist/nylas-list-threads.entry-71411da7.js +70 -0
- package/dist/nylas-list-threads.entry-82e04782.cjs +1 -0
- package/dist/nylas-login.entry-3ccc2bef.cjs +1 -0
- package/dist/nylas-login.entry-48179c01.js +73 -0
- package/dist/nylas-mailbox-pagination.entry-77cf03b5.js +101 -0
- package/dist/nylas-mailbox-pagination.entry-d31f9aa4.cjs +1 -0
- package/dist/nylas-mailbox-toolbar-button.entry-33aad610.cjs +1 -0
- package/dist/nylas-mailbox-toolbar-button.entry-40e3c373.js +82 -0
- package/dist/nylas-mailbox.entry-963de1c3.cjs +1 -0
- package/dist/nylas-mailbox.entry-f4066fb2.js +134 -0
- package/dist/nylas-provider.entry-08767da3.cjs +1 -0
- package/dist/nylas-provider.entry-c61428b1.js +145 -0
- package/dist/nylas-reminder-emails.entry-cd8e1d2e.js +129 -0
- package/dist/nylas-reminder-emails.entry-d42a7f1d.cjs +4 -0
- package/dist/nylas-reminder-time_2.entry-d7115393.js +105 -0
- package/dist/nylas-reminder-time_2.entry-e5540fdd.cjs +1 -0
- package/dist/nylas-scheduler-editor.entry-65eb4938.js +1447 -0
- package/dist/nylas-scheduler-editor.entry-67904653.cjs +2 -0
- package/dist/nylas-scheduling.entry-50e41d85.cjs +1 -0
- package/dist/nylas-scheduling.entry-7aad4f63.js +345 -0
- package/dist/nylas-threads-refresh.entry-1b8befab.cjs +1 -0
- package/dist/nylas-threads-refresh.entry-d025575a.js +74 -0
- package/dist/nylas-threads-search.entry-78c06183.cjs +1 -0
- package/dist/nylas-threads-search.entry-a254c36e.js +69 -0
- package/dist/nylas-time-window-picker.entry-30baeb50.cjs +1 -0
- package/dist/nylas-time-window-picker.entry-89c15823.js +316 -0
- package/dist/nylas-view-thread.entry-939a4561.cjs +1 -0
- package/dist/nylas-view-thread.entry-c8d56573.js +203 -0
- package/dist/person-icon.entry-5ab75598.cjs +1 -0
- package/dist/person-icon.entry-8aef4041.js +15 -0
- package/dist/play-icon_2.entry-392ad303.cjs +1 -0
- package/dist/play-icon_2.entry-4b068c1b.js +25 -0
- package/dist/react.cjs +1 -0
- package/dist/react.js +145 -0
- package/dist/refresh-icon.entry-9ea254c9.cjs +1 -0
- package/dist/refresh-icon.entry-a754a2b5.js +15 -0
- package/dist/register-component-ea95564d-ab3d630f.cjs +1 -0
- package/dist/register-component-ea95564d-e19ec159.js +109 -0
- package/dist/scheduler-config-store-2a3b403d-4e10b542.cjs +1 -0
- package/dist/scheduler-config-store-2a3b403d-581c70cf.js +27 -0
- package/dist/scheduler-store-9ff4914b-6e28240e.cjs +1 -0
- package/dist/scheduler-store-9ff4914b-b71a0aca.js +474 -0
- package/dist/textarea-component.entry-70bb02bf.cjs +1 -0
- package/dist/textarea-component.entry-a5daab6c.js +37 -0
- package/dist/time-period-selector.entry-25348de7.js +80 -0
- package/dist/time-period-selector.entry-6306e456.cjs +1 -0
- package/dist/translate-icon.entry-785fa109.cjs +1 -0
- package/dist/translate-icon.entry-b6094ecc.js +15 -0
- package/dist/warning-icon.entry-4b400ee2.js +15 -0
- package/dist/warning-icon.entry-94e34c58.cjs +1 -0
- package/package.json +12 -8
- package/dist/elements/index.js +0 -92
- package/dist/elements/index.js.map +0 -1
- package/dist/elements/react-component-lib/createComponent.js +0 -65
- package/dist/elements/react-component-lib/createComponent.js.map +0 -1
- package/dist/elements/react-component-lib/createOverlayComponent.js +0 -98
- package/dist/elements/react-component-lib/createOverlayComponent.js.map +0 -1
- package/dist/elements/react-component-lib/index.js +0 -3
- package/dist/elements/react-component-lib/index.js.map +0 -1
- package/dist/elements/react-component-lib/interfaces.js +0 -2
- package/dist/elements/react-component-lib/interfaces.js.map +0 -1
- package/dist/elements/react-component-lib/utils/attachProps.js +0 -92
- package/dist/elements/react-component-lib/utils/attachProps.js.map +0 -1
- package/dist/elements/react-component-lib/utils/case.js +0 -7
- package/dist/elements/react-component-lib/utils/case.js.map +0 -1
- package/dist/elements/react-component-lib/utils/dev.js +0 -13
- package/dist/elements/react-component-lib/utils/dev.js.map +0 -1
- package/dist/elements/react-component-lib/utils/index.js +0 -31
- package/dist/elements/react-component-lib/utils/index.js.map +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- /package/dist/{types/elements → elements}/react-component-lib/createComponent.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/createOverlayComponent.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/index.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/interfaces.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/utils/attachProps.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/utils/case.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/utils/dev.d.ts +0 -0
- /package/dist/{types/elements → elements}/react-component-lib/utils/index.d.ts +0 -0
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { d as o, e as f } from "./index-a134f625.js";
|
|
2
|
+
import { X as u, Z as d } from "./index.es-79f5b771-ce07d6fc.js";
|
|
3
|
+
class S {
|
|
4
|
+
constructor(t, e) {
|
|
5
|
+
this.nylasAuth = t, this.nylasAuthStore = e;
|
|
6
|
+
}
|
|
7
|
+
async validateSession() {
|
|
8
|
+
const t = await this.isAccessTokenValid();
|
|
9
|
+
if (!t)
|
|
10
|
+
this.logout();
|
|
11
|
+
else {
|
|
12
|
+
let e = await this.nylasAuth.getTokenInfo();
|
|
13
|
+
if (e) {
|
|
14
|
+
const a = Math.floor(Date.now() / 1e3);
|
|
15
|
+
if (e.expires_in && e.expires_in - a < 3e5 && (o("[NylasAuthConnectorMixin] Refreshing access token"), e = await this.nylasAuth.refreshAccessToken(), !e)) {
|
|
16
|
+
o("[NylasAuthConnectorMixin] Token is expired and could not be refreshed. Logging out."), this.logout();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.nylasAuthStore.state.tokenInfo = e;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
this.nylasAuthStore.state.isAuthenticated = t;
|
|
23
|
+
}
|
|
24
|
+
async isAuthenticated() {
|
|
25
|
+
return this.nylasAuth.isAuthenticated();
|
|
26
|
+
}
|
|
27
|
+
async getTokenInfo() {
|
|
28
|
+
return this.nylasAuth.getTokenInfo();
|
|
29
|
+
}
|
|
30
|
+
async isAccessTokenValid() {
|
|
31
|
+
return this.nylasAuth.isAccessTokenValid();
|
|
32
|
+
}
|
|
33
|
+
async logout() {
|
|
34
|
+
await this.nylasAuth.logout();
|
|
35
|
+
}
|
|
36
|
+
async getHostedAuthRedirectURL(t, e, s) {
|
|
37
|
+
return this.nylasAuth.getHostedAuthRedirectURL(t, e, s);
|
|
38
|
+
}
|
|
39
|
+
async manageHostedAuthCodeExchange(t) {
|
|
40
|
+
const s = new URL(t).searchParams.get("code");
|
|
41
|
+
if (s) {
|
|
42
|
+
const a = await this.nylasAuth.exchangeAuthCodeForTokenInfo(s);
|
|
43
|
+
if (a)
|
|
44
|
+
return this.nylasAuthStore.state.tokenInfo = a, this.nylasAuthStore.state.isAuthenticated = !0, a;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class A {
|
|
50
|
+
constructor(t, e, s) {
|
|
51
|
+
this.nylasAuth = t, this.nylasAuthStore = e, this.nylasMailboxStore = s;
|
|
52
|
+
}
|
|
53
|
+
async getMessages() {
|
|
54
|
+
var n;
|
|
55
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
56
|
+
throw new Error("Not authenticated");
|
|
57
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
58
|
+
throw new Error("Missing message:read-only scope");
|
|
59
|
+
this.nylasMailboxStore.state.state = "loading";
|
|
60
|
+
const t = this.nylasMailboxStore.state.messgeQueryParams, e = new URLSearchParams();
|
|
61
|
+
for (const i in t) {
|
|
62
|
+
const l = (n = t[i]) == null ? void 0 : n.toString();
|
|
63
|
+
l && e.append(i, l);
|
|
64
|
+
}
|
|
65
|
+
const s = `/v3/grants/me/messages?${e.toString()}`, a = await this.nylasAuth.nylasAPIRequest(s);
|
|
66
|
+
if (u(a))
|
|
67
|
+
throw new d(a.error);
|
|
68
|
+
const r = a.data;
|
|
69
|
+
return this.nylasMailboxStore.state.messages = r, this.nylasMailboxStore.state.state = "ready", r;
|
|
70
|
+
}
|
|
71
|
+
async getThreadMessages(t) {
|
|
72
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
73
|
+
throw new Error("Not authenticated");
|
|
74
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
75
|
+
throw new Error("Missing message:read-only scope");
|
|
76
|
+
const e = await this.nylasAuth.nylasAPIRequest(`/v3/grants/me/messages?thread_id=${t}&fields=include_headers`);
|
|
77
|
+
if (u(e))
|
|
78
|
+
throw new d(e.error);
|
|
79
|
+
const s = e.data;
|
|
80
|
+
return this.nylasMailboxStore.state.messages = s, s;
|
|
81
|
+
}
|
|
82
|
+
downloadMessageAttachments(t) {
|
|
83
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
84
|
+
throw new Error("Not authenticated");
|
|
85
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
86
|
+
throw new Error("Missing message:read-only scope");
|
|
87
|
+
const e = [], s = t.attachments || [];
|
|
88
|
+
for (const a of s) {
|
|
89
|
+
const r = this.nylasAuth.nylasDownloadFileRequest(`/v3/grants/me/attachments/${a.id}?message_id=${t.id}`);
|
|
90
|
+
e.push(r);
|
|
91
|
+
}
|
|
92
|
+
return e;
|
|
93
|
+
}
|
|
94
|
+
async summarizeText(t) {
|
|
95
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
96
|
+
throw new Error("Not authenticated");
|
|
97
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
98
|
+
throw new Error("Missing message:read-only scope");
|
|
99
|
+
const e = await this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/summarize", "POST", {
|
|
100
|
+
message: {
|
|
101
|
+
body: t
|
|
102
|
+
}
|
|
103
|
+
}, !0, this.nylasAuth.config.elementsApiUri);
|
|
104
|
+
if (u(e))
|
|
105
|
+
throw new d(e.error);
|
|
106
|
+
return e.data.summary;
|
|
107
|
+
}
|
|
108
|
+
async textToSpeech(t, e) {
|
|
109
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
110
|
+
throw new Error("Not authenticated");
|
|
111
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
112
|
+
throw new Error("Missing message:read-only scope");
|
|
113
|
+
return this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/tts", "POST", {
|
|
114
|
+
text: t
|
|
115
|
+
}, !1, this.nylasAuth.config.elementsApiUri, {
|
|
116
|
+
...e ? { signal: e == null ? void 0 : e.signal } : {}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class T {
|
|
121
|
+
constructor(t, e, s, a) {
|
|
122
|
+
this.nylasAuth = t, this.nylasAuthStore = e, this.nylasMailboxStore = s, this.router = a;
|
|
123
|
+
}
|
|
124
|
+
async getThreads(t, e = "overwrite", s = !0) {
|
|
125
|
+
var y;
|
|
126
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
127
|
+
throw new Error("Not authenticated");
|
|
128
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
129
|
+
throw new Error("Missing thread:read-only scope");
|
|
130
|
+
s && (this.nylasMailboxStore.state.state = "loading");
|
|
131
|
+
const a = t || this.nylasMailboxStore.state.threadsQueryParams, r = new URLSearchParams();
|
|
132
|
+
for (const g in a) {
|
|
133
|
+
const c = (y = a[g]) == null ? void 0 : y.toString();
|
|
134
|
+
typeof c < "u" && c !== null && r.append(g, c);
|
|
135
|
+
}
|
|
136
|
+
a.search_query_native ? this.router.navigate(`/?query=${a.search_query_native}`, !0) : this.nylasMailboxStore.state.threadsQueryParams.search_query_native && !a.search_query_native && this.router.navigate("/", !0), a.page_token || (this.nylasMailboxStore.state.previousThreadPageTokens = []), this.nylasMailboxStore.state.threadsQueryParams = a;
|
|
137
|
+
const n = `/v3/grants/me/threads?${r.toString()}`, i = await this.nylasAuth.nylasAPIRequest(n);
|
|
138
|
+
if (u(i))
|
|
139
|
+
throw new d(i.error);
|
|
140
|
+
const l = i.data;
|
|
141
|
+
switch (e) {
|
|
142
|
+
case "prepend":
|
|
143
|
+
this.nylasMailboxStore.state.threads = [...l, ...this.nylasMailboxStore.state.threads];
|
|
144
|
+
break;
|
|
145
|
+
case "append":
|
|
146
|
+
this.nylasMailboxStore.state.threads = [...this.nylasMailboxStore.state.threads, ...l];
|
|
147
|
+
break;
|
|
148
|
+
case "overwrite":
|
|
149
|
+
default:
|
|
150
|
+
this.nylasMailboxStore.state.threads = l;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
return i.next_cursor ? this.nylasMailboxStore.state.nextThreadPageToken = i.next_cursor : this.nylasMailboxStore.state.nextThreadPageToken = null, s && (this.nylasMailboxStore.state.state = "ready"), l;
|
|
154
|
+
}
|
|
155
|
+
async getThread(t) {
|
|
156
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
157
|
+
throw new Error("Not authenticated");
|
|
158
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
159
|
+
throw new Error("Missing thread:read-only scope");
|
|
160
|
+
const e = this.nylasMailboxStore.state.threads.find((n) => n.id === t);
|
|
161
|
+
if (e)
|
|
162
|
+
return e;
|
|
163
|
+
this.nylasMailboxStore.state.state = "loading";
|
|
164
|
+
const s = `/v3/grants/me/threads/${t}`, a = await this.nylasAuth.nylasAPIRequest(s);
|
|
165
|
+
if (u(a))
|
|
166
|
+
throw new d(a.error);
|
|
167
|
+
const r = a.data;
|
|
168
|
+
return this.nylasMailboxStore.state.threads = this.nylasMailboxStore.state.threads.map((n) => n.id === r.id ? r : n), this.nylasMailboxStore.state.state = "ready", r;
|
|
169
|
+
}
|
|
170
|
+
async nextThreadPage(t = "overwrite", e = !0) {
|
|
171
|
+
if (!this.nylasMailboxStore.state.nextThreadPageToken)
|
|
172
|
+
throw new Error("No next page token");
|
|
173
|
+
this.nylasMailboxStore.state.previousThreadPageTokens = Array.from(/* @__PURE__ */ new Set([...this.nylasMailboxStore.state.previousThreadPageTokens, this.nylasMailboxStore.state.threadsQueryParams.page_token ?? null]));
|
|
174
|
+
const s = this.nylasMailboxStore.state.nextThreadPageToken;
|
|
175
|
+
return this.getThreads({
|
|
176
|
+
...this.nylasMailboxStore.state.threadsQueryParams,
|
|
177
|
+
page_token: s
|
|
178
|
+
}, t, e);
|
|
179
|
+
}
|
|
180
|
+
async previousThreadPage(t = "overwrite", e = !0) {
|
|
181
|
+
if (!this.nylasMailboxStore.state.previousThreadPageTokens.length)
|
|
182
|
+
throw new Error("No previous page token");
|
|
183
|
+
const s = [...this.nylasMailboxStore.state.previousThreadPageTokens], a = s.pop();
|
|
184
|
+
return this.nylasMailboxStore.state.previousThreadPageTokens = s, this.getThreads({
|
|
185
|
+
...this.nylasMailboxStore.state.threadsQueryParams,
|
|
186
|
+
page_token: a ?? void 0
|
|
187
|
+
}, t, e);
|
|
188
|
+
}
|
|
189
|
+
updateThreadQueryParams(t) {
|
|
190
|
+
this.nylasMailboxStore.state.threadsQueryParams = {
|
|
191
|
+
...this.nylasMailboxStore.state.threadsQueryParams,
|
|
192
|
+
...t
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
back() {
|
|
196
|
+
this.router.navigate("/", !0), this.nylasMailboxStore.state.selectedThread = null;
|
|
197
|
+
}
|
|
198
|
+
unSelectThread() {
|
|
199
|
+
this.nylasMailboxStore.state.selectedThread = null;
|
|
200
|
+
}
|
|
201
|
+
async selectThread(t) {
|
|
202
|
+
this.router.navigate(`/thread/${t.id}`, !0), this.nylasMailboxStore.state.selectedThread = t, t.unread && this.markThreadAsRead(t).catch((e) => {
|
|
203
|
+
o("Error marking thread as read", e);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async markThreadAsRead(t) {
|
|
207
|
+
return this.updateThread(t, { unread: !1 });
|
|
208
|
+
}
|
|
209
|
+
async updateThread(t, e) {
|
|
210
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
211
|
+
throw new Error("Not authenticated");
|
|
212
|
+
if (!this.nylasAuth.hasScopeByType("email", "modify"))
|
|
213
|
+
throw new Error("Missing thread:modify scope");
|
|
214
|
+
const s = `/v3/grants/me/threads/${t.id}`, a = await this.nylasAuth.nylasAPIRequest(s, "PUT", e);
|
|
215
|
+
if (u(a))
|
|
216
|
+
throw new d(a.error);
|
|
217
|
+
const r = a.data;
|
|
218
|
+
return this.nylasMailboxStore.state.threads = this.nylasMailboxStore.state.threads.map((n) => n.id === r.id ? r : n), this.nylasMailboxStore.state.selectedThread = r, r;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
class x {
|
|
222
|
+
constructor(t, e, s) {
|
|
223
|
+
this.nylasAuth = t, this.nylasAuthStore = e, this.nylasMailboxStore = s;
|
|
224
|
+
}
|
|
225
|
+
async getFolders() {
|
|
226
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
227
|
+
throw new Error("Not authenticated");
|
|
228
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
229
|
+
throw new Error("Missing thread:read-only scope");
|
|
230
|
+
this.nylasMailboxStore.state.state = "loading";
|
|
231
|
+
const t = "/v3/grants/me/folders", e = await this.nylasAuth.nylasAPIRequest(t);
|
|
232
|
+
if (u(e))
|
|
233
|
+
throw new d(e.error);
|
|
234
|
+
const s = e.data;
|
|
235
|
+
return this.nylasMailboxStore.state.folders = s, this.nylasMailboxStore.state.state = "ready", s;
|
|
236
|
+
}
|
|
237
|
+
async selectFolder(t) {
|
|
238
|
+
this.nylasMailboxStore.state.threadsQueryParams = {
|
|
239
|
+
in: t.id,
|
|
240
|
+
...this.nylasMailboxStore.state.threadsQueryParams || {}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
class m extends Event {
|
|
245
|
+
constructor(t, e) {
|
|
246
|
+
super(t, e), this.oldURL = e.oldURL, this.newURL = e.newURL;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
class P {
|
|
250
|
+
constructor() {
|
|
251
|
+
this.routeChangeListeners = [], o("HashRouter constructor");
|
|
252
|
+
}
|
|
253
|
+
destroy() {
|
|
254
|
+
o("HashRouter destroy"), window.removeEventListener("hashchange", this.onRouteChange.bind(this));
|
|
255
|
+
}
|
|
256
|
+
init() {
|
|
257
|
+
if (o("HashRouter init"), window.addEventListener("hashchange", this.onRouteChange.bind(this)), typeof HashChangeEvent < "u") {
|
|
258
|
+
const t = new HashChangeEvent("hashchange", { oldURL: "", newURL: window.location.href });
|
|
259
|
+
this.onRouteChange(t);
|
|
260
|
+
} else {
|
|
261
|
+
const t = new m("hashchange", { oldURL: "", newURL: window.location.href });
|
|
262
|
+
this.onRouteChange(t);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
addRouteChangeListener(t, e) {
|
|
266
|
+
o("HashRouter addRouteChangeListener"), this.routeChangeListeners.push([t, e]);
|
|
267
|
+
}
|
|
268
|
+
navigate(t, e) {
|
|
269
|
+
if (o("HashRouter navigate"), e)
|
|
270
|
+
return window.history.pushState(null, "", `#${t}`);
|
|
271
|
+
window.location.hash = t;
|
|
272
|
+
}
|
|
273
|
+
setRoute(t) {
|
|
274
|
+
o("HashRouter setRoute"), window.location.hash = t;
|
|
275
|
+
}
|
|
276
|
+
matchRoute(t, e) {
|
|
277
|
+
const s = t.split("/"), a = e.split("/");
|
|
278
|
+
if (o(`HashRouter matchRoute route=${t} path=${e}`, { routeParts: s, pathParts: a }), s[1] === "" && a[0] === "")
|
|
279
|
+
return !0;
|
|
280
|
+
if (s.length !== a.length)
|
|
281
|
+
return !1;
|
|
282
|
+
for (let r = 0; r < s.length; r++) {
|
|
283
|
+
const n = s[r], i = a[r];
|
|
284
|
+
if (!n.startsWith(":") && n !== i)
|
|
285
|
+
return !1;
|
|
286
|
+
}
|
|
287
|
+
return !0;
|
|
288
|
+
}
|
|
289
|
+
getRouteParams(t) {
|
|
290
|
+
o("HashRouter getRouteParams");
|
|
291
|
+
const e = {}, s = t.split("/"), a = window.location.hash.split("/");
|
|
292
|
+
return s.forEach((r, n) => {
|
|
293
|
+
if (r.startsWith(":")) {
|
|
294
|
+
const i = r.substring(1);
|
|
295
|
+
e[i] = a[n];
|
|
296
|
+
}
|
|
297
|
+
}), e;
|
|
298
|
+
}
|
|
299
|
+
getRouteWithParams(t, e) {
|
|
300
|
+
o("HashRouter getRouteWithParams");
|
|
301
|
+
let s = t;
|
|
302
|
+
return Object.keys(e).forEach((a) => {
|
|
303
|
+
s = s.replace(`:${a}`, e[a]);
|
|
304
|
+
}), s;
|
|
305
|
+
}
|
|
306
|
+
getRoute() {
|
|
307
|
+
return o("HashRouter getRoute"), window.location.hash;
|
|
308
|
+
}
|
|
309
|
+
onRouteChange(t) {
|
|
310
|
+
this.routeChangeListeners.forEach(async ([e, s]) => {
|
|
311
|
+
const a = t.newURL.indexOf("#") === -1 ? "" : t.newURL.substring(t.newURL.indexOf("#") + 1);
|
|
312
|
+
if (o(`HashRouter onRouteChange route=${e} path=${a}`, { event: t }), !this.matchRoute(e, a)) {
|
|
313
|
+
o(`HashRouter onRouteChange route=${e} path=${a} does not match`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const r = this.getRouteParams(e);
|
|
317
|
+
await s(e, a, r);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
getBasePath() {
|
|
321
|
+
return o("HashRouter getBasePath"), "";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function b(h = {}) {
|
|
325
|
+
const t = {
|
|
326
|
+
isAuthenticated: !1,
|
|
327
|
+
tokenInfo: null,
|
|
328
|
+
state: "ready",
|
|
329
|
+
...h
|
|
330
|
+
}, e = f(t);
|
|
331
|
+
return e.reset = () => {
|
|
332
|
+
for (const s in t) {
|
|
333
|
+
const a = t[s];
|
|
334
|
+
e.set(s, a);
|
|
335
|
+
}
|
|
336
|
+
}, e;
|
|
337
|
+
}
|
|
338
|
+
function M(h = {}) {
|
|
339
|
+
const t = {
|
|
340
|
+
state: "ready",
|
|
341
|
+
messages: [],
|
|
342
|
+
threads: [],
|
|
343
|
+
folders: [],
|
|
344
|
+
selectedThread: null,
|
|
345
|
+
nextThreadPageToken: null,
|
|
346
|
+
previousThreadPageTokens: [],
|
|
347
|
+
searchQuery: "",
|
|
348
|
+
hasNextThreadPage: !1,
|
|
349
|
+
hasPreviousThreadPage: !1,
|
|
350
|
+
selectedFolder: "inbox",
|
|
351
|
+
threadsQueryParams: {
|
|
352
|
+
in: "inbox"
|
|
353
|
+
},
|
|
354
|
+
messgeQueryParams: {
|
|
355
|
+
fields: "include_headers"
|
|
356
|
+
},
|
|
357
|
+
...h
|
|
358
|
+
}, e = f({ ...t });
|
|
359
|
+
return e.onChange("nextThreadPageToken", (s) => {
|
|
360
|
+
e.set("hasNextThreadPage", s !== null);
|
|
361
|
+
}), e.onChange("previousThreadPageTokens", (s) => {
|
|
362
|
+
e.set("hasPreviousThreadPage", s.length > 0);
|
|
363
|
+
}), e.onChange("threadsQueryParams", (s) => {
|
|
364
|
+
e.set("selectedFolder", s.in || "inbox"), e.set("searchQuery", s.search_query_native || "");
|
|
365
|
+
}), e.reset = () => {
|
|
366
|
+
for (const s in t) {
|
|
367
|
+
const a = t[s];
|
|
368
|
+
e.set(s, a);
|
|
369
|
+
}
|
|
370
|
+
}, e;
|
|
371
|
+
}
|
|
372
|
+
export {
|
|
373
|
+
b as C,
|
|
374
|
+
P as H,
|
|
375
|
+
S as N,
|
|
376
|
+
M as a,
|
|
377
|
+
T as b,
|
|
378
|
+
A as c,
|
|
379
|
+
x as d
|
|
380
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-2a53b6a8.cjs");require("react");require("react-dom");const r=':host{display:block;width:inherit;--nylas-primary:#2563eb;--nylas-error:#cc4841;--nylas-error-pressed:#992222;--nylas-wraning:#f06c00;--nylas-success:#16a392;--nylas-info:#2b8fc2;--nylas-base-0:#ffffff;--nylas-base-25:#fcfcfd;--nylas-base-50:#f8f9fc;--nylas-base-100:#eaecf5;--nylas-base-200:#d5d9eb;--nylas-base-300:#b3b8d8;--nylas-base-400:#717bbc;--nylas-base-500:#4e5ba6;--nylas-base-600:#3e4784;--nylas-base-700:#263f72;--nylas-base-800:#293056;--nylas-base-900:#101323;--nylas-base-950:#0e101b;--nylas-border-radius:0.25rem;--nylas-border-radius-2x:0.5rem;--nylas-border-radius-3x:0.75rem;--nylas-font-family:"Inter", sans-serif}.dropdown{display:inline-block;width:100%;position:relative}.dropdown .dropdown-label{display:flex;align-items:center;gap:0.25rem;color:var(--nylas-base-800)}.dropdown span.error{color:var(--nylas-error);font-size:14px}.dropbtn{width:inherit;height:48px;color:black;padding:0.5rem;font-size:1rem;cursor:pointer;display:flex;gap:0.5rem;justify-content:space-between;align-items:center;background:transparent;border:1px solid var(--nylas-base-200);border-radius:var(--nylas-border-radius-2x)}.dropbtn.focus{background:transparent}.dropbtn.error{border:1px solid var(--nylas-error)}.dropbtn:hover,.dropbtn:active{border:1px solid var(--nylas-primary)}.dropbtn:active{outline:2px solid var(--nylas-primary)}.dropbtn span.open{transform:rotate(90deg)}.dropbtn span.closed{transform:rotate(270deg)}.dropdown-content{display:block;margin-top:0.5rem;background-color:var(--nylas-base-0);width:100%;max-height:336px;overflow:auto;z-index:1;border-radius:4px;position:absolute;top:72px;box-shadow:0px 4px 6px -2px rgba(0, 0, 0, 0.0509803922);box-shadow:0px 10px 15px -3px rgba(0, 0, 0, 0.1019607843)}.dropdown-content ul{padding:0;list-style-type:none;color:var(--nylas-base-900);max-height:336px}.dropdown-content ul li{padding:16px, 12px, 16px, 12px;color:black;padding:12px 16px;text-decoration:none;display:block;font-family:inherit;font-size:14px;font-weight:400;line-height:20px;letter-spacing:0px;text-align:left;cursor:pointer}.dropdown-content ul li:hover,.dropdown-content ul li:focus{background-color:var(--nylas-base-100)}.dropdown-content ul li label{display:flex;align-items:center;gap:0.5rem}.dropdown-content ul li label input{margin:0}.selected-options{display:flex;flex-wrap:wrap;gap:0.5rem;padding:0.5rem 0;margin-top:0.25rem;background:var(--nylas-base-0)}.selected-options .selected-option{display:flex;align-items:center;gap:0.5rem;padding:4px 8px;border-radius:var(--nylas-border-radius-2x);background:var(--nylas-base-100);color:var(--nylas-base-800);font-size:16px;font-weight:500;line-height:1.5rem;letter-spacing:0.5px}.selected-options .selected-option button{background:transparent;border:none;cursor:pointer;padding:0}.selected-options .selected-option button:hover{color:var(--nylas-primary)}',l=r,o=class{constructor(e){s.registerInstance(this,e),this.selectedOptionsChanged=s.createEvent(this,"selectedOptionsChanged",7),this.name=void 0,this.label=void 0,this.options=[],this.error="",this.availableOptions=this.options,this.isOpen=!1,this.ariaActivedescendant="",this.shouldFocusFirstOption=!1}componentDidLoad(){s.debug("multi-select-dropdown","componentDidLoad"),this.options&&(this.availableOptions=this.options)}componentDidRender(){var e;s.debug("multi-select-dropdown","componentDidRender"),this.isOpen&&this.shouldFocusFirstOption&&(this.ariaActivedescendant=(e=this.availableOptions[0])==null?void 0:e.value,this.focusOption(0),this.shouldFocusFirstOption=!1)}handleOutsideClick(e){!e.composedPath().includes(this.el)&&this.isOpen&&(this.isOpen=!1)}selectOption(e){this.availableOptions=this.availableOptions.map(t=>(t.value===e.value&&(t.selected=!e.selected),t));const a=this.availableOptions.filter(t=>t.selected).map(t=>t.value);this.selectedOptionsChanged.emit({value:a,name:this.name})}toggleDropdown(){this.isOpen=!this.isOpen,this.isOpen?this.shouldFocusFirstOption=!0:this.ariaActivedescendant=""}handleSelectButtonKeyDown(e){switch(e.key){case"ArrowDown":case"Enter":e.preventDefault(),this.isOpen||this.toggleDropdown();break;case"Escape":this.isOpen=!1;break}}handleListboxKeydown(e){const a=this.availableOptions,t=a.findIndex(n=>n.value===this.ariaActivedescendant);switch(e.key){case"ArrowDown":case"Tab":if(e.shiftKey){e.preventDefault();const i=t-1>=0?t-1:a.length-1;this.ariaActivedescendant=a[i].value,this.focusOption(i)}else{e.preventDefault();const i=t+1<a.length?t+1:0;this.ariaActivedescendant=a[i].value,this.focusOption(i)}break;case"ArrowUp":e.preventDefault();const n=t-1>=0?t-1:a.length-1;this.ariaActivedescendant=a[n].value,this.focusOption(n);break;case"Enter":e.preventDefault(),this.ariaActivedescendant&&this.selectOption(a[t]);break;case"Escape":this.isOpen=!1;break}}focusOption(e){var i;const a=this.availableOptions[e];if(!a)return;const t=a.value,n=(i=this.el.shadowRoot)==null?void 0:i.getElementById(t);n&&(n.focus(),n.scrollIntoView({behavior:"smooth",block:"nearest"}))}getSelectedOptions(){return this.availableOptions.filter(e=>e.selected)}renderOption(e){return s.h("li",{key:e.value,id:e.value,role:"option",tabindex:"0","aria-selected":e.selected?"true":"false",onClick:a=>{a.stopImmediatePropagation(),this.selectOption(e)},class:{selected:!!e.selected}},s.h("label",{htmlFor:e.value},s.h("input",{"aria-hidden":"true",id:e.value,type:"checkbox",checked:e.selected}),s.h("span",null,e.label)))}render(){var e,a;return s.h(s.Host,{key:"cecb77880fd937e5845868c7cae0d9e341991088"},s.h("div",{key:"3d6acf55e72e25e411812f2fd887678bb332ef16",class:"dropdown",part:"msd_dropdown"},s.h("label",{key:"c509b2157684148c0ee0d33f9a2de999d4e05945",class:"dropdown-label"},this.label,s.h("slot",{key:"568acd93a920e4538350a56c2cef04a67fa07dc7",name:"label-icon","aria-hidden":"true"})),s.h("button",{key:"036bf6146c9071cb369f95ec3e60ea6d8cf12d1a",name:this.name,part:`msd_dropdown-button ${this.error?"msd_dropdown-button--error":""}`,class:{dropbtn:!0,open:this.isOpen,error:!!this.error},onClick:()=>this.toggleDropdown(),"aria-haspopup":"listbox","aria-expanded":this.isOpen?"true":"false","aria-label":this.name,onKeyDown:t=>this.handleSelectButtonKeyDown(t)},s.h("slot",{key:"4760a3c065fa4f0af09cf11326423aacf5511066",name:"select-icon","aria-hidden":"true"}),s.h("span",{key:"4edd567dc3f25451a4f0cbddb02391bde5fc56fd",class:"selected-option",part:"msd_dropdown-button-selected-label"},this.getSelectedOptions().length>1?"Multiple options selected":((e=this.availableOptions.filter(t=>t.selected)[0])==null?void 0:e.label)??((a=this.availableOptions[0])==null?void 0:a.label)),s.h("span",{key:"6ae9028141f44f16dc56ecd294a2acc3db9a01d5",class:this.isOpen?"open":"closed","aria-hidden":"true"},s.h("chevron-icon",{key:"7381625a3b7a961a125d91a27e7b96e4754fb0a1",width:"16",height:"16"}))),this.error?s.h("span",{class:"error"},this.error):null,this.isOpen?null:s.h("div",{class:"selected-options"},this.getSelectedOptions().map(t=>s.h("span",{class:"selected-option"},t.label,s.h("button",{key:t.label,onClick:()=>this.selectOption(t)},s.h("close-icon",null))))),this.isOpen?s.h("div",{class:"dropdown-content",part:"msd_dropdown-content"},s.h("ul",{tabindex:"-1",role:"listbox","aria-label":this.name,"aria-multiselectable":!0,"aria-activedescendant":this.ariaActivedescendant,onKeyDown:t=>this.handleListboxKeydown(t)},this.availableOptions.map(t=>this.renderOption(t)))):null))}get el(){return s.getElement(this)}};o.style=l;exports.multi_select_dropdown=o;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { r as l, c as r, d as o, h as s, H as d, g as c } from "./index-a134f625.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import "react-dom";
|
|
4
|
+
const p = ':host{display:block;width:inherit;--nylas-primary:#2563eb;--nylas-error:#cc4841;--nylas-error-pressed:#992222;--nylas-wraning:#f06c00;--nylas-success:#16a392;--nylas-info:#2b8fc2;--nylas-base-0:#ffffff;--nylas-base-25:#fcfcfd;--nylas-base-50:#f8f9fc;--nylas-base-100:#eaecf5;--nylas-base-200:#d5d9eb;--nylas-base-300:#b3b8d8;--nylas-base-400:#717bbc;--nylas-base-500:#4e5ba6;--nylas-base-600:#3e4784;--nylas-base-700:#263f72;--nylas-base-800:#293056;--nylas-base-900:#101323;--nylas-base-950:#0e101b;--nylas-border-radius:0.25rem;--nylas-border-radius-2x:0.5rem;--nylas-border-radius-3x:0.75rem;--nylas-font-family:"Inter", sans-serif}.dropdown{display:inline-block;width:100%;position:relative}.dropdown .dropdown-label{display:flex;align-items:center;gap:0.25rem;color:var(--nylas-base-800)}.dropdown span.error{color:var(--nylas-error);font-size:14px}.dropbtn{width:inherit;height:48px;color:black;padding:0.5rem;font-size:1rem;cursor:pointer;display:flex;gap:0.5rem;justify-content:space-between;align-items:center;background:transparent;border:1px solid var(--nylas-base-200);border-radius:var(--nylas-border-radius-2x)}.dropbtn.focus{background:transparent}.dropbtn.error{border:1px solid var(--nylas-error)}.dropbtn:hover,.dropbtn:active{border:1px solid var(--nylas-primary)}.dropbtn:active{outline:2px solid var(--nylas-primary)}.dropbtn span.open{transform:rotate(90deg)}.dropbtn span.closed{transform:rotate(270deg)}.dropdown-content{display:block;margin-top:0.5rem;background-color:var(--nylas-base-0);width:100%;max-height:336px;overflow:auto;z-index:1;border-radius:4px;position:absolute;top:72px;box-shadow:0px 4px 6px -2px rgba(0, 0, 0, 0.0509803922);box-shadow:0px 10px 15px -3px rgba(0, 0, 0, 0.1019607843)}.dropdown-content ul{padding:0;list-style-type:none;color:var(--nylas-base-900);max-height:336px}.dropdown-content ul li{padding:16px, 12px, 16px, 12px;color:black;padding:12px 16px;text-decoration:none;display:block;font-family:inherit;font-size:14px;font-weight:400;line-height:20px;letter-spacing:0px;text-align:left;cursor:pointer}.dropdown-content ul li:hover,.dropdown-content ul li:focus{background-color:var(--nylas-base-100)}.dropdown-content ul li label{display:flex;align-items:center;gap:0.5rem}.dropdown-content ul li label input{margin:0}.selected-options{display:flex;flex-wrap:wrap;gap:0.5rem;padding:0.5rem 0;margin-top:0.25rem;background:var(--nylas-base-0)}.selected-options .selected-option{display:flex;align-items:center;gap:0.5rem;padding:4px 8px;border-radius:var(--nylas-border-radius-2x);background:var(--nylas-base-100);color:var(--nylas-base-800);font-size:16px;font-weight:500;line-height:1.5rem;letter-spacing:0.5px}.selected-options .selected-option button{background:transparent;border:none;cursor:pointer;padding:0}.selected-options .selected-option button:hover{color:var(--nylas-primary)}', h = p, b = class {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
l(this, e), this.selectedOptionsChanged = r(this, "selectedOptionsChanged", 7), this.name = void 0, this.label = void 0, this.options = [], this.error = "", this.availableOptions = this.options, this.isOpen = !1, this.ariaActivedescendant = "", this.shouldFocusFirstOption = !1;
|
|
7
|
+
}
|
|
8
|
+
componentDidLoad() {
|
|
9
|
+
o("multi-select-dropdown", "componentDidLoad"), this.options && (this.availableOptions = this.options);
|
|
10
|
+
}
|
|
11
|
+
componentDidRender() {
|
|
12
|
+
var e;
|
|
13
|
+
o("multi-select-dropdown", "componentDidRender"), this.isOpen && this.shouldFocusFirstOption && (this.ariaActivedescendant = (e = this.availableOptions[0]) == null ? void 0 : e.value, this.focusOption(0), this.shouldFocusFirstOption = !1);
|
|
14
|
+
}
|
|
15
|
+
handleOutsideClick(e) {
|
|
16
|
+
!e.composedPath().includes(this.el) && this.isOpen && (this.isOpen = !1);
|
|
17
|
+
}
|
|
18
|
+
selectOption(e) {
|
|
19
|
+
this.availableOptions = this.availableOptions.map((t) => (t.value === e.value && (t.selected = !e.selected), t));
|
|
20
|
+
const a = this.availableOptions.filter((t) => t.selected).map((t) => t.value);
|
|
21
|
+
this.selectedOptionsChanged.emit({
|
|
22
|
+
value: a,
|
|
23
|
+
name: this.name
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
toggleDropdown() {
|
|
27
|
+
this.isOpen = !this.isOpen, this.isOpen ? this.shouldFocusFirstOption = !0 : this.ariaActivedescendant = "";
|
|
28
|
+
}
|
|
29
|
+
handleSelectButtonKeyDown(e) {
|
|
30
|
+
switch (e.key) {
|
|
31
|
+
case "ArrowDown":
|
|
32
|
+
case "Enter":
|
|
33
|
+
e.preventDefault(), this.isOpen || this.toggleDropdown();
|
|
34
|
+
break;
|
|
35
|
+
case "Escape":
|
|
36
|
+
this.isOpen = !1;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
handleListboxKeydown(e) {
|
|
41
|
+
const a = this.availableOptions, t = a.findIndex((n) => n.value === this.ariaActivedescendant);
|
|
42
|
+
switch (e.key) {
|
|
43
|
+
case "ArrowDown":
|
|
44
|
+
case "Tab":
|
|
45
|
+
if (e.shiftKey) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
const i = t - 1 >= 0 ? t - 1 : a.length - 1;
|
|
48
|
+
this.ariaActivedescendant = a[i].value, this.focusOption(i);
|
|
49
|
+
} else {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
const i = t + 1 < a.length ? t + 1 : 0;
|
|
52
|
+
this.ariaActivedescendant = a[i].value, this.focusOption(i);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case "ArrowUp":
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
const n = t - 1 >= 0 ? t - 1 : a.length - 1;
|
|
58
|
+
this.ariaActivedescendant = a[n].value, this.focusOption(n);
|
|
59
|
+
break;
|
|
60
|
+
case "Enter":
|
|
61
|
+
e.preventDefault(), this.ariaActivedescendant && this.selectOption(a[t]);
|
|
62
|
+
break;
|
|
63
|
+
case "Escape":
|
|
64
|
+
this.isOpen = !1;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
focusOption(e) {
|
|
69
|
+
var i;
|
|
70
|
+
const a = this.availableOptions[e];
|
|
71
|
+
if (!a)
|
|
72
|
+
return;
|
|
73
|
+
const t = a.value, n = (i = this.el.shadowRoot) == null ? void 0 : i.getElementById(t);
|
|
74
|
+
n && (n.focus(), n.scrollIntoView({ behavior: "smooth", block: "nearest" }));
|
|
75
|
+
}
|
|
76
|
+
getSelectedOptions() {
|
|
77
|
+
return this.availableOptions.filter((e) => e.selected);
|
|
78
|
+
}
|
|
79
|
+
renderOption(e) {
|
|
80
|
+
return s("li", { key: e.value, id: e.value, role: "option", tabindex: "0", "aria-selected": e.selected ? "true" : "false", onClick: (a) => {
|
|
81
|
+
a.stopImmediatePropagation(), this.selectOption(e);
|
|
82
|
+
}, class: { selected: !!e.selected } }, s("label", { htmlFor: e.value }, s("input", { "aria-hidden": "true", id: e.value, type: "checkbox", checked: e.selected }), s("span", null, e.label)));
|
|
83
|
+
}
|
|
84
|
+
render() {
|
|
85
|
+
var e, a;
|
|
86
|
+
return s(d, { key: "cecb77880fd937e5845868c7cae0d9e341991088" }, s("div", { key: "3d6acf55e72e25e411812f2fd887678bb332ef16", class: "dropdown", part: "msd_dropdown" }, s("label", { key: "c509b2157684148c0ee0d33f9a2de999d4e05945", class: "dropdown-label" }, this.label, s("slot", { key: "568acd93a920e4538350a56c2cef04a67fa07dc7", name: "label-icon", "aria-hidden": "true" })), s("button", { key: "036bf6146c9071cb369f95ec3e60ea6d8cf12d1a", name: this.name, part: `msd_dropdown-button ${this.error ? "msd_dropdown-button--error" : ""}`, class: { dropbtn: !0, open: this.isOpen, error: !!this.error }, onClick: () => this.toggleDropdown(), "aria-haspopup": "listbox", "aria-expanded": this.isOpen ? "true" : "false", "aria-label": this.name, onKeyDown: (t) => this.handleSelectButtonKeyDown(t) }, s("slot", { key: "4760a3c065fa4f0af09cf11326423aacf5511066", name: "select-icon", "aria-hidden": "true" }), s("span", { key: "4edd567dc3f25451a4f0cbddb02391bde5fc56fd", class: "selected-option", part: "msd_dropdown-button-selected-label" }, this.getSelectedOptions().length > 1 ? "Multiple options selected" : ((e = this.availableOptions.filter((t) => t.selected)[0]) == null ? void 0 : e.label) ?? ((a = this.availableOptions[0]) == null ? void 0 : a.label)), s("span", { key: "6ae9028141f44f16dc56ecd294a2acc3db9a01d5", class: this.isOpen ? "open" : "closed", "aria-hidden": "true" }, s("chevron-icon", { key: "7381625a3b7a961a125d91a27e7b96e4754fb0a1", width: "16", height: "16" }))), this.error ? s("span", { class: "error" }, this.error) : null, this.isOpen ? null : s("div", { class: "selected-options" }, this.getSelectedOptions().map((t) => s("span", { class: "selected-option" }, t.label, s("button", { key: t.label, onClick: () => this.selectOption(t) }, s("close-icon", null))))), this.isOpen ? s("div", { class: "dropdown-content", part: "msd_dropdown-content" }, s("ul", { tabindex: "-1", role: "listbox", "aria-label": this.name, "aria-multiselectable": !0, "aria-activedescendant": this.ariaActivedescendant, onKeyDown: (t) => this.handleListboxKeydown(t) }, this.availableOptions.map((t) => this.renderOption(t)))) : null));
|
|
87
|
+
}
|
|
88
|
+
get el() {
|
|
89
|
+
return c(this);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
b.style = h;
|
|
93
|
+
export {
|
|
94
|
+
b as multi_select_dropdown
|
|
95
|
+
};
|