@h-k-dev/angular-email-editor 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.
Files changed (51) hide show
  1. package/README.md +127 -2
  2. package/fesm2022/h-k-dev-angular-email-editor-actions.mjs +179 -0
  3. package/fesm2022/h-k-dev-angular-email-editor-actions.mjs.map +1 -0
  4. package/fesm2022/h-k-dev-angular-email-editor-address-chip.mjs +383 -0
  5. package/fesm2022/h-k-dev-angular-email-editor-address-chip.mjs.map +1 -0
  6. package/fesm2022/h-k-dev-angular-email-editor-address-input.mjs +1106 -0
  7. package/fesm2022/h-k-dev-angular-email-editor-address-input.mjs.map +1 -0
  8. package/fesm2022/h-k-dev-angular-email-editor-address.mjs +489 -0
  9. package/fesm2022/h-k-dev-angular-email-editor-address.mjs.map +1 -0
  10. package/fesm2022/h-k-dev-angular-email-editor-anchor.mjs +64 -0
  11. package/fesm2022/h-k-dev-angular-email-editor-anchor.mjs.map +1 -0
  12. package/fesm2022/h-k-dev-angular-email-editor-attachment-chip.mjs +387 -0
  13. package/fesm2022/h-k-dev-angular-email-editor-attachment-chip.mjs.map +1 -0
  14. package/fesm2022/h-k-dev-angular-email-editor-attachment-chips.mjs +80 -0
  15. package/fesm2022/h-k-dev-angular-email-editor-attachment-chips.mjs.map +1 -0
  16. package/fesm2022/h-k-dev-angular-email-editor-chat-input.mjs +346 -0
  17. package/fesm2022/h-k-dev-angular-email-editor-chat-input.mjs.map +1 -0
  18. package/fesm2022/h-k-dev-angular-email-editor-focus.mjs +78 -0
  19. package/fesm2022/h-k-dev-angular-email-editor-focus.mjs.map +1 -0
  20. package/fesm2022/h-k-dev-angular-email-editor-image.mjs +132 -0
  21. package/fesm2022/h-k-dev-angular-email-editor-image.mjs.map +1 -0
  22. package/fesm2022/h-k-dev-angular-email-editor-material.mjs +124 -0
  23. package/fesm2022/h-k-dev-angular-email-editor-material.mjs.map +1 -0
  24. package/fesm2022/h-k-dev-angular-email-editor-metrics.mjs +243 -0
  25. package/fesm2022/h-k-dev-angular-email-editor-metrics.mjs.map +1 -0
  26. package/fesm2022/h-k-dev-angular-email-editor-palette.mjs +87 -0
  27. package/fesm2022/h-k-dev-angular-email-editor-palette.mjs.map +1 -0
  28. package/fesm2022/h-k-dev-angular-email-editor-proposal.mjs +307 -0
  29. package/fesm2022/h-k-dev-angular-email-editor-proposal.mjs.map +1 -0
  30. package/fesm2022/h-k-dev-angular-email-editor-suggestion-menu.mjs +392 -0
  31. package/fesm2022/h-k-dev-angular-email-editor-suggestion-menu.mjs.map +1 -0
  32. package/fesm2022/h-k-dev-angular-email-editor.mjs +18820 -0
  33. package/fesm2022/h-k-dev-angular-email-editor.mjs.map +1 -0
  34. package/package.json +133 -3
  35. package/styles/_scroll.scss +101 -0
  36. package/types/h-k-dev-angular-email-editor-actions.d.ts +147 -0
  37. package/types/h-k-dev-angular-email-editor-address-chip.d.ts +234 -0
  38. package/types/h-k-dev-angular-email-editor-address-input.d.ts +449 -0
  39. package/types/h-k-dev-angular-email-editor-address.d.ts +125 -0
  40. package/types/h-k-dev-angular-email-editor-anchor.d.ts +44 -0
  41. package/types/h-k-dev-angular-email-editor-attachment-chip.d.ts +271 -0
  42. package/types/h-k-dev-angular-email-editor-attachment-chips.d.ts +48 -0
  43. package/types/h-k-dev-angular-email-editor-chat-input.d.ts +101 -0
  44. package/types/h-k-dev-angular-email-editor-focus.d.ts +46 -0
  45. package/types/h-k-dev-angular-email-editor-image.d.ts +66 -0
  46. package/types/h-k-dev-angular-email-editor-material.d.ts +65 -0
  47. package/types/h-k-dev-angular-email-editor-metrics.d.ts +110 -0
  48. package/types/h-k-dev-angular-email-editor-palette.d.ts +51 -0
  49. package/types/h-k-dev-angular-email-editor-proposal.d.ts +170 -0
  50. package/types/h-k-dev-angular-email-editor-suggestion-menu.d.ts +177 -0
  51. package/types/h-k-dev-angular-email-editor.d.ts +3959 -0
@@ -0,0 +1,1106 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Directive, inject, TemplateRef, model, input, signal, computed, numberAttribute, booleanAttribute, output, contentChild, viewChild, ElementRef, Injector, viewChildren, afterNextRender, Component } from '@angular/core';
3
+ import { ADDRESS_RULES, isMailbox, isPending, addressKey, separatesAt, defaultAddressRules } from '@h-k-dev/angular-email-editor/address';
4
+ import { AddressChipRemove, AddressChip, ADDRESS_DRAG_TYPE } from '@h-k-dev/angular-email-editor/address-chip';
5
+ import { NgTemplateOutlet } from '@angular/common';
6
+ import { validate } from '@angular/forms/signals';
7
+
8
+ /**
9
+ * Scopes chip drag and drop to the address inputs inside it: they trade
10
+ * chips with each other and refuse anyone else's — a writer's From, To, Cc
11
+ * and Bcc, and not the rows of another writer on the same page. Put it on
12
+ * whatever holds the rows:
13
+ *
14
+ * <form emailAddressDragGroup [formRoot]="envelope">
15
+ * <div email-address-input [formField]="envelope.from" limit="1"></div>
16
+ * <div email-address-input [formField]="envelope.to"></div>
17
+ * …
18
+ * </form>
19
+ *
20
+ * The nearest group around an input is its group. Inputs in no group make
21
+ * up one group of their own, so a page with a single writer needs none.
22
+ * Behaviour only: it renders nothing and sets no attribute.
23
+ *
24
+ * A chip lands in an address input or nowhere — it carries no plain text,
25
+ * so a subject line, an editor or any other field leaves it alone.
26
+ */
27
+ class AddressDragGroup {
28
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AddressDragGroup, deps: [], target: i0.ɵɵFactoryTarget.Directive });
29
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.6", type: AddressDragGroup, isStandalone: true, selector: "[emailAddressDragGroup]", exportAs: ["emailAddressDragGroup"], ngImport: i0 });
30
+ }
31
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AddressDragGroup, decorators: [{
32
+ type: Directive,
33
+ args: [{ selector: '[emailAddressDragGroup]', exportAs: 'emailAddressDragGroup' }]
34
+ }] });
35
+
36
+ /**
37
+ * The address input's label slot — opt in. By default the control owns no
38
+ * label: the template that holds the form draws the row and the label beside
39
+ * it, as it does for a plain `<input>`. A host that wants the label *inside*
40
+ * the control — at the start of the chips, the chips wrapping under it, the
41
+ * whole control one box (a Material form field around it, as iusta core
42
+ * writes its rows) — hands the control a template:
43
+ *
44
+ * <div email-address-input [formField]="envelope.to">
45
+ * <ng-template emailAddressLabel>To</ng-template>
46
+ * </div>
47
+ *
48
+ * The control renders it first in its row, in a box of its own
49
+ * (`[data-slot=label]`), and names its text input by it — unless the host
50
+ * named the input itself (`aria-labelledby` / `aria-label`).
51
+ */
52
+ class AddressInputLabel {
53
+ template = inject(TemplateRef);
54
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AddressInputLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
55
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.6", type: AddressInputLabel, isStandalone: true, selector: "ng-template[emailAddressLabel]", ngImport: i0 });
56
+ }
57
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AddressInputLabel, decorators: [{
58
+ type: Directive,
59
+ args: [{ selector: 'ng-template[emailAddressLabel]' }]
60
+ }] });
61
+
62
+ let nextId = 0;
63
+ /** The chip drag in flight from an address input on this page: where it
64
+ came from, and whether an address input took it as a move. The drag
65
+ data can't be read until the drop, and `dropEffect` at the drag's end is
66
+ not to be trusted (WebKit reports `all`): this is how a target refuses
67
+ a duplicate before the drop and how the source learns to let go. */
68
+ let drag = null;
69
+ /** The entry a chip on this page last put on the clipboard — by a hold, by
70
+ Ctrl+C or by Ctrl+X. A hold writes plain text only (the async clipboard
71
+ takes no type of ours), so a paste of exactly this text is known to be a
72
+ chip's, and comes back as one. */
73
+ let clipboardEntry = null;
74
+ /**
75
+ * An address field the way Gmail's works: committed addresses as chips,
76
+ * free typing after them. Enter, comma, semicolon or a paste commits what
77
+ * was typed — a comma or semicolon inside a quoted name or angle brackets is
78
+ * just typed, and no key commits while an IME is composing; Backspace on the empty input takes the chip before the caret
79
+ * back for editing; `limit` caps the count (From takes one) and hides the
80
+ * input once reached.
81
+ *
82
+ * **Only an address becomes a chip while typing.** Enter, comma, semicolon,
83
+ * Tab and a paste commit the addresses in what was typed and leave the rest —
84
+ * what is not an address yet — in the input, flagged, for the user to
85
+ * finish. Leaving the field commits everything, so the form sees the typo
86
+ * and flags it; and focus coming back hands the malformed entries at the
87
+ * end of the list straight back to the input, as plain typing again.
88
+ *
89
+ * **The input is always at the end, and editing happens there.** A chip
90
+ * taken back for editing — a double click, Enter on a picked chip,
91
+ * Backspace, `edit()` — leaves its place: its address goes into the input,
92
+ * after the last chip, exactly like a typo the field handed back — and what
93
+ * is committed from it joins the end of the list. There is one place where
94
+ * text is typed, and it never moves.
95
+ *
96
+ * **One pending edit at a time.** There is only ever one thing being fixed,
97
+ * and it is what the caret is on. Starting another edit — `edit()`, Enter
98
+ * on a picked chip, Backspace taking the chip before the caret back — ends
99
+ * the one pending: a typo left in the input and any chip that is not an
100
+ * address go.
101
+ *
102
+ * **Chips while focused, a line of text otherwise.** With focus elsewhere
103
+ * the addresses read as a comma-separated line — no surface, no buttons;
104
+ * focus in the input turns them into chips.
105
+ *
106
+ * **The arrow keys rove the chips; the caret stays in the input.** With
107
+ * the caret at the start of the typing, ← puts a highlight on the last chip
108
+ * and walks back along the list; → walks forward, and past the last chip
109
+ * returns to the caret. Enter or F2 — or a double click on
110
+ * any chip — edits it, Alt+← and Alt+→ move it a place along the list,
111
+ * Ctrl+C (Cmd+C) copies it, as a hold does, and Ctrl+X cuts it — unless
112
+ * text is selected in the input, which copies as ever —
113
+ * Backspace or Delete removes it, Escape drops the highlight, and so does
114
+ * typing. A click on a chip highlights it. Reaching a chip either way is
115
+ * being done with the typing: an address in the input becomes a chip first,
116
+ * as Enter would make it. The highlight is
117
+ * `aria-activedescendant` on the input and `aria-current` on the chip, and the
118
+ * chips' remove buttons stay out of the tab order — Tab lands on the input —
119
+ * except when the field is full and has no input to land on.
120
+ *
121
+ * A display name is kept — `Ada Lovelace <ada@example.com>` is one chip
122
+ * that shows "Ada Lovelace" — and the value stays `string[]` in header
123
+ * form, ready for a `To:` line. Typed bare, `Ada Lovelace ada@example.com`
124
+ * becomes that same chip. An address is in the list once: another entry
125
+ * with the same address — in any case, under any name — is dropped.
126
+ *
127
+ * **The control, not the row.** By default it owns no label and draws no row: the
128
+ * template that holds the form puts it in a row of its own making, beside a
129
+ * label of its own making, exactly as it does for a plain `<input>` — and
130
+ * names the control through `aria-labelledby` (the label's id) or
131
+ * `aria-label`, which land on the text input inside, the element assistive
132
+ * tech reaches. Clicking anywhere on the control puts the caret in; a row
133
+ * that wants its label to do the same calls `focus()`.
134
+ *
135
+ * **A signal-forms control, optionally.** It implements `FormValueControl`
136
+ * for `string[]`: bind a field with `[formField]="envelope.to"` and the
137
+ * directive drives `value` both ways, pushes `invalid`, `touched`,
138
+ * `disabled`, `readonly`, `required` and `name` in, and hears `touch` when
139
+ * focus leaves the input. Without a form, `[(value)]` alone is the whole
140
+ * contract; the state inputs are optional and the chips still flag a
141
+ * malformed address on their own. The rules that go with it — `addressList`
142
+ * — live beside it, because the built-in `required` and `email` know
143
+ * nothing of an array of mailboxes.
144
+ *
145
+ * **No messages of its own.** The control reflects the field's state —
146
+ * invalid *and* touched, so nothing shouts before the user has left it —
147
+ * and a malformed address is flagged on its chip; wording what is wrong is
148
+ * the job of the component that owns the form, which has the errors.
149
+ *
150
+ * **Parts are `data-slot`s** — `chips`, `entry`, `input` — plus the chips'
151
+ * own; that is how the control is styled from outside: theme it through
152
+ * the `--email-*` tokens, and reach a part for a structural override with
153
+ * two attributes.
154
+ *
155
+ * **The selection and its commands are public.** A host's own controls —
156
+ * a bar over the writer, the way a phone's action bar sits over the app
157
+ * bar — work the picked chip through `current()` and `select()` for the
158
+ * state and `edit()`, `remove()` and `copy()` for the commands, each on the
159
+ * current chip unless given another. Such a bar's buttons must decline
160
+ * their mousedown (`(mousedown)="$event.preventDefault()"`): focus stays in
161
+ * the input, and the selection with it — focus leaving the control clears
162
+ * the selection.
163
+ *
164
+ * **Chips move between inputs by drag and drop.** A chip of an editable
165
+ * input can be dragged to another — To into Cc, as Gmail and Outlook do —
166
+ * and leaves its own list when the other takes it. The other commits it
167
+ * as it was, flagged or pending alike. A chip whose address the other
168
+ * already holds is absorbed, as Gmail does: it leaves its list and the
169
+ * other keeps its own entry. A full list (From holds one) refuses the
170
+ * drop, and the chip stays. Dropped in its own list, a chip is reordered:
171
+ * it moves to the line; the line is not drawn where the chip already is. Alt (Option), or Ctrl, makes
172
+ * it a copy — onto a duplicate, a copy is nothing, so refused. Nothing
173
+ * moves while a drag is over a target: a thin line between its chips
174
+ * (`drop-marker`) shows where the chip will land, before or after the chip
175
+ * under the pointer, and the drop puts it there; the host carries
176
+ * `data-dropping` meanwhile. Only chips are places: a draft — typed in the
177
+ * input, or left at the end of the list when the row lost focus — is not,
178
+ * and a drop lands before it.
179
+ * A drop counts as working both fields: each is touched.
180
+ * A chip lands in an address input or nowhere: it carries no plain text,
181
+ * so a subject line or an editor can't take it. `emailAddressDragGroup` on
182
+ * the element around a writer's rows keeps its chips among them. Plain text
183
+ * dropped from elsewhere is a paste — the addresses become chips, the rest
184
+ * is left typed.
185
+ * `moveTo()` is the same move for the keyboard — a host's "Move to Cc" —
186
+ * and the moved chip says so (`movedLabel`). A touch is never a drag: on
187
+ * a phone the press is the chip's hold-to-copy. `allowDrag` turns it off;
188
+ * a disabled or read-only input is neither source nor target.
189
+ *
190
+ * **The chips' remove control is a template slot.** An
191
+ * `ng-template[emailAddressChipRemove]` in the input's content is handed to
192
+ * every chip it renders, in place of the default × button.
193
+ *
194
+ * **State on the host.** `aria-disabled` while disabled; `data-invalid`
195
+ * while invalid and touched; `data-full` once `limit` is reached;
196
+ * `data-focused` while focus is anywhere in the control. The text input
197
+ * carries `data-refused` while it holds text a commit left behind.
198
+ *
199
+ * No Material, no icon font, no headless library. It holds the list it
200
+ * shows and nothing else: contacts, lookups and sending are the host's.
201
+ */
202
+ class AddressInput {
203
+ /** The committed addresses, in header form. Two-way; the form's value. */
204
+ value = model([], /* @ts-ignore */
205
+ ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
206
+ placeholder = input('', /* @ts-ignore */
207
+ ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
208
+ /** The id of the row's label, passed through to the text input — the
209
+ host's label, wherever the host put it. */
210
+ ariaLabelledby = input(null, { ...(ngDevMode ? { debugName: "ariaLabelledby" } : /* istanbul ignore next */ {}), alias: 'aria-labelledby' });
211
+ /** A name for the text input when there is no visible label. */
212
+ ariaLabel = input(null, { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: 'aria-label' });
213
+ /** The ids of whatever describes the field — a hint, an error line —
214
+ passed through to the text input, where assistive tech reads them. */
215
+ ariaDescribedby = input(null, { ...(ngDevMode ? { debugName: "ariaDescribedby" } : /* istanbul ignore next */ {}), alias: 'aria-describedby' });
216
+ #frameIds = signal([], /* @ts-ignore */
217
+ ...(ngDevMode ? [{ debugName: "#frameIds" }] : /* istanbul ignore next */ []));
218
+ /** What the text input's `aria-describedby` says: the host's own ids and a
219
+ frame's, each once. */
220
+ describedBy = computed(() => {
221
+ const ids = new Set([...(this.ariaDescribedby()?.split(/\s+/) ?? []), ...this.#frameIds()]);
222
+ ids.delete('');
223
+ return ids.size ? [...ids].join(' ') : null;
224
+ }, /* @ts-ignore */
225
+ ...(ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []));
226
+ /** Adds the ids of a frame's own lines — a form field's hint and error —
227
+ to what describes the text input, beside the host's `aria-describedby`;
228
+ each call replaces the frame's previous ids. */
229
+ describe(ids) {
230
+ this.#frameIds.set(ids);
231
+ }
232
+ /** Most addresses the field takes; the input hides once reached. Named
233
+ `limit`, not `max`: the form contract keeps that name for the `max` rule. */
234
+ limit = input(Infinity, { ...(ngDevMode ? { debugName: "limit" } : /* istanbul ignore next */ {}), transform: numberAttribute });
235
+ /** Prefix for each chip's remove button — "Remove ada@example.com". */
236
+ removeLabel = input('Remove', /* @ts-ignore */
237
+ ...(ngDevMode ? [{ debugName: "removeLabel" }] : /* istanbul ignore next */ []));
238
+ /** What a malformed address is flagged as. */
239
+ invalidLabel = input('not an email address', /* @ts-ignore */
240
+ ...(ngDevMode ? [{ debugName: "invalidLabel" }] : /* istanbul ignore next */ []));
241
+ /** The chips' note on a placeholder a template fills in later. */
242
+ pendingLabel = input('filled in when sent', /* @ts-ignore */
243
+ ...(ngDevMode ? [{ debugName: "pendingLabel" }] : /* istanbul ignore next */ []));
244
+ /** What a chip moved into this input says, before its address — a host
245
+ with labelled rows says where: "Moved to Cc:". */
246
+ movedLabel = input('Moved', /* @ts-ignore */
247
+ ...(ngDevMode ? [{ debugName: "movedLabel" }] : /* istanbul ignore next */ []));
248
+ /** Chips may be dragged out of this input and dropped into it. Set false
249
+ for a row that only shows; a disabled or read-only input never takes
250
+ part either way. */
251
+ allowDrag = input(true, { ...(ngDevMode ? { debugName: "allowDrag" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
252
+ // ── the form contract: pushed in by the field directive ───────────────
253
+ /** The input's `name` attribute; the directive derives one from the path. */
254
+ name = input('', /* @ts-ignore */
255
+ ...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
256
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
257
+ readonly = input(false, { ...(ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
258
+ required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
259
+ invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
260
+ touched = input(false, { ...(ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
261
+ /** Focus left the input. The directive marks the field touched on it. */
262
+ touch = output();
263
+ /** The text input's id, for a host label's `for`. */
264
+ id = `email-address-input-${nextId++}`;
265
+ /** The host's label template, if it opted into one — rendered first in
266
+ the row; the text input is named by it. */
267
+ labelSlot = contentChild(AddressInputLabel, /* @ts-ignore */
268
+ ...(ngDevMode ? [{ debugName: "labelSlot" }] : /* istanbul ignore next */ []));
269
+ /** The label box's id, for the text input's `aria-labelledby`. */
270
+ labelId = `${this.id}-label`;
271
+ /** What names the text input: the host's own `aria-labelledby`; else the
272
+ label slot — unless the host gave an `aria-label` instead. */
273
+ labelledBy = computed(() => this.ariaLabelledby() ?? (this.labelSlot() && !this.ariaLabel() ? this.labelId : null), /* @ts-ignore */
274
+ ...(ngDevMode ? [{ debugName: "labelledBy" }] : /* istanbul ignore next */ []));
275
+ /** The host's remove template, passed on to every chip. */
276
+ removeSlot = contentChild(AddressChipRemove, /* @ts-ignore */
277
+ ...(ngDevMode ? [{ debugName: "removeSlot" }] : /* istanbul ignore next */ []));
278
+ field = viewChild.required('field', /* @ts-ignore */
279
+ ...(ngDevMode ? [{ debugName: "field" }] : /* istanbul ignore next */ []));
280
+ /** The list of chips, where a press on a draggable chip parks focus. */
281
+ chipList = viewChild.required('chipList', /* @ts-ignore */
282
+ ...(ngDevMode ? [{ debugName: "chipList" }] : /* istanbul ignore next */ []));
283
+ #host = inject(ElementRef);
284
+ #injector = inject(Injector);
285
+ /** The address rule in force — ours, or the host's (`provideAddressRules`):
286
+ how typing splits, what is an address, what is one recipient. */
287
+ #rules = inject(ADDRESS_RULES);
288
+ /** What becomes a chip: a well-formed mailbox, or a placeholder a
289
+ template fills in later. Everything else is a typo to hand back. */
290
+ #accepts = (raw) => isMailbox(raw, this.#rules) || isPending(raw, this.#rules);
291
+ #key = (raw) => addressKey(raw, this.#rules);
292
+ /** The list has this address already — in any case, under any name. */
293
+ #holds = (raw) => this.#keys().has(this.#key(raw));
294
+ /** The list's addresses by key, parsed once a change — not on every
295
+ `dragover`. */
296
+ #keys = computed(() => new Set(this.value().map(this.#key)), /* @ts-ignore */
297
+ ...(ngDevMode ? [{ debugName: "#keys" }] : /* istanbul ignore next */ []));
298
+ /** The chips this input trades with: those of the nearest
299
+ `emailAddressDragGroup`, or of every input in none. */
300
+ #group = inject(AddressDragGroup, { optional: true });
301
+ #focused = signal(false, /* @ts-ignore */
302
+ ...(ngDevMode ? [{ debugName: "#focused" }] : /* istanbul ignore next */ []));
303
+ /** Focus is somewhere in the control — the input or a chip's remove
304
+ button. The chips are chips only then. Read-only; for a host's own
305
+ frame (a form field whose label floats on it). */
306
+ focused = this.#focused.asReadonly();
307
+ #text = signal('', /* @ts-ignore */
308
+ ...(ngDevMode ? [{ debugName: "#text" }] : /* istanbul ignore next */ []));
309
+ /** What is typed in the input and not committed yet — for a host's own
310
+ frame, where a field with typing in it is not empty. */
311
+ text = this.#text.asReadonly();
312
+ /** The input holds text a commit left behind: not an address yet. */
313
+ refused = signal(false, /* @ts-ignore */
314
+ ...(ngDevMode ? [{ debugName: "refused" }] : /* istanbul ignore next */ []));
315
+ /** The chip the arrow keys or a click picked, by index in the value — the
316
+ one Enter, Backspace and Delete act on while the caret stays in the
317
+ input. */
318
+ active = signal(null, /* @ts-ignore */
319
+ ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
320
+ /** The picked chip's address — the one the arrow keys or a click reached
321
+ and the commands act on — or null. Public, for a host's own controls. */
322
+ current = computed(() => {
323
+ const index = this.active();
324
+ return index === null ? null : (this.value()[index] ?? null);
325
+ }, /* @ts-ignore */
326
+ ...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
327
+ /** Picks a chip by address, or none. */
328
+ select(address) {
329
+ const index = address === null ? -1 : this.value().indexOf(address);
330
+ this.active.set(index < 0 ? null : index);
331
+ }
332
+ /** The chips as rendered, for the commands that are the chip's own. */
333
+ chips = viewChildren(AddressChip, /* @ts-ignore */
334
+ ...(ngDevMode ? [{ debugName: "chips" }] : /* istanbul ignore next */ []));
335
+ /** The active chip's id, for the input's `aria-activedescendant`. */
336
+ activeId = computed(() => {
337
+ const index = this.active();
338
+ return index !== null && index < this.value().length ? this.chipId(index) : null;
339
+ }, /* @ts-ignore */
340
+ ...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
341
+ chipId(index) {
342
+ return `${this.id}-chip-${index}`;
343
+ }
344
+ /** The cap is reached: a further address is refused. */
345
+ full = computed(() => this.value().length >= this.limit(), /* @ts-ignore */
346
+ ...(ngDevMode ? [{ debugName: "full" }] : /* istanbul ignore next */ []));
347
+ /** The malformed addresses at the end of the list — what focus hands back
348
+ to the input. */
349
+ #trailingMalformed = computed(() => {
350
+ const value = this.value();
351
+ let start = value.length;
352
+ while (start > 0 && !this.#accepts(value[start - 1]))
353
+ start--;
354
+ return value.slice(start);
355
+ }, /* @ts-ignore */
356
+ ...(ngDevMode ? [{ debugName: "#trailingMalformed" }] : /* istanbul ignore next */ []));
357
+ /** Where the draft starts in the list: the trailing malformed entries are
358
+ the typing the row was left with — what focus hands back to the input
359
+ — and no chip is placed among or after them. A drop, or `moveTo()`,
360
+ lands before. */
361
+ #draftStart = computed(() => this.value().length - this.#trailingMalformed().length, /* @ts-ignore */
362
+ ...(ngDevMode ? [{ debugName: "#draftStart" }] : /* istanbul ignore next */ []));
363
+ /** Full, and nothing in it to fix: the input hides — the chips say
364
+ everything. A full list ending in a typo keeps it, so focus can hand
365
+ the typo back. */
366
+ closed = computed(() => this.full() && !this.#trailingMalformed().length, /* @ts-ignore */
367
+ ...(ngDevMode ? [{ debugName: "closed" }] : /* istanbul ignore next */ []));
368
+ /** Nothing may change: disabled or read-only. Chips lose their remove
369
+ button, the input is out of play. */
370
+ locked = computed(() => this.disabled() || this.readonly(), /* @ts-ignore */
371
+ ...(ngDevMode ? [{ debugName: "locked" }] : /* istanbul ignore next */ []));
372
+ /** Chips can be dragged out of the list, and dropped into it. */
373
+ canDrag = computed(() => this.allowDrag() && !this.locked(), /* @ts-ignore */
374
+ ...(ngDevMode ? [{ debugName: "canDrag" }] : /* istanbul ignore next */ []));
375
+ /** Where a drag over the input would land: the index in the list, and
376
+ the line drawn there — in the chip list's own coordinates. Null while
377
+ no drag the input would take is over it. Drawn on top, out of the
378
+ flow, so nothing moves under the pointer. */
379
+ dropMarker = signal(null, { ...(ngDevMode ? { debugName: "dropMarker" } : /* istanbul ignore next */ {}),
380
+ // A drag sends `dragover` every few dozen milliseconds, moving or not:
381
+ // the same place again is no change, and renders nothing.
382
+ equal: (a, b) => a === b ||
383
+ (!!a && !!b && a.index === b.index && a.x === b.x && a.y === b.y && a.height === b.height) });
384
+ /** A drag the input would take is over it. */
385
+ dropping = computed(() => this.dropMarker() !== null, /* @ts-ignore */
386
+ ...(ngDevMode ? [{ debugName: "dropping" }] : /* istanbul ignore next */ []));
387
+ /** The press under way is a mouse's (or a pen's) on a draggable chip:
388
+ its default has to stay, or the browser never starts the drag. */
389
+ #dragPress = false;
390
+ /** Invalid *and* touched — the moment the state becomes the user's business. */
391
+ flagged = computed(() => this.invalid() && this.touched(), /* @ts-ignore */
392
+ ...(ngDevMode ? [{ debugName: "flagged" }] : /* istanbul ignore next */ []));
393
+ /** Splits a run into addresses and adds the new ones to the end of the
394
+ list, up to `limit`. Duplicates — by address, case-insensitively —
395
+ are dropped; a malformed one is kept and
396
+ flagged — this is the host's way in, and the host decides what it
397
+ holds. */
398
+ commit(raw) {
399
+ this.#insert(this.#rules.split(raw));
400
+ }
401
+ /** Drops one address — the picked chip's by default. Identity by string:
402
+ the list never holds the same header form twice, so this takes exactly
403
+ the chip that asked. */
404
+ remove(address = this.current()) {
405
+ if (this.locked() || address === null)
406
+ return;
407
+ this.active.set(null);
408
+ const index = this.value().indexOf(address);
409
+ if (index < 0)
410
+ return;
411
+ this.value.update((current) => current.filter((a) => a !== address));
412
+ }
413
+ /** A chip's remove control was used: the address goes, and the caret
414
+ comes back to the input — the focused button went with its chip, and
415
+ focus left on nothing would strand a keyboard user and read to a host
416
+ as the field being left. */
417
+ removeChip(address) {
418
+ this.remove(address);
419
+ this.focus();
420
+ }
421
+ /** Takes a chip — the picked one by default — back for editing: it
422
+ leaves the list and the input, at the end, holds its address, caret at
423
+ the end. The edit pending until now ends first. A locked list edits
424
+ nothing. */
425
+ edit(address = this.current(), input = this.field().nativeElement) {
426
+ if (this.locked() || address === null)
427
+ return;
428
+ this.active.set(null);
429
+ this.#endPending(input, address);
430
+ if (!this.value().includes(address))
431
+ return;
432
+ this.remove(address);
433
+ this.#write(input, address);
434
+ input.focus();
435
+ input.setSelectionRange(input.value.length, input.value.length);
436
+ }
437
+ /** Ends the pending edit so another can start: the addresses typed so far
438
+ become chips, the rest of the typing goes, and so
439
+ does every chip that is not an address — but `keep`, the one about to
440
+ be edited. */
441
+ #endPending(input, keep) {
442
+ this.#insert(this.#rules.split(input.value).filter((token) => this.#accepts(token)));
443
+ this.#write(input, '');
444
+ this.refused.set(false);
445
+ const value = this.value();
446
+ const kept = value.filter((address) => this.#accepts(address) || address === keep);
447
+ if (kept.length !== value.length)
448
+ this.value.set(kept);
449
+ }
450
+ /** Puts the caret in the input — the whole control is the field, and a
451
+ host's label row may forward its own clicks here. A full field has no
452
+ input to put it in: focus goes to the last chip's remove control. */
453
+ focus() {
454
+ if (this.locked())
455
+ return;
456
+ if (!this.closed()) {
457
+ this.field().nativeElement.focus();
458
+ return;
459
+ }
460
+ const controls = this.#host.nativeElement.querySelectorAll('[data-slot=trailing] :is(button, [href], input, [tabindex]:not([tabindex="-1"]))');
461
+ controls[controls.length - 1]?.focus();
462
+ }
463
+ /** A press anywhere on the control is the input's from that moment: it
464
+ takes focus at the press, not at the click after the release — so a
465
+ chip pressed in a line of text turns the line to chips at once, and a
466
+ hold on a chip runs with the document focused, which the clipboard
467
+ insists on. `keepCaret` then declines the press's own default, which
468
+ would move focus off again. */
469
+ onPointerdown(event) {
470
+ const input = this.field().nativeElement;
471
+ const target = event.target;
472
+ this.#dragPress =
473
+ event.pointerType !== 'touch' &&
474
+ this.canDrag() &&
475
+ !!target.closest?.('[email-address-chip]') &&
476
+ !target.closest('[data-slot=trailing]');
477
+ if (target === input || this.locked() || this.closed())
478
+ return;
479
+ input.focus();
480
+ }
481
+ /** A press anywhere on the control but the text input itself — a chip,
482
+ its button, the gap between — leaves the caret where it is. The
483
+ browser would otherwise move focus to the body for the press and back
484
+ on the click, and in that instant the row would drop to text and
485
+ reflow: a flash, and a blur that commits and touches for nothing.
486
+ Except a mouse's press on a draggable chip: no engine starts a drag
487
+ from a press whose default was declined, so it keeps it, and the
488
+ press's focus lands on the chip list instead (`tabindex="-1"`) —
489
+ still inside the control, so nothing commits; the click or the drag's
490
+ end brings the caret back. */
491
+ keepCaret(event) {
492
+ if (event.target === this.field().nativeElement || this.#dragPress)
493
+ return;
494
+ event.preventDefault();
495
+ }
496
+ /** A click on a chip — not on its remove control — picks it, and only
497
+ that: a click on the picked chip picks it again. The caret is in the
498
+ input either way. */
499
+ onChipClick(event, index, input) {
500
+ if (event.target.closest('[data-slot=trailing]') || this.locked())
501
+ return;
502
+ this.#pick(index, input);
503
+ input.focus();
504
+ }
505
+ /** A double click on a chip — not on its remove control — takes it back
506
+ for editing. */
507
+ onChipDblclick(event, address, input) {
508
+ if (event.target.closest('[data-slot=trailing]'))
509
+ return;
510
+ this.edit(address, input);
511
+ }
512
+ /** Copies a chip's address — the picked one by default — to the
513
+ clipboard, as a hold on the chip does; the chip shows and says so.
514
+ Resolves to whether the copy went. */
515
+ async copy(address = this.current()) {
516
+ const chip = this.chips().find((candidate) => candidate.address() === address);
517
+ return chip ? chip.copy() : false;
518
+ }
519
+ /** Moves a chip — the picked one by default — to another address input:
520
+ the keyboard's way to do what a drag does, for a host's own "Move to
521
+ Cc". The target takes it as it is, to the end of its list — before
522
+ a draft the row was left with — and it
523
+ leaves this one; both are touched, and the moved chip says so
524
+ (`movedLabel`). One the target already holds is absorbed: it leaves
525
+ here, and the target keeps its own entry. A full target, or either
526
+ input locked, moves nothing. Returns whether it moved. */
527
+ moveTo(target, address = this.current()) {
528
+ if (address === null || target === this || this.locked() || target.locked())
529
+ return false;
530
+ if (!this.value().includes(address))
531
+ return false;
532
+ if (!target.#holds(address) && !target.#insert([address], target.#draftStart()).length) {
533
+ return false;
534
+ }
535
+ this.remove(address);
536
+ this.touch.emit();
537
+ target.touch.emit();
538
+ target.#announceMoved(address);
539
+ return true;
540
+ }
541
+ /** The chip that arrived by a move — or the entry that absorbed it —
542
+ says so, once it is drawn. */
543
+ #announceMoved(address) {
544
+ const key = this.#key(address);
545
+ afterNextRender(() => this.chips()
546
+ .find((chip) => this.#key(chip.address()) === key)
547
+ ?.announce(`${this.movedLabel()} ${address}`), { injector: this.#injector });
548
+ }
549
+ // ── drag and drop ─────────────────────────────────────────────────────
550
+ /** A chip of this list started a drag: remember it, so a target on the
551
+ page can judge the drop before it happens and tell this list to let
552
+ go after. */
553
+ onChipDragstart(address) {
554
+ drag = this.canDrag() ? { source: this, group: this.#group, address, moved: false } : null;
555
+ }
556
+ /** The drag ended: if an address input took the chip as a move, it
557
+ leaves — through `remove()`, as the × takes it — and the field is
558
+ touched. The press parked focus on the list; the caret comes back. */
559
+ onChipDragend() {
560
+ const ended = drag;
561
+ drag = null;
562
+ if (ended?.source === this && ended.moved) {
563
+ this.remove(ended.address);
564
+ this.touch.emit();
565
+ }
566
+ if (document.activeElement === this.chipList().nativeElement)
567
+ this.focus();
568
+ }
569
+ /** What a drop here would be: `move` or `copy` for a drag the input
570
+ takes, `none` for one it refuses — said, so the text input inside
571
+ can't take the text in its place — and null for a drag that isn't an
572
+ address (files: the page's drop zone's), left to the page. A chip is
573
+ taken only from another input of the same group, while this page's
574
+ drag is in flight — a chip from anywhere else is refused. */
575
+ #dropEffect(event) {
576
+ const types = event.dataTransfer?.types ?? [];
577
+ const chip = types.includes(ADDRESS_DRAG_TYPE);
578
+ if (!chip && !types.includes('text/plain'))
579
+ return null;
580
+ if (!this.canDrag())
581
+ return chip ? 'none' : null;
582
+ if (!chip)
583
+ return this.full() ? 'none' : 'copy';
584
+ const from = drag;
585
+ if (!from || from.group !== this.#group)
586
+ return 'none';
587
+ const copy = event.altKey || event.ctrlKey;
588
+ // Its own list: a move is a reorder; a copy would add nothing.
589
+ if (from.source === this)
590
+ return copy ? 'none' : 'move';
591
+ // Held already: a move is absorbed, even into a full list; a copy is
592
+ // nothing.
593
+ if (this.#holds(from.address))
594
+ return copy ? 'none' : 'move';
595
+ if (this.full())
596
+ return 'none';
597
+ return copy ? 'copy' : 'move';
598
+ }
599
+ onDragover(event) {
600
+ const effect = this.#dropEffect(event);
601
+ if (effect === null)
602
+ return;
603
+ event.preventDefault();
604
+ event.dataTransfer.dropEffect = effect;
605
+ const marker = effect === 'none' ? null : this.#dropAt(event);
606
+ this.dropMarker.set(marker && this.#inPlace(marker.index) ? null : marker);
607
+ }
608
+ /** A drop at this index would leave the dragged chip where it is: right
609
+ before or right after itself, in its own list. No line there. */
610
+ #inPlace(index) {
611
+ if (drag?.source !== this)
612
+ return false;
613
+ const at = this.value().indexOf(drag.address);
614
+ return index === at || index === at + 1;
615
+ }
616
+ /** Moves a chip of the list to stand before the entry at `at` (the end,
617
+ past the last). True when it moved — not when it would stay put. */
618
+ #reorder(address, at) {
619
+ const from = this.value().indexOf(address);
620
+ if (from < 0 || at < 0 || at > this.value().length || at === from || at === from + 1) {
621
+ return false;
622
+ }
623
+ const to = at > from ? at - 1 : at;
624
+ this.value.update((current) => {
625
+ const next = current.filter((held) => held !== address);
626
+ next.splice(to, 0, address);
627
+ return next;
628
+ });
629
+ return true;
630
+ }
631
+ /** Where a drop at the pointer lands, in reading order: before the first
632
+ entry that starts after the pointer — on a later line, or on its line
633
+ past the pointer's side of the entry's middle — else at the end. And
634
+ the line that says so: midway between two entries on one line, or
635
+ just outside the entry at a line's start or end. */
636
+ #dropAt(event) {
637
+ const list = this.chipList().nativeElement;
638
+ const box = list.getBoundingClientRect();
639
+ const rtl = getComputedStyle(list).direction === 'rtl';
640
+ const x = event.clientX ?? 0;
641
+ const y = event.clientY ?? 0;
642
+ const chips = [...list.querySelectorAll(':scope > [email-address-chip]')];
643
+ // Only the chips before the draft are places; the draft is not.
644
+ const rects = chips.slice(0, this.#draftStart()).map((chip) => chip.getBoundingClientRect());
645
+ let index = rects.findIndex((r) => y < r.top || (y <= r.bottom && (rtl ? x > r.left + r.width / 2 : x < r.left + r.width / 2)));
646
+ if (index < 0)
647
+ index = rects.length;
648
+ const start = (r) => (rtl ? r.right : r.left);
649
+ const end = (r) => (rtl ? r.left : r.right);
650
+ // At a line's start or end the line stands a gap off the entry, as Gmail's does.
651
+ const out = rtl ? 4 : -4;
652
+ const at = rects[index];
653
+ const before = rects[index - 1];
654
+ let line;
655
+ if (at && before && Math.abs(before.top - at.top) < 1) {
656
+ line = { x: (end(before) + start(at)) / 2, top: at.top, height: at.height };
657
+ }
658
+ else if (at) {
659
+ line = { x: start(at) + out, top: at.top, height: at.height };
660
+ }
661
+ else if (before) {
662
+ line = { x: end(before) - out, top: before.top, height: before.height };
663
+ }
664
+ else {
665
+ // No chip yet: at the start — of the draft, if the row was left with one.
666
+ const first = (chips[0] ?? list.querySelector('[data-slot=entry]')).getBoundingClientRect();
667
+ line = { x: start(first) + (chips[0] ? out : 0), top: first.top, height: first.height };
668
+ }
669
+ return { index, x: line.x - box.left, y: line.top - box.top, height: line.height };
670
+ }
671
+ /** Leaving for somewhere outside the control: the drag is no longer over
672
+ it. (A leave with nowhere named — some engines — ends it too; the
673
+ next `dragover` inside brings it back.) */
674
+ onDragleave(event) {
675
+ const to = event.relatedTarget;
676
+ if (!to || !this.#host.nativeElement.contains(to))
677
+ this.dropMarker.set(null);
678
+ }
679
+ /** The drop: a chip is committed as it was; plain text from elsewhere is
680
+ a paste — its addresses become chips, the rest joins the typing. What
681
+ was typed stays. A chip the list holds already is absorbed by a move:
682
+ nothing is added, and the source lets it go. Nothing added otherwise
683
+ (the limit) is no drop: the source keeps its chip. */
684
+ onDrop(event) {
685
+ const effect = this.#dropEffect(event);
686
+ this.dropMarker.set(null);
687
+ if (effect === null)
688
+ return;
689
+ event.preventDefault();
690
+ const transfer = event.dataTransfer;
691
+ if (effect === 'none') {
692
+ transfer.dropEffect = 'none';
693
+ return;
694
+ }
695
+ const entry = transfer.getData(ADDRESS_DRAG_TYPE);
696
+ const { index } = this.#dropAt(event);
697
+ let changed;
698
+ if (entry && drag?.source === this) {
699
+ // Its own chip: a reorder. The source is this list; nothing leaves.
700
+ changed = this.#reorder(entry, index);
701
+ if (changed)
702
+ this.active.set(null);
703
+ }
704
+ else if (entry) {
705
+ const absorbed = effect === 'move' && this.#holds(entry);
706
+ changed = absorbed || this.#insert([entry], index).length > 0;
707
+ if (changed && drag?.address === entry) {
708
+ drag.moved = effect === 'move';
709
+ if (drag.moved)
710
+ this.#announceMoved(entry);
711
+ }
712
+ }
713
+ else {
714
+ const tokens = this.#rules.split(transfer.getData('text/plain'));
715
+ changed =
716
+ this.#insert(tokens.filter((token) => this.#accepts(token)), index).length > 0;
717
+ const rest = tokens.filter((token) => !this.#accepts(token));
718
+ if (rest.length) {
719
+ const input = this.field().nativeElement;
720
+ this.#write(input, [input.value, ...rest].filter(Boolean).join(', '));
721
+ this.refused.set(true);
722
+ input.focus();
723
+ changed = true;
724
+ }
725
+ }
726
+ if (!changed) {
727
+ transfer.dropEffect = 'none';
728
+ return;
729
+ }
730
+ this.touch.emit();
731
+ }
732
+ /** Picking a chip is being done with the typing: the addresses in it
733
+ become chips first, as Enter would make them, and what is not an
734
+ address stays behind, flagged. */
735
+ #pick(index, input) {
736
+ const address = this.value()[index];
737
+ this.#settle(input, input.value);
738
+ this.active.set(address === undefined ? null : this.value().indexOf(address));
739
+ }
740
+ onFocusin() {
741
+ this.#focused.set(true);
742
+ }
743
+ onInput(input) {
744
+ this.#text.set(input.value);
745
+ this.refused.set(false);
746
+ this.active.set(null);
747
+ }
748
+ onKeydown(event, input) {
749
+ // An IME's own Enter picks its candidate; nothing here may act on it.
750
+ if (event.isComposing)
751
+ return;
752
+ const active = this.active();
753
+ if (active !== null && this.#onActiveKey(event, active, input))
754
+ return;
755
+ switch (event.key) {
756
+ case 'ArrowLeft': {
757
+ // From the start of the typing, ← reaches the last chip — the
758
+ // typing becoming chips first, when it holds an address.
759
+ if (input.selectionStart !== 0 || input.selectionEnd !== 0 || this.locked())
760
+ return;
761
+ const typed = this.#rules.split(input.value).some((token) => this.#accepts(token));
762
+ if (typed)
763
+ this.#settle(input, input.value);
764
+ const last = this.value().length - 1;
765
+ if (typed || last >= 0)
766
+ event.preventDefault();
767
+ if (last >= 0)
768
+ this.active.set(last);
769
+ return;
770
+ }
771
+ case ',':
772
+ case ';':
773
+ // Inside a quoted name or angle brackets the character is the
774
+ // mailbox's own: `"Lovelace, Ada"`.
775
+ if (!separatesAt(input.value, input.selectionStart ?? input.value.length))
776
+ return;
777
+ event.preventDefault();
778
+ this.#settle(input, input.value);
779
+ return;
780
+ case 'Enter':
781
+ // Swallowed even with nothing typed: Enter in an address row must
782
+ // never submit the form around it. The subject line is where Enter
783
+ // sends.
784
+ event.preventDefault();
785
+ this.#settle(input, input.value);
786
+ return;
787
+ case 'Tab':
788
+ // Tab on an address commits it and keeps the caret here, ready for
789
+ // the next one — the list is not left until there is nothing more
790
+ // to commit. Tab on nothing, on a typo, or backwards leaves the
791
+ // field as ever, and leaving commits and flags what was typed.
792
+ if (event.shiftKey || !this.#rules.split(input.value).some((token) => this.#accepts(token))) {
793
+ return;
794
+ }
795
+ event.preventDefault();
796
+ this.#settle(input, input.value);
797
+ return;
798
+ case 'Backspace': {
799
+ // On nothing typed, the last chip comes back to be edited — the one
800
+ // pending edit.
801
+ if (input.value)
802
+ return;
803
+ const previous = this.value().at(-1);
804
+ if (previous === undefined || this.locked())
805
+ return;
806
+ event.preventDefault();
807
+ this.edit(previous, input);
808
+ return;
809
+ }
810
+ }
811
+ }
812
+ /** The keys that act on the highlighted chip. True when one did. The
813
+ arrows walk the chips: ← stops at the first, → past the last returns
814
+ to the caret. */
815
+ #onActiveKey(event, active, input) {
816
+ const chips = this.value();
817
+ if (event.altKey && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
818
+ // Alt+← / Alt+→ move the chip a place — the drag's reorder, by key.
819
+ // At either end there is nowhere to go, and the key is still the
820
+ // chip's: it never walks the highlight instead.
821
+ if (this.locked())
822
+ return false;
823
+ const address = chips[active];
824
+ if (this.#reorder(address, event.key === 'ArrowLeft' ? active - 1 : active + 2)) {
825
+ this.active.set(this.value().indexOf(address));
826
+ this.touch.emit();
827
+ }
828
+ event.preventDefault();
829
+ return true;
830
+ }
831
+ switch (event.key) {
832
+ case 'ArrowLeft':
833
+ this.active.set(Math.max(0, active - 1));
834
+ break;
835
+ case 'ArrowRight':
836
+ if (active + 1 < chips.length) {
837
+ this.active.set(active + 1);
838
+ }
839
+ else {
840
+ this.active.set(null);
841
+ input.setSelectionRange(0, 0);
842
+ }
843
+ break;
844
+ case 'Escape':
845
+ this.active.set(null);
846
+ break;
847
+ case 'Enter':
848
+ case 'F2':
849
+ this.edit(chips[active], input);
850
+ break;
851
+ case 'Backspace':
852
+ case 'Delete':
853
+ if (this.locked())
854
+ return false;
855
+ this.remove(chips[active]);
856
+ break;
857
+ default:
858
+ return false;
859
+ }
860
+ event.preventDefault();
861
+ return true;
862
+ }
863
+ /** A paste of several addresses: the addresses become chips, the rest
864
+ joins what the input already holds. A single token is left to the
865
+ input, so a name with spaces can still be edited before it commits —
866
+ but a chip's own copy (Ctrl+C, Ctrl+X, a hold) comes back as a chip,
867
+ as it was. With a chip picked, what is pasted goes right after it. */
868
+ onPaste(event, input) {
869
+ if (this.locked())
870
+ return;
871
+ const data = event.clipboardData;
872
+ const text = data?.getData('text') ?? '';
873
+ const chip = [...(data?.types ?? [])].includes(ADDRESS_DRAG_TYPE);
874
+ const entry = (chip && data.getData(ADDRESS_DRAG_TYPE)) || (text === clipboardEntry ? text : '');
875
+ const active = this.active();
876
+ const at = active === null ? this.#draftStart() : active + 1;
877
+ if (entry) {
878
+ event.preventDefault();
879
+ this.#insert([entry], at);
880
+ this.active.set(null);
881
+ return;
882
+ }
883
+ const tokens = this.#rules.split(text);
884
+ if (tokens.length < 2 && active === null)
885
+ return;
886
+ event.preventDefault();
887
+ if (active === null) {
888
+ this.#settle(input, `${input.value}, ${text}`);
889
+ return;
890
+ }
891
+ const addresses = tokens.filter((token) => this.#accepts(token));
892
+ this.#insert(addresses, at);
893
+ const rest = tokens.filter((token) => !this.#accepts(token));
894
+ if (rest.length) {
895
+ this.#write(input, [input.value, ...rest].filter(Boolean).join(', '));
896
+ this.refused.set(true);
897
+ }
898
+ this.active.set(null);
899
+ }
900
+ /** Ctrl+C or Ctrl+X (Cmd on a Mac, or the Edit menu) with a chip picked
901
+ and no text selected: the chip goes on the clipboard — its header
902
+ form, as text and as the library's own type, so a paste into an
903
+ address input brings it back as a chip — and shows and says so, as a
904
+ hold does. A cut then removes it, as the × would. */
905
+ onClipboard(event, input, cut) {
906
+ const address = this.current();
907
+ const data = event.clipboardData;
908
+ if (address === null || !data || input.selectionStart !== input.selectionEnd)
909
+ return;
910
+ if (cut && this.locked())
911
+ return;
912
+ event.preventDefault();
913
+ data.setData('text/plain', address);
914
+ data.setData(ADDRESS_DRAG_TYPE, address);
915
+ clipboardEntry = address;
916
+ if (cut) {
917
+ this.remove(address);
918
+ return;
919
+ }
920
+ this.chips()
921
+ .find((chip) => chip.address() === address)
922
+ ?.showCopied();
923
+ }
924
+ /** A chip's hold copied it: remembered, so a paste of it is a chip. */
925
+ onChipCopied(address) {
926
+ clipboardEntry = address;
927
+ }
928
+ /** Focus arrived in the input: the typos at the end of the list come back
929
+ into it, to be fixed — unless the user is already typing there. They
930
+ come back as plain typing, not flagged: the caret is on them, and the
931
+ next commit judges them again. */
932
+ onFocus(input) {
933
+ const typos = this.#trailingMalformed();
934
+ if (input.value || !typos.length || this.locked())
935
+ return;
936
+ this.value.update((current) => current.slice(0, current.length - typos.length));
937
+ this.#write(input, typos.join(', '));
938
+ input.setSelectionRange(input.value.length, input.value.length);
939
+ this.refused.set(false);
940
+ }
941
+ /** Leaving the field commits everything typed — the addresses, then a
942
+ typo at the end of the list, so the form sees it and the next focus
943
+ hands it back — and is the touch. Moving to a chip's remove button is
944
+ not leaving. */
945
+ onBlur(event, input) {
946
+ if (this.#within(event))
947
+ return;
948
+ this.#leave(input);
949
+ }
950
+ #leave(input) {
951
+ const tokens = this.#rules.split(input.value);
952
+ this.#insert(tokens.filter((token) => this.#accepts(token)));
953
+ this.#insert(tokens.filter((token) => !this.#accepts(token)));
954
+ this.#write(input, '');
955
+ this.refused.set(false);
956
+ this.touch.emit();
957
+ }
958
+ onFocusout(event) {
959
+ if (this.#within(event))
960
+ return;
961
+ // Focus parked on the chip list by a press that came to nothing leaves
962
+ // from there: leaving is leaving, wherever the caret had got to.
963
+ if (event.target === this.chipList().nativeElement)
964
+ this.#leave(this.field().nativeElement);
965
+ this.#focused.set(false);
966
+ this.active.set(null);
967
+ }
968
+ /** Commits the addresses in a run and leaves the rest in the input. */
969
+ #settle(input, raw) {
970
+ const tokens = this.#rules.split(raw);
971
+ this.#insert(tokens.filter((token) => this.#accepts(token)));
972
+ this.#write(input, tokens.filter((token) => !this.#accepts(token)).join(', '));
973
+ this.refused.set(!!input.value);
974
+ }
975
+ /** Adds the new addresses to the list — at the end, or before the entry
976
+ at `at` (a drop) — up to `limit`, each only if its address is not in
977
+ the list yet; the entry already there keeps its name. Returns what
978
+ was added. */
979
+ #insert(incoming, at = Infinity) {
980
+ const added = [];
981
+ if (!incoming.length)
982
+ return added;
983
+ this.value.update((current) => {
984
+ const seen = new Set(current.map(this.#key));
985
+ for (const address of incoming) {
986
+ if (current.length + added.length >= this.limit())
987
+ break;
988
+ if (seen.has(this.#key(address)))
989
+ continue;
990
+ seen.add(this.#key(address));
991
+ added.push(address);
992
+ }
993
+ return [...current.slice(0, at), ...added, ...current.slice(at)];
994
+ });
995
+ return added;
996
+ }
997
+ /** Puts text in the input — the one way it is written, so `text` follows. */
998
+ #write(input, text) {
999
+ input.value = text;
1000
+ this.#text.set(text);
1001
+ }
1002
+ /** Whether focus is moving to somewhere else inside the control. */
1003
+ #within(event) {
1004
+ const destination = event.relatedTarget;
1005
+ return !!destination && this.#host.nativeElement.contains(destination);
1006
+ }
1007
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AddressInput, deps: [], target: i0.ɵɵFactoryTarget.Component });
1008
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.6", type: AddressInput, isStandalone: true, selector: "[email-address-input]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaDescribedby: { classPropertyName: "ariaDescribedby", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, limit: { classPropertyName: "limit", publicName: "limit", isSignal: true, isRequired: false, transformFunction: null }, removeLabel: { classPropertyName: "removeLabel", publicName: "removeLabel", isSignal: true, isRequired: false, transformFunction: null }, invalidLabel: { classPropertyName: "invalidLabel", publicName: "invalidLabel", isSignal: true, isRequired: false, transformFunction: null }, pendingLabel: { classPropertyName: "pendingLabel", publicName: "pendingLabel", isSignal: true, isRequired: false, transformFunction: null }, movedLabel: { classPropertyName: "movedLabel", publicName: "movedLabel", isSignal: true, isRequired: false, transformFunction: null }, allowDrag: { classPropertyName: "allowDrag", publicName: "allowDrag", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", touch: "touch" }, host: { listeners: { "pointerdown": "onPointerdown($event)", "mousedown": "keepCaret($event)", "click": "focus()", "focusin": "onFocusin()", "focusout": "onFocusout($event)", "dragenter": "onDragover($event)", "dragover": "onDragover($event)", "dragleave": "onDragleave($event)", "drop": "onDrop($event)" }, properties: { "attr.aria-disabled": "disabled() || null", "attr.data-invalid": "flagged() || null", "attr.data-full": "full() || null", "attr.data-focused": "focused() || null", "attr.data-dropping": "dropping() || null" } }, queries: [{ propertyName: "labelSlot", first: true, predicate: AddressInputLabel, descendants: true, isSignal: true }, { propertyName: "removeSlot", first: true, predicate: AddressChipRemove, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "field", first: true, predicate: ["field"], descendants: true, isSignal: true }, { propertyName: "chipList", first: true, predicate: ["chipList"], descendants: true, isSignal: true }, { propertyName: "chips", predicate: AddressChip, descendants: true, isSignal: true }], ngImport: i0, template: "<!-- No label here: the row around this control names it, through\n aria-labelledby or aria-label, both passed down to the text input. -->\n<!-- Focusable by script and by a press only (tabindex -1, while chips can\n be dragged): a press on a draggable chip must keep its default for the\n drag to start, and its focus lands here \u2014 inside the control. -->\n<ul #chipList data-slot=\"chips\" role=\"list\" [attr.tabindex]=\"canDrag() ? -1 : null\">\n <!-- The opt-in label (emailAddressLabel): first in the row, so the chips\n wrap under it. Hidden from assistive tech as text \u2014 it names the\n text input instead, through aria-labelledby. -->\n @if (labelSlot(); as slot) {\n <li data-slot=\"label\" aria-hidden=\"true\" [id]=\"labelId\">\n <ng-container [ngTemplateOutlet]=\"slot.template\" />\n </li>\n }\n @for (address of value(); track address) {\n <li\n email-address-chip\n [id]=\"chipId($index)\"\n [address]=\"address\"\n [removable]=\"!locked()\"\n [inline]=\"!focused()\"\n [draggable]=\"canDrag()\"\n [aria-current]=\"active() === $index\"\n [removeTabbable]=\"closed()\"\n [removeLabel]=\"removeLabel()\"\n [removeTemplate]=\"removeSlot()?.template ?? null\"\n [invalidLabel]=\"invalidLabel()\"\n [pendingLabel]=\"pendingLabel()\"\n [aria-disabled]=\"disabled()\"\n (removed)=\"removeChip(address)\"\n (copied)=\"onChipCopied($event)\"\n (click)=\"onChipClick($event, $index, field)\"\n (dblclick)=\"onChipDblclick($event, address, field)\"\n (dragstart)=\"onChipDragstart(address)\"\n (dragend)=\"onChipDragend()\"\n ></li>\n }\n <!-- Where a drag over the control would land: a line between entries,\n drawn on top and out of the flow \u2014 nothing moves under the pointer. -->\n @if (dropMarker(); as marker) {\n <li\n data-slot=\"drop-marker\"\n aria-hidden=\"true\"\n [style.left.px]=\"marker.x\"\n [style.top.px]=\"marker.y\"\n [style.height.px]=\"marker.height\"\n ></li>\n }\n <!-- The entry is a list item too, so the chips and the typing sit in one\n wrapping row \u2014 always after the last chip. Hidden once the field is full (From takes one address)\n with nothing to fix: the chips say everything, and a second address\n would only be refused. -->\n <li data-slot=\"entry\" [hidden]=\"closed()\">\n <input\n #field\n data-slot=\"input\"\n type=\"text\"\n inputmode=\"email\"\n autocomplete=\"off\"\n autocapitalize=\"off\"\n spellcheck=\"false\"\n [id]=\"id\"\n [attr.name]=\"name() || null\"\n [disabled]=\"disabled()\"\n [readOnly]=\"readonly()\"\n [placeholder]=\"value().length ? '' : placeholder()\"\n [attr.aria-labelledby]=\"labelledBy()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"describedBy()\"\n [attr.aria-required]=\"required() || null\"\n [attr.aria-invalid]=\"flagged() || refused() || null\"\n [attr.aria-activedescendant]=\"activeId()\"\n [attr.data-refused]=\"refused() || null\"\n (keydown)=\"onKeydown($event, field)\"\n (paste)=\"onPaste($event, field)\"\n (copy)=\"onClipboard($event, field, false)\"\n (cut)=\"onClipboard($event, field, true)\"\n (input)=\"onInput(field)\"\n (mousedown)=\"active.set(null)\"\n (focus)=\"onFocus(field)\"\n (blur)=\"onBlur($event, field)\"\n />\n </li>\n</ul>\n", styles: [":host{display:flex;min-width:0;color:var(--email-address-input-color, var(--mat-sys-on-surface, light-dark(#1f1f1f, #e3e3e3)));font-family:var(--email-address-input-font-family, var(--mat-sys-body-medium-font, system-ui, sans-serif));font-size:var(--email-address-input-font-size, var(--mat-sys-body-medium-size, .875rem));font-weight:var(--email-address-input-font-weight, var(--mat-sys-body-medium-weight, 400));line-height:var(--email-address-input-line-height, var(--mat-sys-body-medium-line-height, 1.25rem));letter-spacing:var(--email-address-input-letter-spacing, var(--mat-sys-body-medium-tracking, .016rem));cursor:text}:host([aria-disabled=true]){cursor:default;opacity:.6}:host :where([data-slot=chips]){position:relative;flex:1 1 0;display:flex;flex-wrap:wrap;align-items:center;gap:var(--email-address-input-row-gap, 8px) var(--email-address-input-column-gap, 4px);min-width:0;margin:0;padding:0;list-style:none}:host :where([data-slot=chips]):focus{outline:none}:host :where([data-slot=drop-marker]){position:absolute;box-sizing:content-box;margin-top:calc(-1 * var(--email-address-input-drop-overhang, 4px));padding-block:var(--email-address-input-drop-overhang, 4px);width:var(--email-address-input-drop-width, 2px);margin-left:calc(var(--email-address-input-drop-width, 2px) / -2);border-radius:1px;background:var(--email-address-input-drop-color, var(--mat-sys-primary, light-dark(#0b57d0, #a8c7fa)));pointer-events:none}:host :where([data-slot=label]){flex:none;margin-inline-end:var(--email-address-input-label-gap, 4px);color:var(--email-address-input-label-color, var(--mat-sys-on-surface-variant, light-dark(#444746, #c4c7c5)));line-height:var(--email-address-input-label-line-height, 24px);white-space:nowrap}:host(:not([data-focused])) :where([data-slot=chips]){column-gap:var(--email-address-input-inline-gap, .3em)}:host(:not([data-focused])) :where([email-address-chip]:has(+[email-address-chip])):after{content:\",\"}:host :where([data-slot=entry]){flex:1 1 8ch;min-width:8ch;display:flex}:host :where([data-slot=entry][hidden]){display:none}:host(:not([data-focused])) :where([data-slot=entry]){flex-basis:0;min-width:0}:host :where([data-slot=input]){flex:1 1 auto;width:100%;min-width:0;height:var(--email-address-chip-height, 24px);margin:0;padding:0;box-sizing:border-box;border:none;outline:none;background:none;color:inherit;font:inherit;letter-spacing:inherit;line-height:var(--email-address-chip-height, 24px)}:host :where([data-slot=input][data-refused]){color:var(--email-address-chip-invalid-color, var(--mat-sys-error, light-dark(#b3261e, #f2b8b5)))}:host :where([data-slot=input])::placeholder{color:var(--email-address-input-placeholder-color, var(--mat-sys-on-surface-variant, light-dark(#5f6368, #9aa0a6)))}\n"], dependencies: [{ kind: "component", type: AddressChip, selector: "[email-address-chip]", inputs: ["address", "removable", "inline", "aria-current", "removeTabbable", "removeLabel", "invalidLabel", "pendingLabel", "aria-disabled", "holdDelay", "copiedLabel", "draggable", "removeTemplate"], outputs: ["removed", "copied"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] });
1009
+ }
1010
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AddressInput, decorators: [{
1011
+ type: Component,
1012
+ args: [{ selector: '[email-address-input]', imports: [AddressChip, NgTemplateOutlet], host: {
1013
+ '[attr.aria-disabled]': 'disabled() || null',
1014
+ '[attr.data-invalid]': 'flagged() || null',
1015
+ '[attr.data-full]': 'full() || null',
1016
+ '[attr.data-focused]': 'focused() || null',
1017
+ '[attr.data-dropping]': 'dropping() || null',
1018
+ '(pointerdown)': 'onPointerdown($event)',
1019
+ '(mousedown)': 'keepCaret($event)',
1020
+ '(click)': 'focus()',
1021
+ '(focusin)': 'onFocusin()',
1022
+ '(focusout)': 'onFocusout($event)',
1023
+ '(dragenter)': 'onDragover($event)',
1024
+ '(dragover)': 'onDragover($event)',
1025
+ '(dragleave)': 'onDragleave($event)',
1026
+ '(drop)': 'onDrop($event)',
1027
+ }, template: "<!-- No label here: the row around this control names it, through\n aria-labelledby or aria-label, both passed down to the text input. -->\n<!-- Focusable by script and by a press only (tabindex -1, while chips can\n be dragged): a press on a draggable chip must keep its default for the\n drag to start, and its focus lands here \u2014 inside the control. -->\n<ul #chipList data-slot=\"chips\" role=\"list\" [attr.tabindex]=\"canDrag() ? -1 : null\">\n <!-- The opt-in label (emailAddressLabel): first in the row, so the chips\n wrap under it. Hidden from assistive tech as text \u2014 it names the\n text input instead, through aria-labelledby. -->\n @if (labelSlot(); as slot) {\n <li data-slot=\"label\" aria-hidden=\"true\" [id]=\"labelId\">\n <ng-container [ngTemplateOutlet]=\"slot.template\" />\n </li>\n }\n @for (address of value(); track address) {\n <li\n email-address-chip\n [id]=\"chipId($index)\"\n [address]=\"address\"\n [removable]=\"!locked()\"\n [inline]=\"!focused()\"\n [draggable]=\"canDrag()\"\n [aria-current]=\"active() === $index\"\n [removeTabbable]=\"closed()\"\n [removeLabel]=\"removeLabel()\"\n [removeTemplate]=\"removeSlot()?.template ?? null\"\n [invalidLabel]=\"invalidLabel()\"\n [pendingLabel]=\"pendingLabel()\"\n [aria-disabled]=\"disabled()\"\n (removed)=\"removeChip(address)\"\n (copied)=\"onChipCopied($event)\"\n (click)=\"onChipClick($event, $index, field)\"\n (dblclick)=\"onChipDblclick($event, address, field)\"\n (dragstart)=\"onChipDragstart(address)\"\n (dragend)=\"onChipDragend()\"\n ></li>\n }\n <!-- Where a drag over the control would land: a line between entries,\n drawn on top and out of the flow \u2014 nothing moves under the pointer. -->\n @if (dropMarker(); as marker) {\n <li\n data-slot=\"drop-marker\"\n aria-hidden=\"true\"\n [style.left.px]=\"marker.x\"\n [style.top.px]=\"marker.y\"\n [style.height.px]=\"marker.height\"\n ></li>\n }\n <!-- The entry is a list item too, so the chips and the typing sit in one\n wrapping row \u2014 always after the last chip. Hidden once the field is full (From takes one address)\n with nothing to fix: the chips say everything, and a second address\n would only be refused. -->\n <li data-slot=\"entry\" [hidden]=\"closed()\">\n <input\n #field\n data-slot=\"input\"\n type=\"text\"\n inputmode=\"email\"\n autocomplete=\"off\"\n autocapitalize=\"off\"\n spellcheck=\"false\"\n [id]=\"id\"\n [attr.name]=\"name() || null\"\n [disabled]=\"disabled()\"\n [readOnly]=\"readonly()\"\n [placeholder]=\"value().length ? '' : placeholder()\"\n [attr.aria-labelledby]=\"labelledBy()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"describedBy()\"\n [attr.aria-required]=\"required() || null\"\n [attr.aria-invalid]=\"flagged() || refused() || null\"\n [attr.aria-activedescendant]=\"activeId()\"\n [attr.data-refused]=\"refused() || null\"\n (keydown)=\"onKeydown($event, field)\"\n (paste)=\"onPaste($event, field)\"\n (copy)=\"onClipboard($event, field, false)\"\n (cut)=\"onClipboard($event, field, true)\"\n (input)=\"onInput(field)\"\n (mousedown)=\"active.set(null)\"\n (focus)=\"onFocus(field)\"\n (blur)=\"onBlur($event, field)\"\n />\n </li>\n</ul>\n", styles: [":host{display:flex;min-width:0;color:var(--email-address-input-color, var(--mat-sys-on-surface, light-dark(#1f1f1f, #e3e3e3)));font-family:var(--email-address-input-font-family, var(--mat-sys-body-medium-font, system-ui, sans-serif));font-size:var(--email-address-input-font-size, var(--mat-sys-body-medium-size, .875rem));font-weight:var(--email-address-input-font-weight, var(--mat-sys-body-medium-weight, 400));line-height:var(--email-address-input-line-height, var(--mat-sys-body-medium-line-height, 1.25rem));letter-spacing:var(--email-address-input-letter-spacing, var(--mat-sys-body-medium-tracking, .016rem));cursor:text}:host([aria-disabled=true]){cursor:default;opacity:.6}:host :where([data-slot=chips]){position:relative;flex:1 1 0;display:flex;flex-wrap:wrap;align-items:center;gap:var(--email-address-input-row-gap, 8px) var(--email-address-input-column-gap, 4px);min-width:0;margin:0;padding:0;list-style:none}:host :where([data-slot=chips]):focus{outline:none}:host :where([data-slot=drop-marker]){position:absolute;box-sizing:content-box;margin-top:calc(-1 * var(--email-address-input-drop-overhang, 4px));padding-block:var(--email-address-input-drop-overhang, 4px);width:var(--email-address-input-drop-width, 2px);margin-left:calc(var(--email-address-input-drop-width, 2px) / -2);border-radius:1px;background:var(--email-address-input-drop-color, var(--mat-sys-primary, light-dark(#0b57d0, #a8c7fa)));pointer-events:none}:host :where([data-slot=label]){flex:none;margin-inline-end:var(--email-address-input-label-gap, 4px);color:var(--email-address-input-label-color, var(--mat-sys-on-surface-variant, light-dark(#444746, #c4c7c5)));line-height:var(--email-address-input-label-line-height, 24px);white-space:nowrap}:host(:not([data-focused])) :where([data-slot=chips]){column-gap:var(--email-address-input-inline-gap, .3em)}:host(:not([data-focused])) :where([email-address-chip]:has(+[email-address-chip])):after{content:\",\"}:host :where([data-slot=entry]){flex:1 1 8ch;min-width:8ch;display:flex}:host :where([data-slot=entry][hidden]){display:none}:host(:not([data-focused])) :where([data-slot=entry]){flex-basis:0;min-width:0}:host :where([data-slot=input]){flex:1 1 auto;width:100%;min-width:0;height:var(--email-address-chip-height, 24px);margin:0;padding:0;box-sizing:border-box;border:none;outline:none;background:none;color:inherit;font:inherit;letter-spacing:inherit;line-height:var(--email-address-chip-height, 24px)}:host :where([data-slot=input][data-refused]){color:var(--email-address-chip-invalid-color, var(--mat-sys-error, light-dark(#b3261e, #f2b8b5)))}:host :where([data-slot=input])::placeholder{color:var(--email-address-input-placeholder-color, var(--mat-sys-on-surface-variant, light-dark(#5f6368, #9aa0a6)))}\n"] }]
1028
+ }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], ariaLabelledby: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaDescribedby: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-describedby", required: false }] }], limit: [{ type: i0.Input, args: [{ isSignal: true, alias: "limit", required: false }] }], removeLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "removeLabel", required: false }] }], invalidLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalidLabel", required: false }] }], pendingLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "pendingLabel", required: false }] }], movedLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "movedLabel", required: false }] }], allowDrag: [{ type: i0.Input, args: [{ isSignal: true, alias: "allowDrag", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], touched: [{ type: i0.Input, args: [{ isSignal: true, alias: "touched", required: false }] }], touch: [{ type: i0.Output, args: ["touch"] }], labelSlot: [{ type: i0.ContentChild, args: [i0.forwardRef(() => AddressInputLabel), { isSignal: true }] }], removeSlot: [{ type: i0.ContentChild, args: [i0.forwardRef(() => AddressChipRemove), { isSignal: true }] }], field: [{ type: i0.ViewChild, args: ['field', { isSignal: true }] }], chipList: [{ type: i0.ViewChild, args: ['chipList', { isSignal: true }] }], chips: [{ type: i0.ViewChildren, args: [i0.forwardRef(() => AddressChip), { isSignal: true }] }] } });
1029
+
1030
+ /** The error kinds `addressList` reports, for a host that switches on them. */
1031
+ const ADDRESS_LIST_EMPTY = 'addressList.empty';
1032
+ const ADDRESS_LIST_INVALID = 'addressList.invalid';
1033
+ const ADDRESS_LIST_TOO_MANY = 'addressList.tooMany';
1034
+ const MESSAGES = {
1035
+ empty: (min) => (min === 1 ? 'Add at least one address' : `Add at least ${min} addresses`),
1036
+ invalid: (offenders) => {
1037
+ const [first, ...rest] = offenders;
1038
+ if (!rest.length)
1039
+ return `“${first}” is not an email address`;
1040
+ return `“${first}” and ${rest.length} other${rest.length === 1 ? '' : 's'} are not email addresses`;
1041
+ },
1042
+ tooMany: (max) => (max === 1 ? 'Only one address here' : `At most ${max} addresses`),
1043
+ };
1044
+ /**
1045
+ * The rule an address field needs and the built-ins cannot give it:
1046
+ * `required` takes an empty array for a value, and `email` validates one
1047
+ * string. This validates a `string[]` of mailboxes in header form — the
1048
+ * address input's value — as a list: at least `min` of them (one, unless
1049
+ * told otherwise), at most `max`, and every one a well-formed address, with
1050
+ * the offenders named in the message so a chip can be found and fixed. A
1051
+ * placeholder a template fills in later (`{{contact.email}}`, by the rule's
1052
+ * `isPlaceholder`) is no offender — it counts toward `min` and `max`;
1053
+ * whether it may still be sent unresolved is the host's call.
1054
+ *
1055
+ * ```ts
1056
+ * const envelope = form(model, (p) => {
1057
+ * addressList(p.from, { max: 1 });
1058
+ * addressList(p.to);
1059
+ * addressList(p.cc, { min: 0 });
1060
+ * });
1061
+ * ```
1062
+ *
1063
+ * Errors carry a `kind` from the `ADDRESS_LIST_*` constants and a `message`
1064
+ * the input shows; pass `messages` to word or translate them.
1065
+ */
1066
+ function addressList(path, options = {}) {
1067
+ const { min = 1, max = Infinity } = options;
1068
+ const messages = { ...MESSAGES, ...options.messages };
1069
+ const rules = options.rules ?? rulesInForce();
1070
+ validate(path, ({ value }) => {
1071
+ const addresses = value();
1072
+ const errors = [];
1073
+ if (addresses.length < min) {
1074
+ errors.push({ kind: ADDRESS_LIST_EMPTY, message: messages.empty(min) });
1075
+ }
1076
+ const offenders = addresses.filter((address) => !isMailbox(address, rules) && !isPending(address, rules));
1077
+ if (offenders.length) {
1078
+ errors.push({ kind: ADDRESS_LIST_INVALID, message: messages.invalid(offenders) });
1079
+ }
1080
+ if (addresses.length > max) {
1081
+ errors.push({ kind: ADDRESS_LIST_TOO_MANY, message: messages.tooMany(max) });
1082
+ }
1083
+ return errors.length ? errors : null;
1084
+ });
1085
+ }
1086
+ /** The rule provided where the schema runs — the form's injection context,
1087
+ when it was made in one — or ours. */
1088
+ function rulesInForce() {
1089
+ try {
1090
+ return inject(ADDRESS_RULES);
1091
+ }
1092
+ catch {
1093
+ return defaultAddressRules;
1094
+ }
1095
+ }
1096
+
1097
+ /*
1098
+ * Public API Surface of @h-k-dev/angular-email-editor/address-input
1099
+ */
1100
+
1101
+ /**
1102
+ * Generated bundle index. Do not edit.
1103
+ */
1104
+
1105
+ export { ADDRESS_LIST_EMPTY, ADDRESS_LIST_INVALID, ADDRESS_LIST_TOO_MANY, AddressDragGroup, AddressInput, AddressInputLabel, addressList };
1106
+ //# sourceMappingURL=h-k-dev-angular-email-editor-address-input.mjs.map