ochreui 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +153 -2
- package/cli/ochreui.mjs +601 -0
- package/mcp/core.mjs +126 -0
- package/mcp/docs.json +906 -0
- package/mcp/server.mjs +23 -0
- package/package.json +393 -3
- package/registry/agent-team.ts +350 -0
- package/registry/avatar.ts +300 -0
- package/registry/badge.ts +207 -0
- package/registry/breadcrumb.ts +435 -0
- package/registry/button.ts +238 -0
- package/registry/card.ts +221 -0
- package/registry/change-summary.ts +200 -0
- package/registry/checkbox.ts +204 -0
- package/registry/code-block.ts +332 -0
- package/registry/color-picker.ts +720 -0
- package/registry/comment-thread.ts +503 -0
- package/registry/context-menu.ts +281 -0
- package/registry/cover-flow.ts +623 -0
- package/registry/date-picker.ts +799 -0
- package/registry/decision-inbox.ts +340 -0
- package/registry/dialog.ts +577 -0
- package/registry/dropdown-menu.ts +864 -0
- package/registry/email-draft.ts +916 -0
- package/registry/empty-calendar.ts +199 -0
- package/registry/empty-state.ts +164 -0
- package/registry/enrichment-orbit.ts +164 -0
- package/registry/filter-menu.ts +541 -0
- package/registry/form-field.ts +308 -0
- package/registry/frost-cloud.ts +381 -0
- package/registry/ghosted-chat.ts +210 -0
- package/registry/glow-cloud.ts +402 -0
- package/registry/grid-background.ts +164 -0
- package/registry/hover-card.ts +401 -0
- package/registry/icon-button.ts +133 -0
- package/registry/index.json +2124 -0
- package/registry/integration-beam.ts +588 -0
- package/registry/integration-grid.ts +209 -0
- package/registry/kbd.ts +176 -0
- package/registry/layer-stack.ts +351 -0
- package/registry/lead-sourcing.ts +285 -0
- package/registry/logo-cluster.ts +239 -0
- package/registry/logo-marquee.ts +505 -0
- package/registry/message-actions.ts +833 -0
- package/registry/model-orbit.ts +583 -0
- package/registry/model-wheel.ts +372 -0
- package/registry/notification-stack.ts +301 -0
- package/registry/number-input.ts +552 -0
- package/registry/number-ticker.ts +261 -0
- package/registry/ochre.css +917 -0
- package/registry/otp-input.ts +704 -0
- package/registry/overlay.ts +312 -0
- package/registry/pagination.ts +362 -0
- package/registry/popover.ts +296 -0
- package/registry/profile-menu.ts +332 -0
- package/registry/progress-tracker.ts +291 -0
- package/registry/rating.ts +461 -0
- package/registry/reaction-bar.ts +322 -0
- package/registry/region-map.ts +537 -0
- package/registry/resizable.ts +489 -0
- package/registry/scroll-area.ts +271 -0
- package/registry/segmented-control.ts +433 -0
- package/registry/select.ts +769 -0
- package/registry/separator.ts +97 -0
- package/registry/shimmer-loader.ts +211 -0
- package/registry/side-folder.ts +152 -0
- package/registry/skeleton.ts +136 -0
- package/registry/skill/INSTRUCTIONS.md +11 -0
- package/registry/skill/SKILL.md +65 -0
- package/registry/skill/checklist.md +45 -0
- package/registry/skill/references/agent-team.md +105 -0
- package/registry/skill/references/avatar.md +88 -0
- package/registry/skill/references/badge.md +92 -0
- package/registry/skill/references/breadcrumb.md +99 -0
- package/registry/skill/references/button.md +82 -0
- package/registry/skill/references/card.md +111 -0
- package/registry/skill/references/catalog.md +114 -0
- package/registry/skill/references/change-summary.md +103 -0
- package/registry/skill/references/checkbox.md +105 -0
- package/registry/skill/references/code-block.md +109 -0
- package/registry/skill/references/color-picker.md +138 -0
- package/registry/skill/references/comment-thread.md +164 -0
- package/registry/skill/references/context-menu.md +205 -0
- package/registry/skill/references/cover-flow.md +128 -0
- package/registry/skill/references/date-picker.md +154 -0
- package/registry/skill/references/decision-inbox.md +126 -0
- package/registry/skill/references/dialog.md +155 -0
- package/registry/skill/references/dropdown-menu.md +144 -0
- package/registry/skill/references/email-draft.md +182 -0
- package/registry/skill/references/empty-calendar.md +74 -0
- package/registry/skill/references/empty-state.md +118 -0
- package/registry/skill/references/enrichment-orbit.md +71 -0
- package/registry/skill/references/filter-menu.md +143 -0
- package/registry/skill/references/form-field.md +118 -0
- package/registry/skill/references/frost-cloud.md +80 -0
- package/registry/skill/references/ghosted-chat.md +75 -0
- package/registry/skill/references/glow-cloud.md +84 -0
- package/registry/skill/references/grid-background.md +76 -0
- package/registry/skill/references/hover-card.md +125 -0
- package/registry/skill/references/icon-button.md +99 -0
- package/registry/skill/references/integration-beam.md +107 -0
- package/registry/skill/references/integration-grid.md +100 -0
- package/registry/skill/references/kbd.md +65 -0
- package/registry/skill/references/layer-stack.md +115 -0
- package/registry/skill/references/lead-sourcing.md +92 -0
- package/registry/skill/references/logo-cluster.md +92 -0
- package/registry/skill/references/logo-marquee.md +123 -0
- package/registry/skill/references/message-actions.md +146 -0
- package/registry/skill/references/model-orbit.md +106 -0
- package/registry/skill/references/model-wheel.md +84 -0
- package/registry/skill/references/notification-stack.md +138 -0
- package/registry/skill/references/number-input.md +117 -0
- package/registry/skill/references/number-ticker.md +73 -0
- package/registry/skill/references/otp-input.md +142 -0
- package/registry/skill/references/pagination.md +112 -0
- package/registry/skill/references/popover.md +143 -0
- package/registry/skill/references/profile-menu.md +123 -0
- package/registry/skill/references/progress-tracker.md +122 -0
- package/registry/skill/references/rating.md +111 -0
- package/registry/skill/references/reaction-bar.md +128 -0
- package/registry/skill/references/region-map.md +109 -0
- package/registry/skill/references/resizable.md +127 -0
- package/registry/skill/references/scroll-area.md +113 -0
- package/registry/skill/references/segmented-control.md +96 -0
- package/registry/skill/references/select.md +122 -0
- package/registry/skill/references/separator.md +69 -0
- package/registry/skill/references/shimmer-loader.md +83 -0
- package/registry/skill/references/side-folder.md +75 -0
- package/registry/skill/references/skeleton.md +95 -0
- package/registry/skill/references/smart-recommendation.md +132 -0
- package/registry/skill/references/spinner.md +84 -0
- package/registry/skill/references/switch.md +79 -0
- package/registry/skill/references/tab-overload.md +70 -0
- package/registry/skill/references/tag-input.md +126 -0
- package/registry/skill/references/team-invite.md +94 -0
- package/registry/skill/references/testimonial-wall.md +110 -0
- package/registry/skill/references/text-area.md +115 -0
- package/registry/skill/references/text-field.md +126 -0
- package/registry/skill/references/text-reveal.md +71 -0
- package/registry/skill/references/thinking-loader.md +87 -0
- package/registry/skill/references/time-picker.md +122 -0
- package/registry/skill/references/tips-panel.md +115 -0
- package/registry/skill/references/toggle-group.md +98 -0
- package/registry/skill/references/tool-call-card.md +151 -0
- package/registry/skill/references/tooltip.md +94 -0
- package/registry/skill/references/tree-view.md +172 -0
- package/registry/skill/theming.md +57 -0
- package/registry/smart-recommendation.ts +415 -0
- package/registry/spinner.ts +67 -0
- package/registry/switch.ts +146 -0
- package/registry/tab-overload.ts +211 -0
- package/registry/tag-input.ts +620 -0
- package/registry/team-invite.ts +248 -0
- package/registry/testimonial-wall.ts +521 -0
- package/registry/text-area.ts +432 -0
- package/registry/text-field.ts +415 -0
- package/registry/text-reveal.ts +175 -0
- package/registry/theme.ts +68 -0
- package/registry/thinking-loader.ts +302 -0
- package/registry/time-picker.ts +828 -0
- package/registry/tips-panel.ts +312 -0
- package/registry/toggle-group.ts +357 -0
- package/registry/tool-call-card.ts +578 -0
- package/registry/tooltip.ts +486 -0
- package/registry/tree-view.ts +454 -0
- package/styles/base.css +500 -0
- package/styles/tokens.css +415 -0
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Email Draft, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens and shared keyframes), added once by `npx ochreui init`.
|
|
5
|
+
*
|
|
6
|
+
* <ui-email-draft reference="INV-2041" status="Due in 3 days" amount="€1,240" account="Harbor & Co" agent="Billing agent"
|
|
7
|
+
* [contacts]="contacts" [tones]="tones" [(attachment)]="file" [link]="link" [(state)]="state" [error]="error()"
|
|
8
|
+
* (send)="deliver($event)" />
|
|
9
|
+
* An agent-written email for a person to review: pick recipient and tone, edit, then send or discard, with Undo.
|
|
10
|
+
* Send sets `state` to 'sending' and emits the email; set 'sent' when it went out, or 'draft' plus `error`.
|
|
11
|
+
*
|
|
12
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
13
|
+
* --ui-email-draft-max widest the card grows (default 480px; Classic 520px)
|
|
14
|
+
*/
|
|
15
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
16
|
+
import {
|
|
17
|
+
Component,
|
|
18
|
+
DOCUMENT,
|
|
19
|
+
DestroyRef,
|
|
20
|
+
ElementRef,
|
|
21
|
+
Injector,
|
|
22
|
+
afterNextRender,
|
|
23
|
+
booleanAttribute,
|
|
24
|
+
computed,
|
|
25
|
+
effect,
|
|
26
|
+
inject,
|
|
27
|
+
input,
|
|
28
|
+
isDevMode,
|
|
29
|
+
linkedSignal,
|
|
30
|
+
model,
|
|
31
|
+
output,
|
|
32
|
+
signal,
|
|
33
|
+
untracked,
|
|
34
|
+
viewChild,
|
|
35
|
+
} from '@angular/core';
|
|
36
|
+
|
|
37
|
+
export interface DraftContact {
|
|
38
|
+
name: string;
|
|
39
|
+
email: string;
|
|
40
|
+
/** Two letters for the avatar in the list. Default: the first letters of the first two words of `name`. */
|
|
41
|
+
initials?: string;
|
|
42
|
+
/** How a greeting addresses them ("Maya", "team"). The component never reads it; your tone bodies may. */
|
|
43
|
+
greeting?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DraftTone {
|
|
47
|
+
id: string;
|
|
48
|
+
label: string;
|
|
49
|
+
/** The text for this tone, written for the chosen recipient. */
|
|
50
|
+
body: (to: DraftContact) => string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DraftLink {
|
|
54
|
+
label: string;
|
|
55
|
+
href: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type EmailDraftState = 'draft' | 'sending' | 'sent' | 'discarded';
|
|
59
|
+
export type EmailDraftStatusTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
60
|
+
|
|
61
|
+
export interface EmailDraftPayload {
|
|
62
|
+
to: DraftContact;
|
|
63
|
+
body: string;
|
|
64
|
+
attachment: string | null;
|
|
65
|
+
tone: string | null;
|
|
66
|
+
link: DraftLink | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Every visible and spoken string, so the card can be translated. */
|
|
70
|
+
export interface EmailDraftLabels {
|
|
71
|
+
to: string;
|
|
72
|
+
recipient: string;
|
|
73
|
+
attach: (file: string) => string;
|
|
74
|
+
remove: (file: string) => string;
|
|
75
|
+
tone: string;
|
|
76
|
+
edit: string;
|
|
77
|
+
body: string;
|
|
78
|
+
clickToEdit: string;
|
|
79
|
+
/** The hint after the shortcut key, which is ⌘ on Apple devices and Ctrl elsewhere. */
|
|
80
|
+
shortcut: (key: string) => string;
|
|
81
|
+
/** Replaces the hint while the text is empty, saying why Send does nothing. */
|
|
82
|
+
emptyHint: string;
|
|
83
|
+
discard: string;
|
|
84
|
+
send: string;
|
|
85
|
+
sending: string;
|
|
86
|
+
sentTo: string;
|
|
87
|
+
with: string;
|
|
88
|
+
discarded: string;
|
|
89
|
+
restored: string;
|
|
90
|
+
undo: string;
|
|
91
|
+
retry: string;
|
|
92
|
+
ready: string;
|
|
93
|
+
sentChip: string;
|
|
94
|
+
discardedChip: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const EMAIL_DRAFT_LABELS: EmailDraftLabels = {
|
|
98
|
+
to: 'To',
|
|
99
|
+
recipient: 'Recipient',
|
|
100
|
+
attach: (f) => `Attach ${f}`,
|
|
101
|
+
remove: (f) => `Remove ${f}`,
|
|
102
|
+
tone: 'Tone',
|
|
103
|
+
edit: 'Edit text',
|
|
104
|
+
body: 'Email text',
|
|
105
|
+
clickToEdit: 'Click to edit',
|
|
106
|
+
shortcut: (k) => `${k} Enter to send`,
|
|
107
|
+
emptyHint: 'Write the email to send it',
|
|
108
|
+
discard: 'Discard',
|
|
109
|
+
send: 'Send email',
|
|
110
|
+
sending: 'Sending',
|
|
111
|
+
sentTo: 'Sent to',
|
|
112
|
+
with: 'with',
|
|
113
|
+
discarded: 'Draft discarded',
|
|
114
|
+
restored: 'Draft restored',
|
|
115
|
+
undo: 'Undo',
|
|
116
|
+
retry: 'Retry',
|
|
117
|
+
ready: 'Ready for review',
|
|
118
|
+
sentChip: 'Sent',
|
|
119
|
+
discardedChip: 'Discarded',
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
let nextId = 0;
|
|
123
|
+
|
|
124
|
+
const sameContact = (a: DraftContact | null | undefined, b: DraftContact | null | undefined) =>
|
|
125
|
+
!!a && !!b && a.email === b.email && a.name === b.name;
|
|
126
|
+
|
|
127
|
+
const initialsOf = (c: DraftContact) =>
|
|
128
|
+
c.initials ??
|
|
129
|
+
c.name
|
|
130
|
+
.split(/\s+/)
|
|
131
|
+
.filter(Boolean)
|
|
132
|
+
.slice(0, 2)
|
|
133
|
+
.map((w) => w[0])
|
|
134
|
+
.join('')
|
|
135
|
+
.toUpperCase();
|
|
136
|
+
|
|
137
|
+
/** Discard, Send, Undo and Retry inside UiEmailDraft. */
|
|
138
|
+
@Component({
|
|
139
|
+
selector: 'button[uiEmailDraftBtn]',
|
|
140
|
+
host: { '[attr.data-kind]': 'kind()', '[attr.aria-busy]': 'busy() || null' },
|
|
141
|
+
template: `@if (busy()) {<svg class="sp" viewBox="0 0 14 14" aria-hidden="true"><circle cx="7" cy="7" r="6" /><path d="M7 1a6 6 0 0 1 6 6" /></svg>}<ng-content />`,
|
|
142
|
+
styles: `
|
|
143
|
+
:host {
|
|
144
|
+
--_h: calc(var(--ui-space-6) + var(--ui-space-1) + var(--ui-space-2) * var(--_t));
|
|
145
|
+
--_bg: var(--ui-bg-surface);
|
|
146
|
+
--_r: var(--_hl);
|
|
147
|
+
--_g: none;
|
|
148
|
+
--_sh: 0 0 #0000;
|
|
149
|
+
--_c: var(--ui-text);
|
|
150
|
+
--_hi: 14%;
|
|
151
|
+
--_lo: 10%;
|
|
152
|
+
display: inline-flex;
|
|
153
|
+
flex: none;
|
|
154
|
+
align-items: center;
|
|
155
|
+
justify-content: center;
|
|
156
|
+
gap: calc(var(--ui-space-1-5) + 1px * var(--_t));
|
|
157
|
+
box-sizing: border-box;
|
|
158
|
+
block-size: var(--_h);
|
|
159
|
+
padding: 0 calc(var(--ui-space-2-5) + var(--ui-space-1) * var(--_t));
|
|
160
|
+
border: 0;
|
|
161
|
+
border-radius: calc(var(--ui-radius-sm) + var(--ui-space-1) * var(--_t));
|
|
162
|
+
background: var(--_g) var(--_bg);
|
|
163
|
+
box-shadow: inset 0 0 0 1px var(--_r), var(--_sh);
|
|
164
|
+
color: var(--_c);
|
|
165
|
+
font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
|
|
166
|
+
font-weight: calc(var(--ui-weight-medium) - 100 * var(--_t));
|
|
167
|
+
white-space: nowrap;
|
|
168
|
+
cursor: pointer;
|
|
169
|
+
-webkit-tap-highlight-color: transparent;
|
|
170
|
+
transition: calc(160ms * var(--ui-motion-scale)) var(--ui-ease-out);
|
|
171
|
+
transition-property: background-color, box-shadow, color, scale;
|
|
172
|
+
}
|
|
173
|
+
:host([data-kind='secondary']) { --_sh: 0 1px 2px calc(-1px + 1px * var(--_t)) color-mix(in srgb, var(--ui-text) calc(8% * var(--_f)), transparent); }
|
|
174
|
+
:host([data-kind='primary']) {
|
|
175
|
+
--_bg: color-mix(in srgb, var(--ui-bg-neutral-solid) calc(94% + 6% * var(--_t)), var(--ui-bg-surface));
|
|
176
|
+
--_r: color-mix(in srgb, var(--ui-bg-neutral-solid) calc(100% * var(--_t)), transparent);
|
|
177
|
+
--_c: var(--ui-text-on-neutral);
|
|
178
|
+
--_g: linear-gradient(color-mix(in srgb, var(--ui-gray-0) calc(var(--_hi) * var(--_t)), transparent), color-mix(in srgb, var(--ui-gray-1000) calc(var(--_lo) * var(--_t)), transparent));
|
|
179
|
+
--_sh: inset 0 1px color-mix(in srgb, var(--ui-gray-0) calc(18% * var(--_t)), transparent);
|
|
180
|
+
}
|
|
181
|
+
:host([data-kind='quiet']) {
|
|
182
|
+
--_h: calc(var(--ui-space-6) + var(--ui-space-1) - 1.4px * var(--_t));
|
|
183
|
+
--_bg: transparent;
|
|
184
|
+
--_r: transparent;
|
|
185
|
+
padding-inline: calc(var(--ui-space-2-5) - var(--ui-space-0-5) * var(--_t));
|
|
186
|
+
font-size: calc(var(--ui-text-base) + 1px * var(--_t));
|
|
187
|
+
}
|
|
188
|
+
@media (hover: hover) {
|
|
189
|
+
:host(:hover:not([aria-disabled='true'])) { --_bg: color-mix(in srgb, var(--ui-text) 3%, var(--ui-bg-surface)); }
|
|
190
|
+
:host([data-kind='primary']:hover:not([aria-disabled='true'])) { --_bg: var(--ui-bg-neutral-solid); --_hi: 22%; --_lo: 0%; }
|
|
191
|
+
:host([data-kind='quiet']:hover) { --_bg: color-mix(in srgb, var(--ui-text) 4%, transparent); }
|
|
192
|
+
}
|
|
193
|
+
:host(:active:not([aria-disabled='true'])) { scale: calc(0.97 + 0.01 * var(--_t)); }
|
|
194
|
+
:host([aria-disabled='true']) { cursor: default; }
|
|
195
|
+
:host(.off) { opacity: var(--ui-disabled-opacity); }
|
|
196
|
+
:host(:focus-visible) { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
197
|
+
.sp { inline-size: var(--ui-icon-sm); block-size: var(--ui-icon-sm); fill: none; stroke: currentColor; animation: ui-spin 700ms linear infinite; }
|
|
198
|
+
circle { opacity: 0.3; }
|
|
199
|
+
@media (pointer: coarse) { :host { block-size: calc(var(--_h) + 6px * var(--_f)); } }
|
|
200
|
+
@media (prefers-reduced-motion: reduce) { .sp { animation: none; } }
|
|
201
|
+
@container style(--ui-motion-scale: 0) { .sp { animation: none; } }
|
|
202
|
+
@media (forced-colors: active) {
|
|
203
|
+
:host { border: 1px solid ButtonText; }
|
|
204
|
+
:host(.off) { color: GrayText; }
|
|
205
|
+
}
|
|
206
|
+
`,
|
|
207
|
+
})
|
|
208
|
+
export class UiEmailDraftButton {
|
|
209
|
+
readonly kind = input<'primary' | 'secondary' | 'quiet'>('secondary', { alias: 'uiEmailDraftBtn' });
|
|
210
|
+
readonly busy = input(false);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** The recipient row inside UiEmailDraft: the recipient list and the attachment. */
|
|
214
|
+
@Component({
|
|
215
|
+
selector: 'ui-email-draft-to',
|
|
216
|
+
host: {
|
|
217
|
+
style:
|
|
218
|
+
'display: flex; align-items: center; gap: var(--ui-space-3); min-inline-size: 0; margin-inline: calc(14px * var(--_t)); padding-block: calc(var(--ui-space-2-5) + 2px * var(--_t)) calc(var(--ui-space-2-5) + 1px * var(--_t)); padding-inline: calc(var(--_i) * var(--_f)) calc(var(--ui-space-3) * var(--_f)); border-block-end: 1px solid var(--_hl); color: var(--ui-text-muted)',
|
|
219
|
+
'(document:pointerdown)': 'outside($event)',
|
|
220
|
+
},
|
|
221
|
+
template: `
|
|
222
|
+
<span class="lb" [id]="uid + 'l'" style="flex: none">{{ t().to }}</span>
|
|
223
|
+
<span class="pk" style="position: relative; display: flex; flex: none; min-inline-size: 0; max-inline-size: calc(100% - 9em); margin-inline-start: calc(var(--ui-space-1) * -1)">
|
|
224
|
+
<button #trigger type="button" class="pill" [id]="uid + 't'" aria-haspopup="listbox" [attr.aria-expanded]="open()"
|
|
225
|
+
[attr.aria-controls]="open() ? uid + 'x' : null" [attr.aria-labelledby]="uid + 'l ' + uid + 't'"
|
|
226
|
+
[title]="value() ? value()!.name + ' <' + value()!.email + '>' : ''" (click)="toggle($event)" (keydown)="triggerKey($event)"
|
|
227
|
+
style="gap: calc(var(--ui-space-1-5) - 2px * var(--_t)); min-inline-size: 0; block-size: calc(var(--_e) - 2px * var(--_t)); padding-inline: calc(var(--ui-space-2-5) - 2px * var(--_t)) var(--ui-space-1-5); border-radius: calc(var(--ui-radius-sm) + 2px * var(--_t))">
|
|
228
|
+
<span dir="auto" style="flex: 0 1 auto; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ui-text); font-weight: calc(var(--ui-weight-medium) - 100 * var(--_t))">{{ value()?.name }}</span>
|
|
229
|
+
<span class="em" style="flex: 0 100 auto; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap"><span class="tr">(</span>{{ value()?.email }}<span class="tr">)</span></span>
|
|
230
|
+
<svg class="ui-icon cv" viewBox="0 0 16 16" aria-hidden="true" [style]="icon" style="color: var(--_ic)"><path d="M4.5 6.5 8 10l3.5-3.5" /></svg>
|
|
231
|
+
</button>
|
|
232
|
+
@if (open()) {
|
|
233
|
+
<div #list class="list" role="listbox" tabindex="-1" [id]="uid + 'x'" [attr.aria-label]="t().recipient"
|
|
234
|
+
[attr.aria-activedescendant]="active() < 0 ? null : uid + 'o' + active()" [attr.data-up]="up() || null"
|
|
235
|
+
(keydown)="listKey($event)" (focusout)="lost($event)"
|
|
236
|
+
style="position: absolute; inset-inline-start: 0; z-index: 5; display: grid; gap: var(--ui-space-0-5); box-sizing: border-box; inline-size: calc(260px - 10px * var(--_t)); max-block-size: min(320px, 50vh); overflow: auto; padding: calc(var(--ui-space-1) + 1px * var(--_t)); border-radius: calc(var(--ui-radius-md) + 2px + 2px * var(--_t)); outline: 0; background: var(--ui-bg-surface); box-shadow: 0 0 0 calc(0.5px + 0.5px * var(--_t)) var(--_hl), 0 calc(12px - 2px * var(--_t)) calc(28px + 2px * var(--_t)) calc(-10px + 10px * var(--_t)) color-mix(in srgb, var(--ui-gray-1000) 14%, transparent), 0 1px 2px var(--_s)">
|
|
237
|
+
@for (c of contacts(); track $index; let i = $index) {
|
|
238
|
+
<div class="opt" role="option" [id]="uid + 'o' + i" [attr.aria-selected]="same(c)" [attr.data-active]="i === active() || null"
|
|
239
|
+
(pointermove)="active.set(i)" (click)="choose(c)"
|
|
240
|
+
style="display: flex; align-items: center; gap: var(--ui-space-2-5); padding: calc(var(--ui-space-1-5) + 1.5px * var(--_t)) var(--ui-space-2); border-radius: calc(var(--ui-radius-sm) + 2px * var(--_t)); color: var(--ui-text); cursor: pointer">
|
|
241
|
+
<span aria-hidden="true" style="display: grid; place-items: center; flex: none; inline-size: calc(var(--ui-space-6) + var(--ui-space-1) - 2px * var(--_t)); aspect-ratio: 1; border-radius: calc(var(--ui-radius-sm) + 7px * var(--_t)); background: color-mix(in srgb, var(--ui-text) 6%, transparent); box-shadow: inset 0 0 0 calc(1px * var(--_t)) var(--_hl); color: var(--ui-text-muted); font-size: calc(10px + 0.5px * var(--_t)); font-weight: calc(var(--ui-weight-medium) + 100 * var(--_t)); line-height: var(--ui-leading-base); letter-spacing: calc(0.5px - 0.5px * var(--_t))">{{ initials(c) }}</span>
|
|
242
|
+
<span style="display: grid; flex: 1; min-inline-size: 0"><span dir="auto">{{ c.name }}</span><small style="color: var(--ui-text-muted); font-size: var(--ui-text-sm); line-height: var(--ui-leading-xs)">{{ c.email }}</small></span>
|
|
243
|
+
@if (same(c)) {
|
|
244
|
+
<svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true" [style]="icon" style="margin-inline-start: auto; color: color-mix(in srgb, var(--ui-text) calc(100% * var(--_t)), var(--ui-hue-blue))"><path d="m3.5 8.5 3 3 6-7" /></svg>
|
|
245
|
+
}
|
|
246
|
+
</div>
|
|
247
|
+
}
|
|
248
|
+
</div>
|
|
249
|
+
}
|
|
250
|
+
</span>
|
|
251
|
+
@if (file(); as f) {
|
|
252
|
+
<span style="display: flex; flex: 0 1 auto; align-items: center; gap: calc(var(--ui-space-1-5) - 1px * var(--_t)); min-inline-size: 0; margin-inline-start: auto">
|
|
253
|
+
<svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true" [style]="icon" style="color: var(--_ic)"><path d="m12.5 7.5-4.6 4.6a3 3 0 0 1-4.2-4.2l5-5a2 2 0 0 1 2.8 2.8l-5 5a1 1 0 0 1-1.4-1.4l4.6-4.6" /></svg>
|
|
254
|
+
<span [title]="f" [style]="cut">{{ f }}</span>
|
|
255
|
+
<button type="button" class="x" [attr.aria-label]="t().remove(f)" (click)="drop()"
|
|
256
|
+
style="position: relative; justify-content: center; flex: none; inline-size: var(--_xs); aspect-ratio: 1; margin-inline-start: -2px; border-radius: var(--ui-radius-sm)">
|
|
257
|
+
<svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true" style="inline-size: calc(var(--ui-icon-sm) - 1px * var(--_t)); block-size: calc(var(--ui-icon-sm) - 1px * var(--_t))"><path d="m4.5 4.5 7 7m0-7-7 7" /></svg>
|
|
258
|
+
</button>
|
|
259
|
+
</span>
|
|
260
|
+
} @else if (addable(); as f) {
|
|
261
|
+
<button type="button" class="add" (click)="add(f)"
|
|
262
|
+
style="flex: 0 1 auto; gap: calc(var(--ui-space-1-5) - 2px * var(--_t)); min-inline-size: 0; block-size: calc(var(--_e) - 3.4px * var(--_t)); margin-inline-start: auto; padding-inline: var(--ui-space-1-5) calc(var(--ui-space-2) - 2px * var(--_t)); border-radius: calc(var(--ui-radius-sm) + 2px * var(--_t)); animation: ui-fade-in calc(220ms * var(--_f) * var(--ui-motion-scale)) var(--ui-ease-out)">
|
|
263
|
+
<svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true" [style]="icon"><path d="M8 3.5v9M3.5 8h9" /></svg>
|
|
264
|
+
<span [style]="cut">{{ t().attach(f) }}</span>
|
|
265
|
+
</button>
|
|
266
|
+
}
|
|
267
|
+
`,
|
|
268
|
+
styles: `
|
|
269
|
+
:host { --_xs: calc(var(--ui-space-6) - var(--ui-space-1) * var(--_t)); }
|
|
270
|
+
button { display: inline-flex; align-items: center; margin: 0; border: 0; padding: 0; background: none; color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: calc(160ms * var(--ui-motion-scale)) var(--ui-ease-out); transition-property: background-color, box-shadow, color; }
|
|
271
|
+
button:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
272
|
+
.pill { background: color-mix(in srgb, var(--ui-text) calc(2.5% * var(--_t)), transparent); box-shadow: inset 0 0 0 1px var(--_hl); }
|
|
273
|
+
.pill[aria-expanded='true'] { background: color-mix(in srgb, var(--ui-text) calc(5% - 2.5% * var(--_t)), transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--_hl) calc(100% * var(--_t)), transparent); }
|
|
274
|
+
@media (hover: hover) { .pill:hover { background: color-mix(in srgb, var(--ui-text) calc(5% - 2.5% * var(--_t)), transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--_hl) calc(100% * var(--_t)), transparent); } }
|
|
275
|
+
.cv { transition: rotate calc(220ms * var(--ui-motion-scale)) var(--ui-ease-out); }
|
|
276
|
+
[aria-expanded='true'] .cv { rotate: 180deg; }
|
|
277
|
+
.tr { display: none; }
|
|
278
|
+
@container style(--ui-look-tray: 1) { .tr { display: inline; } .lb { text-transform: lowercase; } }
|
|
279
|
+
.list { inset-block-start: calc(100% + var(--ui-space-1-5)); transform-origin: 0 0; animation: in calc(200ms * var(--ui-motion-scale)) var(--ui-ease-out); }
|
|
280
|
+
.list:dir(rtl) { transform-origin: 100% 0; }
|
|
281
|
+
.list[data-up] { inset-block: auto calc(100% + var(--ui-space-1-5)); transform-origin: 50% 100%; }
|
|
282
|
+
@keyframes in { from { opacity: 0; scale: 0.96; } }
|
|
283
|
+
.opt[data-active] { background: color-mix(in srgb, var(--ui-text) calc(6.5% - 1.5% * var(--_t)), transparent); }
|
|
284
|
+
.x { color: var(--_ic); }
|
|
285
|
+
.x::after { content: ''; position: absolute; inset: -2px; }
|
|
286
|
+
.add { background: color-mix(in srgb, var(--ui-text) 4%, transparent); color: color-mix(in srgb, var(--ui-text) calc(100% * var(--_t)), var(--ui-text-muted)); }
|
|
287
|
+
@media (hover: hover) {
|
|
288
|
+
.x:hover, .add:hover { background: color-mix(in srgb, var(--ui-text) 4%, transparent); color: var(--ui-text); }
|
|
289
|
+
.add:hover { background: color-mix(in srgb, var(--ui-text) 7%, transparent); }
|
|
290
|
+
}
|
|
291
|
+
@container (width < 440px) { .em { display: none; } }
|
|
292
|
+
@media (pointer: coarse) { :host { --_xs: calc(var(--ui-space-8) - 2px - 10px * var(--_t)); } }
|
|
293
|
+
@media (forced-colors: active) {
|
|
294
|
+
.pill, .add, .list { border: 1px solid; }
|
|
295
|
+
.opt[data-active] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
296
|
+
.opt svg, .opt[data-active] * { color: inherit !important; }
|
|
297
|
+
.opt[data-active] * { background: none !important; }
|
|
298
|
+
}
|
|
299
|
+
`,
|
|
300
|
+
})
|
|
301
|
+
export class UiEmailDraftTo {
|
|
302
|
+
readonly contacts = input.required<readonly DraftContact[]>();
|
|
303
|
+
readonly value = input<DraftContact | null>(null);
|
|
304
|
+
readonly file = input<string | null>(null);
|
|
305
|
+
readonly addable = input<string | null>(null);
|
|
306
|
+
readonly t = input.required<EmailDraftLabels>();
|
|
307
|
+
readonly locked = input(false);
|
|
308
|
+
readonly pick = output<DraftContact>();
|
|
309
|
+
readonly fileChange = output<string | null>();
|
|
310
|
+
|
|
311
|
+
protected readonly uid = `ui-email-draft-${nextId++}-`;
|
|
312
|
+
protected readonly open = signal(false);
|
|
313
|
+
protected readonly active = signal(-1);
|
|
314
|
+
protected readonly up = signal(false);
|
|
315
|
+
private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
316
|
+
private readonly injector = inject(Injector);
|
|
317
|
+
private readonly trigger = viewChild.required<ElementRef<HTMLButtonElement>>('trigger');
|
|
318
|
+
private readonly list = viewChild<ElementRef<HTMLElement>>('list');
|
|
319
|
+
private typed = '';
|
|
320
|
+
private typedAt = 0;
|
|
321
|
+
|
|
322
|
+
protected readonly initials = initialsOf;
|
|
323
|
+
protected readonly icon = 'inline-size: calc(var(--ui-icon-md) - 1px * var(--_t)); block-size: calc(var(--ui-icon-md) - 1px * var(--_t))';
|
|
324
|
+
protected readonly cut = 'min-inline-size: 3em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap';
|
|
325
|
+
protected same(c: DraftContact) {
|
|
326
|
+
return sameContact(c, this.value());
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private selected() {
|
|
330
|
+
return Math.max(0, this.contacts().findIndex((c) => this.same(c)));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
protected toggle(e: MouseEvent) {
|
|
334
|
+
if (this.open()) this.close(true);
|
|
335
|
+
else this.show(e.detail ? -1 : this.selected());
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private show(at: number) {
|
|
339
|
+
if (this.locked() || !this.contacts().length) return;
|
|
340
|
+
this.active.set(at);
|
|
341
|
+
this.open.set(true);
|
|
342
|
+
afterNextRender(
|
|
343
|
+
() => {
|
|
344
|
+
const list = this.list()?.nativeElement;
|
|
345
|
+
if (!list) return;
|
|
346
|
+
const r = this.trigger().nativeElement.getBoundingClientRect();
|
|
347
|
+
const view = list.ownerDocument.defaultView;
|
|
348
|
+
this.up.set(!!view && view.innerHeight - r.bottom < list.offsetHeight + 12 && r.top > list.offsetHeight + 12);
|
|
349
|
+
list.focus({ preventScroll: true });
|
|
350
|
+
this.reveal();
|
|
351
|
+
},
|
|
352
|
+
{ injector: this.injector },
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
close(refocus: boolean) {
|
|
357
|
+
if (!this.open()) return;
|
|
358
|
+
this.open.set(false);
|
|
359
|
+
if (refocus) this.trigger().nativeElement.focus();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
protected choose(c: DraftContact) {
|
|
363
|
+
this.pick.emit(c);
|
|
364
|
+
this.close(true);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
protected triggerKey(e: KeyboardEvent) {
|
|
368
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
|
|
369
|
+
e.preventDefault();
|
|
370
|
+
this.show(e.key === 'ArrowUp' ? this.contacts().length - 1 : this.selected());
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
protected listKey(e: KeyboardEvent) {
|
|
374
|
+
const n = this.contacts().length;
|
|
375
|
+
const at = this.active();
|
|
376
|
+
let next = -1;
|
|
377
|
+
switch (e.key) {
|
|
378
|
+
case 'ArrowDown':
|
|
379
|
+
next = at < 0 ? this.selected() : Math.min(n - 1, at + 1);
|
|
380
|
+
break;
|
|
381
|
+
case 'ArrowUp':
|
|
382
|
+
next = at < 0 ? this.selected() : Math.max(0, at - 1);
|
|
383
|
+
break;
|
|
384
|
+
case 'Home':
|
|
385
|
+
next = 0;
|
|
386
|
+
break;
|
|
387
|
+
case 'End':
|
|
388
|
+
next = n - 1;
|
|
389
|
+
break;
|
|
390
|
+
case 'Enter':
|
|
391
|
+
case ' ':
|
|
392
|
+
e.preventDefault();
|
|
393
|
+
if (at >= 0) this.choose(this.contacts()[at]);
|
|
394
|
+
else this.close(true);
|
|
395
|
+
return;
|
|
396
|
+
case 'Escape':
|
|
397
|
+
e.preventDefault();
|
|
398
|
+
e.stopPropagation();
|
|
399
|
+
this.close(true);
|
|
400
|
+
return;
|
|
401
|
+
case 'Tab':
|
|
402
|
+
if (e.shiftKey) e.preventDefault();
|
|
403
|
+
this.close(true);
|
|
404
|
+
return;
|
|
405
|
+
default:
|
|
406
|
+
if (e.key.length !== 1 || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
407
|
+
next = this.find(e.key, at);
|
|
408
|
+
if (next < 0) return;
|
|
409
|
+
}
|
|
410
|
+
e.preventDefault();
|
|
411
|
+
this.active.set(next);
|
|
412
|
+
this.reveal();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private find(key: string, at: number) {
|
|
416
|
+
const now = Date.now();
|
|
417
|
+
this.typed = (now - this.typedAt < 500 ? this.typed : '') + key.toLowerCase();
|
|
418
|
+
this.typedAt = now;
|
|
419
|
+
const list = this.contacts();
|
|
420
|
+
const from = this.typed.length > 1 ? Math.max(at, 0) : at + 1;
|
|
421
|
+
for (let k = 0; k < list.length; k++) {
|
|
422
|
+
const i = (from + k) % list.length;
|
|
423
|
+
if (list[i].name.toLowerCase().startsWith(this.typed)) return i;
|
|
424
|
+
}
|
|
425
|
+
return -1;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private reveal() {
|
|
429
|
+
afterNextRender(() => this.list()?.nativeElement.querySelector('[data-active]')?.scrollIntoView?.({ block: 'nearest' }), {
|
|
430
|
+
injector: this.injector,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
protected lost(e: FocusEvent) {
|
|
435
|
+
const to = e.relatedTarget as Node | null;
|
|
436
|
+
if (to && !this.list()?.nativeElement.contains(to)) this.close(false);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
protected outside(e: PointerEvent) {
|
|
440
|
+
if (this.open() && !this.el.querySelector('.pk')!.contains(e.target as Node)) this.close(false);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
protected drop() {
|
|
444
|
+
if (this.locked()) return;
|
|
445
|
+
this.fileChange.emit(null);
|
|
446
|
+
this.focusLater('.add');
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
protected add(f: string) {
|
|
450
|
+
if (this.locked()) return;
|
|
451
|
+
this.fileChange.emit(f);
|
|
452
|
+
this.focusLater('.x');
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
private focusLater(sel: string) {
|
|
456
|
+
afterNextRender(() => this.el.querySelector<HTMLElement>(sel)?.focus(), { injector: this.injector });
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
@Component({
|
|
461
|
+
selector: 'ui-email-draft',
|
|
462
|
+
imports: [NgTemplateOutlet, UiEmailDraftButton, UiEmailDraftTo],
|
|
463
|
+
host: {
|
|
464
|
+
role: 'group',
|
|
465
|
+
style:
|
|
466
|
+
'display: block; box-sizing: border-box; inline-size: 100%; max-inline-size: var(--ui-email-draft-max, calc(480px + 40px * var(--_t))); padding: calc(var(--ui-space-1-5) * var(--_t)); border-radius: calc(var(--ui-radius-md) + 2px + 10px * var(--_t)); background: color-mix(in srgb, var(--ui-tray-bg) calc(100% * var(--_t)), var(--ui-bg-surface)); box-shadow: 0 0 0 calc(0.5px * var(--_f)) var(--_hl), 0 1px 1px -1px var(--_d), 0 1px 2px var(--_d); color: var(--ui-text); font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans); animation: ui-fade-in calc(320ms * var(--ui-motion-scale)) var(--ui-ease-out)',
|
|
467
|
+
'[attr.aria-labelledby]': 'ariaLabel() ? null : labelledBy()',
|
|
468
|
+
'[attr.aria-label]': 'ariaLabel() || null',
|
|
469
|
+
'[attr.data-phase]': 'state()',
|
|
470
|
+
'(focusin)': 'inside = true',
|
|
471
|
+
'(focusout)': 'inside = host.contains($any($event).relatedTarget)',
|
|
472
|
+
},
|
|
473
|
+
template: `
|
|
474
|
+
<div class="q">
|
|
475
|
+
<header style="display: grid; gap: calc(2px * var(--_t)); padding: calc(var(--ui-space-3) - 4px * var(--_t)) calc(var(--_i) * var(--_f) + 10px * var(--_t)) calc(var(--ui-space-3) - 2px * var(--_t)); border-block-end: calc(1px * var(--_f)) solid var(--_hl)">
|
|
476
|
+
<div style="display: flex; align-items: center; gap: var(--ui-space-2); min-inline-size: 0; font: var(--ui-weight-medium) calc(var(--ui-text-md) + 1px) / var(--ui-leading-lg) var(--ui-font-sans); letter-spacing: calc(-0.15px * var(--_t))">
|
|
477
|
+
@if (reference()) {<span [id]="uid + 'r'" [title]="reference()" [style]="cut">{{ reference() }}</span>}
|
|
478
|
+
@if (status()) {<span dir="auto" [title]="status()" [style]="chip" [style.background]="tint(statusTone())[0]" [style.color]="tint(statusTone())[1]">{{ status() }}</span>}
|
|
479
|
+
@if (amount()) {<span style="margin-inline-start: auto; padding-inline-start: var(--ui-space-2); font-variant-numeric: tabular-nums; white-space: nowrap">{{ amount() }}</span>}
|
|
480
|
+
</div>
|
|
481
|
+
@if (account()) {<span dir="auto" [id]="uid + 'a'" style="color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 1px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 1px * var(--_t))">{{ account() }}</span>}
|
|
482
|
+
</header>
|
|
483
|
+
<div class="pn" [style.opacity]="busy() ? 0.6 : null"
|
|
484
|
+
style="position: relative; border: calc(1px * var(--_t)) solid var(--ui-bg-muted); border-radius: calc(16px * var(--_t)); background: var(--ui-bg-surface); box-shadow: 0 calc(1px * var(--_t)) calc(2px * var(--_t)) var(--_s); transition: opacity calc(220ms * var(--ui-motion-scale)) var(--ui-ease-out)">
|
|
485
|
+
<div #fold>
|
|
486
|
+
<div>
|
|
487
|
+
@if (open()) {
|
|
488
|
+
<ui-email-draft-to [contacts]="contacts()" [value]="recipient()" [file]="attachment()" [addable]="lastFile() ?? attachable()"
|
|
489
|
+
[t]="t()" [locked]="busy()" (pick)="to.set($event)" (fileChange)="attachment.set($event)" />
|
|
490
|
+
<div style="padding: calc(14px - 2px * var(--_t)) calc(var(--_i) * var(--_f) + 14px * var(--_t)) calc(2px + 2px * var(--_t))">
|
|
491
|
+
@if (editing()) {
|
|
492
|
+
<textarea #area class="ta" dir="auto" rows="2" [attr.aria-label]="t().body" aria-keyshortcuts="Meta+Enter Control+Enter"
|
|
493
|
+
[value]="body()" (input)="typed($event)" (keydown)="areaKey($event)" (blur)="stopEdit(false)" [style]="text"
|
|
494
|
+
style="box-sizing: border-box; inline-size: calc(100% + 12px); overflow: hidden; resize: none; field-sizing: content; background: var(--_w); box-shadow: inset 0 0 0 calc(0.5px + 0.5px * var(--_t)) var(--_hl); font-family: inherit"></textarea>
|
|
495
|
+
} @else {
|
|
496
|
+
@for (k of [textKey()]; track 'text' + k) {
|
|
497
|
+
<p class="tx" dir="auto" [title]="t().clickToEdit" (click)="textClick($event)" [style]="text"
|
|
498
|
+
style="cursor: text; transition: background-color calc(160ms * var(--ui-motion-scale)) var(--ui-ease-out); animation: ui-fade-in calc(280ms * var(--ui-motion-scale)) var(--ui-ease-out)">{{ body() }}{{ link() && body() ? ' ' : '' }}@if (link(); as l) {<a class="ln" [href]="l.href">{{ l.label }}</a>}</p>
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
</div>
|
|
502
|
+
<div style="display: flex; flex-wrap: wrap; align-items: center; gap: calc(var(--ui-space-3) - 2px * var(--_t)); padding-block: calc(14px - 4px * var(--_t)); padding-inline: calc(var(--_i) * var(--_f) + 14px * var(--_t)) calc(var(--ui-space-3) - 2px * var(--_t))">
|
|
503
|
+
<span class="tw" style="display: flex; align-items: center; gap: calc(var(--ui-space-2) - 2px * var(--_t))">
|
|
504
|
+
@if (tones().length) {
|
|
505
|
+
<span role="group" [attr.aria-label]="t().tone" style="display: flex; gap: var(--_g, calc(var(--ui-space-1) - 2px * var(--_t)))">
|
|
506
|
+
@for (o of tones(); track o.id) {
|
|
507
|
+
<button type="button" class="tn" [attr.aria-pressed]="!editing() && tone() === o.id" (click)="pickTone(o)" [style]="btn">{{ o.label }}</button>
|
|
508
|
+
}
|
|
509
|
+
</span>
|
|
510
|
+
}
|
|
511
|
+
<button #pen type="button" class="tn pe" [attr.aria-pressed]="editing()" [attr.aria-label]="t().edit" (mousedown)="$event.preventDefault()" (click)="toggleEdit()"
|
|
512
|
+
[style]="btn + '; inline-size: var(--_e); padding: 0'">
|
|
513
|
+
<svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true" style="inline-size: calc(var(--ui-icon-md) - 1px * var(--_t)); block-size: calc(var(--ui-icon-md) - 1px * var(--_t))"><path d="M10.6 3.2a1.4 1.4 0 0 1 2 2L5.8 12l-2.6.8.8-2.6z" /></svg>
|
|
514
|
+
</button>
|
|
515
|
+
</span>
|
|
516
|
+
<span class="cl"><ng-container *ngTemplateOutlet="hint; context: { $implicit: uid + 'h1' }" /></span>
|
|
517
|
+
<span class="tr"><ng-container *ngTemplateOutlet="actions; context: { $implicit: uid + 'h2' }" /></span>
|
|
518
|
+
</div>
|
|
519
|
+
@if (err(); as e) {
|
|
520
|
+
<div [style]="row" style="margin-inline: calc(14px * var(--_t)); padding-inline: calc(var(--_i) * var(--_f)) calc(var(--ui-space-3) * var(--_f)); border-block-start: 1px solid var(--_hl); color: var(--ui-danger); animation: ui-nudge calc(400ms * var(--ui-motion-scale)) var(--ui-ease-out)">
|
|
521
|
+
<span class="ti" aria-hidden="true" [style]="tile" style="background: var(--ui-danger-soft)"><svg class="ui-icon" viewBox="0 0 16 16" [style]="small"><path d="M8 4.8v3.7M8 11h.01" /></svg></span>
|
|
522
|
+
<span style="flex: 1; min-inline-size: 0; overflow-wrap: anywhere">{{ e }}</span>
|
|
523
|
+
<button type="button" uiEmailDraftBtn="quiet" style="margin-inline-start: auto" (click)="retryIt()">{{ t().retry }}</button>
|
|
524
|
+
</div>
|
|
525
|
+
}
|
|
526
|
+
} @else {
|
|
527
|
+
<div [style]="row" style="padding-inline: calc(var(--_i) * var(--_f) + 12px * var(--_t)) calc(var(--ui-space-3) - 2px * var(--_t)); color: color-mix(in srgb, var(--ui-text) calc(50% * var(--_t)), var(--ui-text-muted)); font-size: calc(var(--ui-text-base) + 1px * var(--_t))">
|
|
528
|
+
<span class="ti" aria-hidden="true" [style]="tile" [style.background]="state() === 'sent' ? 'var(--ui-success-soft)' : 'var(--_w)'"
|
|
529
|
+
[style.color]="state() === 'sent' ? 'var(--ui-success)' : 'var(--_ic)'">
|
|
530
|
+
<svg class="ui-icon" viewBox="0 0 16 16" [style]="small">
|
|
531
|
+
@if (state() === 'sent') {<path d="m3.5 8.5 3 3 6-7" />} @else {<path d="m4.5 4.5 7 7m0-7-7 7" />}
|
|
532
|
+
</svg>
|
|
533
|
+
</span>
|
|
534
|
+
<span [style]="cut">
|
|
535
|
+
@if (state() === 'sent') {
|
|
536
|
+
{{ t().sentTo }} <b dir="auto" style="color: var(--ui-text); font-weight: var(--ui-weight-medium)">{{ recipient()?.name }}</b>@if (attachment(); as f) { {{ t().with }} {{ f }} }
|
|
537
|
+
} @else {
|
|
538
|
+
{{ t().discarded }}
|
|
539
|
+
}
|
|
540
|
+
</span>
|
|
541
|
+
<button type="button" uiEmailDraftBtn="quiet" class="undo" style="margin-inline-start: auto" (click)="undoIt()">{{ t().undo }}</button>
|
|
542
|
+
</div>
|
|
543
|
+
}
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
</div>
|
|
547
|
+
<footer class="ft" style="display: flex; flex-wrap: wrap; align-items: center; gap: var(--ui-space-2); box-sizing: border-box; min-block-size: calc(48px * var(--_f)); padding-block: var(--ui-space-2-5) calc(var(--ui-space-2-5) - 4px * var(--_t)); padding-inline: calc(var(--_i) * var(--_f) + 10px * var(--_t)) var(--ui-space-2-5); border-block-start: calc(1px * var(--_f)) solid var(--_hl)">
|
|
548
|
+
@if (agent()) {<span [class.nx]="open()" [title]="agent()" [style]="cut" style="min-inline-size: 0; font-size: calc(var(--ui-text-base) + 1px * var(--_t))">{{ agent() }}</span>}
|
|
549
|
+
@for (k of [phase()]; track 'phase:' + k) {
|
|
550
|
+
<span [style]="chip" [style.background]="tint(k === 'discarded' ? 'neutral' : 'success')[0]" [style.color]="tint(k === 'discarded' ? 'neutral' : 'success')[1]">{{ k === 'sent' ? t().sentChip : k === 'discarded' ? t().discardedChip : t().ready }}</span>
|
|
551
|
+
}
|
|
552
|
+
@if (open()) {
|
|
553
|
+
<span class="cl"><ng-container *ngTemplateOutlet="actions; context: { $implicit: uid + 'h1' }" /></span>
|
|
554
|
+
<span class="tr"><ng-container *ngTemplateOutlet="hint; context: { $implicit: uid + 'h2' }" /></span>
|
|
555
|
+
}
|
|
556
|
+
</footer>
|
|
557
|
+
</div>
|
|
558
|
+
<p class="ui-sr" role="status">{{ said() }}</p>
|
|
559
|
+
|
|
560
|
+
<ng-template #hint let-id><span class="hn" dir="auto" [id]="id" style="margin-inline-start: auto; color: var(--ui-text-muted); font-size: var(--ui-text-sm); line-height: var(--ui-leading-xs); white-space: nowrap">{{ empty() ? t().emptyHint : t().shortcut(key) }}</span></ng-template>
|
|
561
|
+
<ng-template #actions let-hint>
|
|
562
|
+
<span style="display: flex; gap: var(--ui-space-2); margin-inline-start: auto">
|
|
563
|
+
<button type="button" uiEmailDraftBtn="secondary" [attr.aria-disabled]="busy() || null" (click)="discardIt()">{{ t().discard }}</button>
|
|
564
|
+
<button type="button" uiEmailDraftBtn="primary" class="send" [busy]="busy()" [class.off]="empty()"
|
|
565
|
+
[attr.aria-disabled]="busy() || empty() || null" [attr.aria-describedby]="empty() ? hint : null" (click)="send()">{{ busy() ? t().sending : t().send }}</button>
|
|
566
|
+
</span>
|
|
567
|
+
</ng-template>
|
|
568
|
+
`,
|
|
569
|
+
styles: `
|
|
570
|
+
:host {
|
|
571
|
+
--_t: var(--ui-look-tray, 0);
|
|
572
|
+
--_f: calc(1 - var(--_t));
|
|
573
|
+
--_i: var(--ui-space-4);
|
|
574
|
+
--_e: calc(var(--ui-space-6) + var(--ui-space-1));
|
|
575
|
+
--_hl: color-mix(in srgb, var(--ui-bg-muted) 88%, var(--ui-bg-surface));
|
|
576
|
+
--_s: color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
|
|
577
|
+
--_d: color-mix(in srgb, var(--_s) calc(100% * var(--_f)), transparent);
|
|
578
|
+
--_w: color-mix(in srgb, var(--ui-text) 4%, transparent);
|
|
579
|
+
--_p: calc(var(--ui-space-2-5) - 1px * var(--_t));
|
|
580
|
+
--_ic: light-dark(color-mix(in srgb, var(--ui-icon) 72%, var(--ui-bg-surface)), color-mix(in srgb, var(--ui-icon) 85%, var(--ui-bg-surface)));
|
|
581
|
+
}
|
|
582
|
+
:host::before { content: 'x x x x x x x x' / ''; display: block; block-size: 0; overflow: hidden; font-size: 0; word-spacing: calc(var(--ui-email-draft-max, calc(480px + 40px * var(--_t))) / 7); }
|
|
583
|
+
.q { container-type: inline-size; }
|
|
584
|
+
@media (hover: hover) { .tx:hover { background: var(--_w); } }
|
|
585
|
+
.ln { color: color-mix(in srgb, var(--ui-text) calc(100% * var(--_f)), currentColor); font-weight: calc(var(--ui-weight-medium) - 100 * var(--_t)); text-decoration: underline calc(1px + 0.5px * var(--_t)) color-mix(in srgb, currentColor 30%, transparent); text-underline-offset: calc(3px + 1px * var(--_t)); transition: text-decoration-color calc(160ms * var(--ui-motion-scale)); }
|
|
586
|
+
@media (hover: hover) { .ln:hover { text-decoration-color: currentColor; } }
|
|
587
|
+
a:focus-visible, .tn:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
588
|
+
.ta { border: 0; outline: 0; }
|
|
589
|
+
.tn { --_r: color-mix(in srgb, var(--_hl) calc(100% * var(--_f)), transparent); border: 0; background: none; box-shadow: inset 0 0 0 1px var(--_r); color: var(--ui-text-muted); }
|
|
590
|
+
@media (hover: hover) { .tn:hover { background: color-mix(in srgb, var(--ui-text) calc(3% * var(--_t)), transparent); color: var(--ui-text); } }
|
|
591
|
+
.tn[aria-pressed='true'] { --_r: var(--_hl); background: color-mix(in srgb, var(--ui-text) calc(6.5% - 4% * var(--_t)), transparent); color: var(--ui-text); }
|
|
592
|
+
.tn:active { scale: calc(0.97 + 0.01 * var(--_t)); }
|
|
593
|
+
.pe:not([aria-pressed='true']) { --_r: transparent; }
|
|
594
|
+
.pe { color: var(--_ic); }
|
|
595
|
+
.tr { display: none; }
|
|
596
|
+
.cl { display: contents; }
|
|
597
|
+
@container style(--ui-look-tray: 1) { .cl { display: none; } .tr { display: contents; } }
|
|
598
|
+
@container (width < 420px) { .hn { display: none; } }
|
|
599
|
+
@container (width < 380px) {
|
|
600
|
+
header, .pn, .ft { --_i: 14px; }
|
|
601
|
+
.tw { --_g: 2px; --_p: calc(var(--ui-space-2) + 1px * var(--_t)); }
|
|
602
|
+
.nx { display: none; }
|
|
603
|
+
@container style(--ui-look-tray: 1) { .nx { display: block; } }
|
|
604
|
+
}
|
|
605
|
+
@media (pointer: coarse) { :host { --_e: calc(var(--ui-space-8) + 2px - 6px * var(--_t)); } }
|
|
606
|
+
@media (forced-colors: active) {
|
|
607
|
+
:host { outline: calc(1px * var(--_f)) solid; }
|
|
608
|
+
.tn, .ta, .ti { border: 1px solid; }
|
|
609
|
+
.tn[aria-pressed='true'] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
610
|
+
}
|
|
611
|
+
`,
|
|
612
|
+
})
|
|
613
|
+
export class UiEmailDraft {
|
|
614
|
+
/** What the email is about, at the start of the header: an invoice, a subscription, a ticket. Also the card's name. */
|
|
615
|
+
readonly reference = input<string>();
|
|
616
|
+
/** The account or company, under the reference. */
|
|
617
|
+
readonly account = input<string>();
|
|
618
|
+
/** An amount at the end of the header. */
|
|
619
|
+
readonly amount = input<string>();
|
|
620
|
+
/** A short status chip after the reference. */
|
|
621
|
+
readonly status = input<string>();
|
|
622
|
+
readonly statusTone = input<EmailDraftStatusTone>('warning');
|
|
623
|
+
/** Who wrote the draft, at the start of the last row. */
|
|
624
|
+
readonly agent = input<string>();
|
|
625
|
+
/** People the email can go to. The first one is picked until `to` is set. */
|
|
626
|
+
readonly contacts = input.required<readonly DraftContact[]>();
|
|
627
|
+
/** The recipient. `null` means the first contact. */
|
|
628
|
+
readonly to = model<DraftContact | null>(null);
|
|
629
|
+
/** Text variants. The row of tone buttons is hidden when there are none. */
|
|
630
|
+
readonly tones = input<readonly DraftTone[]>([]);
|
|
631
|
+
/** The pressed tone's id; `null` once the text is edited by hand. With tones and no body, the first tone is picked. */
|
|
632
|
+
readonly tone = model<string | null>(null);
|
|
633
|
+
/** The email text, whether a tone wrote it or the reviewer did. */
|
|
634
|
+
readonly body = model('');
|
|
635
|
+
/** The attached file's name; `null` when there is none. Removing it keeps the name so it can be added back. */
|
|
636
|
+
readonly attachment = model<string | null>(null);
|
|
637
|
+
/** A file that can be attached while `attachment` is null, for drafts that start without it. */
|
|
638
|
+
readonly attachable = input<string | null>(null);
|
|
639
|
+
/** A link shown after the text and sent along in the payload. */
|
|
640
|
+
readonly link = input<DraftLink | null>(null);
|
|
641
|
+
/** draft, sending (after Send, until you set sent or draft), sent or discarded. */
|
|
642
|
+
readonly state = model<EmailDraftState>('draft');
|
|
643
|
+
/** Why the last send failed. Shown above the last row with Retry until the next edit or send. */
|
|
644
|
+
readonly error = input<string | null>(null);
|
|
645
|
+
/** ⌘ Enter or Ctrl Enter in the text sends it. */
|
|
646
|
+
readonly submitShortcut = input(true, { transform: booleanAttribute });
|
|
647
|
+
readonly labels = input<Partial<EmailDraftLabels>>({});
|
|
648
|
+
/** A name for the card when there is no reference. */
|
|
649
|
+
readonly ariaLabel = input<string>(undefined, { alias: 'aria-label' });
|
|
650
|
+
|
|
651
|
+
/** Send was pressed. `state` is now 'sending': set it to 'sent' when delivery is accepted, or back to 'draft' with an `error`. */
|
|
652
|
+
readonly send$ = output<EmailDraftPayload>({ alias: 'send' });
|
|
653
|
+
readonly discard = output<void>();
|
|
654
|
+
/** Undo was pressed after a send or a discard; the draft is back as it was. */
|
|
655
|
+
readonly undo = output<'sent' | 'discarded'>();
|
|
656
|
+
|
|
657
|
+
protected readonly uid = `ui-email-draft-${nextId++}-`;
|
|
658
|
+
protected readonly cut = 'overflow: hidden; text-overflow: ellipsis; white-space: nowrap';
|
|
659
|
+
protected readonly chip =
|
|
660
|
+
'flex: none; padding: 2px calc(var(--ui-space-1-5) + 2px * var(--_t)); border-radius: calc(5px + 3px * var(--_t)); font: var(--ui-weight-medium) calc(var(--ui-text-sm) + 0.5px * var(--_t)) / calc(var(--ui-leading-xs) + 2.6px * var(--_t)) var(--ui-font-sans); letter-spacing: 0; white-space: nowrap; animation: ui-fade-in calc(260ms * var(--ui-motion-scale)) var(--ui-ease-out)';
|
|
661
|
+
protected readonly text =
|
|
662
|
+
'display: block; margin: -4px -6px; padding: 4px 6px; border-radius: calc(var(--ui-radius-sm) + 2px * var(--_t)); color: color-mix(in srgb, var(--ui-text) calc(100% - 50% * var(--_t)), var(--ui-text-muted)); font-size: calc(var(--ui-text-base) + 2px * var(--_t)); line-height: calc(var(--ui-leading-base) + 4px * var(--_t)); white-space: pre-wrap; overflow-wrap: anywhere';
|
|
663
|
+
protected readonly btn =
|
|
664
|
+
'display: inline-grid; place-items: center; box-sizing: border-box; block-size: var(--_e); margin: 0; padding: 0 var(--_p); border-radius: calc(var(--ui-radius-sm) + 2px * var(--_t)); font: inherit; font-size: calc(var(--ui-text-base) - 0.5px * var(--_t)); font-weight: calc(var(--ui-weight-medium) - 100 * var(--_t)); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: calc(160ms * var(--ui-motion-scale)) var(--ui-ease-out); transition-property: background-color, box-shadow, color, scale';
|
|
665
|
+
protected readonly row = 'display: flex; align-items: center; gap: var(--ui-space-2-5); padding-block: var(--ui-space-3)';
|
|
666
|
+
protected readonly tile =
|
|
667
|
+
'display: grid; place-items: center; flex: none; inline-size: calc(var(--ui-space-6) + 2px * var(--_t)); aspect-ratio: 1; border-radius: calc(var(--ui-radius-sm) + 7px * var(--_t))';
|
|
668
|
+
protected readonly small = 'inline-size: var(--ui-icon-sm); block-size: var(--ui-icon-sm)';
|
|
669
|
+
protected tint(tone: EmailDraftStatusTone): [string, string] {
|
|
670
|
+
if (tone === 'neutral') return ['var(--_w)', 'var(--ui-text-muted)'];
|
|
671
|
+
const ink = `var(--ui-${tone})`;
|
|
672
|
+
return [
|
|
673
|
+
`var(--ui-${tone}-soft)`,
|
|
674
|
+
tone === 'warning' ? `color-mix(in srgb, ${ink} calc(100% * var(--_t)), light-dark(oklch(from var(--ui-hue-amber) calc(l - .2) calc(c * .7) h), var(--ui-hue-amber)))` : ink,
|
|
675
|
+
];
|
|
676
|
+
}
|
|
677
|
+
protected readonly t = computed<EmailDraftLabels>(() => ({ ...EMAIL_DRAFT_LABELS, ...this.labels() }));
|
|
678
|
+
protected readonly recipient = computed(() => this.to() ?? this.contacts()[0] ?? null);
|
|
679
|
+
protected readonly toneDef = computed(() => this.tones().find((o) => o.id === this.tone()) ?? null);
|
|
680
|
+
protected readonly open = computed(() => this.state() === 'draft' || this.state() === 'sending');
|
|
681
|
+
protected readonly busy = computed(() => this.state() === 'sending');
|
|
682
|
+
protected readonly empty = computed(() => !this.body().trim());
|
|
683
|
+
protected readonly phase = computed(() => (this.open() ? 'ready' : this.state()));
|
|
684
|
+
protected readonly editing = signal(false);
|
|
685
|
+
protected readonly textKey = signal(0);
|
|
686
|
+
protected readonly said = signal('');
|
|
687
|
+
protected readonly err = linkedSignal(() => this.error());
|
|
688
|
+
protected readonly lastFile = linkedSignal<string | null, string | null>({
|
|
689
|
+
source: this.attachment,
|
|
690
|
+
computation: (file, prev) => file ?? prev?.value ?? null,
|
|
691
|
+
});
|
|
692
|
+
protected readonly labelledBy = computed(() => [this.reference() ? this.uid + 'r' : '', this.account() ? this.uid + 'a' : ''].join(' ').trim() || null);
|
|
693
|
+
|
|
694
|
+
protected readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
695
|
+
protected inside = false;
|
|
696
|
+
private readonly doc = inject(DOCUMENT);
|
|
697
|
+
private readonly injector = inject(Injector);
|
|
698
|
+
private readonly destroyRef = inject(DestroyRef);
|
|
699
|
+
private readonly area = viewChild<ElementRef<HTMLTextAreaElement>>('area');
|
|
700
|
+
private readonly penEl = viewChild<ElementRef<HTMLButtonElement>>('pen');
|
|
701
|
+
private readonly foldEl = viewChild.required<ElementRef<HTMLElement>>('fold');
|
|
702
|
+
private snapshot: { to: DraftContact | null; tone: string | null; body: string; attachment: string | null } | null = null;
|
|
703
|
+
protected readonly key = /Mac|iPhone|iPad|iPod/.test(this.doc.defaultView?.navigator.platform ?? '') ? '⌘' : 'Ctrl';
|
|
704
|
+
|
|
705
|
+
constructor() {
|
|
706
|
+
effect(() => {
|
|
707
|
+
const tone = this.toneDef();
|
|
708
|
+
const to = this.recipient();
|
|
709
|
+
if (tone && to && untracked(this.state) === 'draft') untracked(() => this.body.set(tone.body(to)));
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
effect(() => {
|
|
713
|
+
const e = this.err();
|
|
714
|
+
if (e) untracked(() => this.said.set(e));
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
let was = untracked(this.state);
|
|
718
|
+
effect(() => {
|
|
719
|
+
const now = this.state();
|
|
720
|
+
const before = was;
|
|
721
|
+
was = now;
|
|
722
|
+
if (now === before) return;
|
|
723
|
+
untracked(() => {
|
|
724
|
+
const inside = this.inside;
|
|
725
|
+
if (now === 'sent' || now === 'discarded') {
|
|
726
|
+
this.snapshot ??= this.take();
|
|
727
|
+
this.editing.set(false);
|
|
728
|
+
this.said.set(this.receipt(now));
|
|
729
|
+
if (inside) this.focus('.undo');
|
|
730
|
+
} else if (now === 'draft' && before === 'sending') {
|
|
731
|
+
this.err.set(this.error());
|
|
732
|
+
if (inside) this.focus('.send');
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
afterNextRender(() => {
|
|
738
|
+
if (isDevMode() && !this.reference() && !this.ariaLabel()) {
|
|
739
|
+
console.warn('ui-email-draft: give it a reference or an aria-label, so the card has a name.', this.host);
|
|
740
|
+
}
|
|
741
|
+
if (isDevMode() && !this.contacts().length) console.warn('ui-email-draft: contacts is empty, so there is no one to send to.', this.host);
|
|
742
|
+
this.glide();
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
ngOnInit() {
|
|
747
|
+
if (this.tone() === null && !this.body() && this.tones().length) this.tone.set(this.tones()[0].id);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
protected pickTone(o: DraftTone) {
|
|
751
|
+
if (this.busy()) return;
|
|
752
|
+
this.err.set(null);
|
|
753
|
+
this.tone.set(o.id);
|
|
754
|
+
const to = this.recipient();
|
|
755
|
+
if (to) this.body.set(o.body(to));
|
|
756
|
+
this.textKey.update((k) => k + 1);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
protected textClick(e: MouseEvent) {
|
|
760
|
+
if (!(e.target as HTMLElement).closest('a')) this.startEdit();
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
protected toggleEdit() {
|
|
764
|
+
if (this.editing()) this.stopEdit(true);
|
|
765
|
+
else this.startEdit();
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
private startEdit() {
|
|
769
|
+
if (this.busy()) return;
|
|
770
|
+
this.editing.set(true);
|
|
771
|
+
afterNextRender(
|
|
772
|
+
() => {
|
|
773
|
+
const ta = this.area()?.nativeElement;
|
|
774
|
+
if (!ta) return;
|
|
775
|
+
this.fit(ta);
|
|
776
|
+
ta.focus();
|
|
777
|
+
ta.setSelectionRange(ta.value.length, ta.value.length);
|
|
778
|
+
},
|
|
779
|
+
{ injector: this.injector },
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
stopEdit(refocus: boolean) {
|
|
784
|
+
if (!this.editing()) return;
|
|
785
|
+
this.editing.set(false);
|
|
786
|
+
this.textKey.update((k) => k + 1);
|
|
787
|
+
if (refocus) this.penEl()?.nativeElement.focus();
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
protected typed(e: Event) {
|
|
791
|
+
const ta = e.target as HTMLTextAreaElement;
|
|
792
|
+
this.body.set(ta.value);
|
|
793
|
+
this.tone.set(null);
|
|
794
|
+
this.err.set(null);
|
|
795
|
+
this.fit(ta);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
private fit(ta: HTMLTextAreaElement) {
|
|
799
|
+
if (this.doc.defaultView?.CSS?.supports?.('field-sizing', 'content')) return;
|
|
800
|
+
ta.style.height = 'auto';
|
|
801
|
+
ta.style.height = `${ta.scrollHeight}px`;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
protected areaKey(e: KeyboardEvent) {
|
|
805
|
+
if (e.key === 'Escape') {
|
|
806
|
+
e.preventDefault();
|
|
807
|
+
this.stopEdit(true);
|
|
808
|
+
} else if (e.key === 'Enter' && (e.metaKey || e.ctrlKey) && !e.isComposing && this.submitShortcut()) {
|
|
809
|
+
e.preventDefault();
|
|
810
|
+
if (this.empty()) return;
|
|
811
|
+
this.editing.set(false);
|
|
812
|
+
this.textKey.update((k) => k + 1);
|
|
813
|
+
this.send();
|
|
814
|
+
this.focus('.send');
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/** Sends the draft as it is now, as if Send were pressed. */
|
|
819
|
+
send() {
|
|
820
|
+
const to = this.recipient();
|
|
821
|
+
if (this.state() !== 'draft' || this.empty() || !to) return;
|
|
822
|
+
this.snapshot = this.take();
|
|
823
|
+
this.err.set(null);
|
|
824
|
+
this.state.set('sending');
|
|
825
|
+
this.said.set(this.t().sending);
|
|
826
|
+
this.send$.emit({ to, body: this.body(), attachment: this.attachment(), tone: this.tone(), link: this.link() });
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
protected retryIt() {
|
|
830
|
+
this.inside = true;
|
|
831
|
+
this.send();
|
|
832
|
+
this.focus('.send');
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
protected discardIt() {
|
|
836
|
+
if (this.state() !== 'draft') return;
|
|
837
|
+
this.snapshot = this.take();
|
|
838
|
+
this.err.set(null);
|
|
839
|
+
this.state.set('discarded');
|
|
840
|
+
this.discard.emit();
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
protected undoIt() {
|
|
844
|
+
const was = this.state();
|
|
845
|
+
if (was !== 'sent' && was !== 'discarded') return;
|
|
846
|
+
const s = this.snapshot;
|
|
847
|
+
this.snapshot = null;
|
|
848
|
+
if (s) {
|
|
849
|
+
this.to.set(s.to);
|
|
850
|
+
this.tone.set(s.tone);
|
|
851
|
+
this.body.set(s.body);
|
|
852
|
+
this.attachment.set(s.attachment);
|
|
853
|
+
}
|
|
854
|
+
this.state.set('draft');
|
|
855
|
+
this.textKey.update((k) => k + 1);
|
|
856
|
+
this.said.set(this.t().restored);
|
|
857
|
+
this.undo.emit(was);
|
|
858
|
+
this.focus('.send');
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
private take() {
|
|
862
|
+
return { to: this.to(), tone: this.tone(), body: this.body(), attachment: this.attachment() };
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
private receipt(s: EmailDraftState) {
|
|
866
|
+
const t = this.t();
|
|
867
|
+
const f = this.attachment();
|
|
868
|
+
return s === 'sent' ? [t.sentTo, this.recipient()?.name, f ? `${t.with} ${f}` : ''].filter(Boolean).join(' ') : t.discarded;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
private focus(sel: string) {
|
|
872
|
+
afterNextRender(
|
|
873
|
+
() => {
|
|
874
|
+
const all = [...this.host.querySelectorAll<HTMLElement>(sel)];
|
|
875
|
+
(all.find((el) => el.getClientRects().length) ?? all[0])?.focus();
|
|
876
|
+
},
|
|
877
|
+
{ injector: this.injector },
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
private glide() {
|
|
882
|
+
const box = this.foldEl().nativeElement;
|
|
883
|
+
const inner = box.firstElementChild as HTMLElement;
|
|
884
|
+
const view = this.doc.defaultView;
|
|
885
|
+
if (!view?.ResizeObserver || !box.animate) return;
|
|
886
|
+
let h = inner.offsetHeight;
|
|
887
|
+
let w = inner.offsetWidth;
|
|
888
|
+
let run: Animation | null = null;
|
|
889
|
+
const ro = new view.ResizeObserver(() => {
|
|
890
|
+
const next = inner.offsetHeight;
|
|
891
|
+
const from = run ? parseFloat(view.getComputedStyle(box).height) || box.offsetHeight : h;
|
|
892
|
+
const resized = inner.offsetWidth !== w;
|
|
893
|
+
h = next;
|
|
894
|
+
w = inner.offsetWidth;
|
|
895
|
+
run?.cancel();
|
|
896
|
+
run = null;
|
|
897
|
+
box.style.overflow = '';
|
|
898
|
+
const style = view.getComputedStyle(box);
|
|
899
|
+
const scale = parseFloat(style.getPropertyValue('--ui-motion-scale'));
|
|
900
|
+
if (resized || from === next || scale === 0 || view.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
901
|
+
box.style.overflow = 'clip';
|
|
902
|
+
const a = box.animate([{ height: `${from}px` }, { height: `${next}px` }], {
|
|
903
|
+
duration: 360 * (scale || 1),
|
|
904
|
+
easing: style.getPropertyValue('--ui-ease-out').trim() || 'ease-out',
|
|
905
|
+
});
|
|
906
|
+
run = a;
|
|
907
|
+
a.onfinish = () => {
|
|
908
|
+
if (run !== a) return;
|
|
909
|
+
run = null;
|
|
910
|
+
box.style.overflow = '';
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
ro.observe(inner);
|
|
914
|
+
this.destroyRef.onDestroy(() => ro.disconnect());
|
|
915
|
+
}
|
|
916
|
+
}
|