@h-k-dev/angular-email-editor 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -2
- package/fesm2022/h-k-dev-angular-email-editor-actions.mjs +179 -0
- package/fesm2022/h-k-dev-angular-email-editor-actions.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-address-chip.mjs +285 -0
- package/fesm2022/h-k-dev-angular-email-editor-address-chip.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-address-input.mjs +686 -0
- package/fesm2022/h-k-dev-angular-email-editor-address-input.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-address.mjs +489 -0
- package/fesm2022/h-k-dev-angular-email-editor-address.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-anchor.mjs +64 -0
- package/fesm2022/h-k-dev-angular-email-editor-anchor.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-attachment-chip.mjs +387 -0
- package/fesm2022/h-k-dev-angular-email-editor-attachment-chip.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-attachment-chips.mjs +80 -0
- package/fesm2022/h-k-dev-angular-email-editor-attachment-chips.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-chat-input.mjs +346 -0
- package/fesm2022/h-k-dev-angular-email-editor-chat-input.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-focus.mjs +68 -0
- package/fesm2022/h-k-dev-angular-email-editor-focus.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-image.mjs +132 -0
- package/fesm2022/h-k-dev-angular-email-editor-image.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-material.mjs +124 -0
- package/fesm2022/h-k-dev-angular-email-editor-material.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-metrics.mjs +243 -0
- package/fesm2022/h-k-dev-angular-email-editor-metrics.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-palette.mjs +87 -0
- package/fesm2022/h-k-dev-angular-email-editor-palette.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-proposal.mjs +307 -0
- package/fesm2022/h-k-dev-angular-email-editor-proposal.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor-suggestion-menu.mjs +392 -0
- package/fesm2022/h-k-dev-angular-email-editor-suggestion-menu.mjs.map +1 -0
- package/fesm2022/h-k-dev-angular-email-editor.mjs +18818 -0
- package/fesm2022/h-k-dev-angular-email-editor.mjs.map +1 -0
- package/package.json +133 -3
- package/styles/_scroll.scss +101 -0
- package/types/h-k-dev-angular-email-editor-actions.d.ts +147 -0
- package/types/h-k-dev-angular-email-editor-address-chip.d.ts +193 -0
- package/types/h-k-dev-angular-email-editor-address-input.d.ts +328 -0
- package/types/h-k-dev-angular-email-editor-address.d.ts +125 -0
- package/types/h-k-dev-angular-email-editor-anchor.d.ts +44 -0
- package/types/h-k-dev-angular-email-editor-attachment-chip.d.ts +271 -0
- package/types/h-k-dev-angular-email-editor-attachment-chips.d.ts +48 -0
- package/types/h-k-dev-angular-email-editor-chat-input.d.ts +101 -0
- package/types/h-k-dev-angular-email-editor-focus.d.ts +40 -0
- package/types/h-k-dev-angular-email-editor-image.d.ts +66 -0
- package/types/h-k-dev-angular-email-editor-material.d.ts +65 -0
- package/types/h-k-dev-angular-email-editor-metrics.d.ts +110 -0
- package/types/h-k-dev-angular-email-editor-palette.d.ts +51 -0
- package/types/h-k-dev-angular-email-editor-proposal.d.ts +170 -0
- package/types/h-k-dev-angular-email-editor-suggestion-menu.d.ts +177 -0
- package/types/h-k-dev-angular-email-editor.d.ts +3959 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"h-k-dev-angular-email-editor-address-input.mjs","sources":["../../../projects/angular-email-editor/address-input/address-input.slots.ts","../../../projects/angular-email-editor/address-input/address-input.ts","../../../projects/angular-email-editor/address-input/address-input.html","../../../projects/angular-email-editor/address-input/address-rules.ts","../../../projects/angular-email-editor/address-input/public-api.ts","../../../projects/angular-email-editor/address-input/h-k-dev-angular-email-editor-address-input.ts"],"sourcesContent":["import { Directive, TemplateRef, inject } from '@angular/core';\n\n/**\n * The address input's label slot — opt in. By default the control owns no\n * label: the template that holds the form draws the row and the label beside\n * it, as it does for a plain `<input>`. A host that wants the label *inside*\n * the control — at the start of the chips, the chips wrapping under it, the\n * whole control one box (a Material form field around it, as iusta core\n * writes its rows) — hands the control a template:\n *\n * <div email-address-input [formField]=\"envelope.to\">\n * <ng-template emailAddressLabel>To</ng-template>\n * </div>\n *\n * The control renders it first in its row, in a box of its own\n * (`[data-slot=label]`), and names its text input by it — unless the host\n * named the input itself (`aria-labelledby` / `aria-label`).\n */\n@Directive({ selector: 'ng-template[emailAddressLabel]' })\nexport class AddressInputLabel {\n readonly template = inject(TemplateRef);\n}\n","import {\n Component,\n ElementRef,\n inject,\n\n // Signals\n booleanAttribute,\n computed,\n contentChild,\n input,\n model,\n numberAttribute,\n output,\n signal,\n viewChild,\n viewChildren,\n} from '@angular/core';\nimport type { FormValueControl } from '@angular/forms/signals';\nimport { ADDRESS_RULES, addressKey, isMailbox, isPending, separatesAt } from '@h-k-dev/angular-email-editor/address';\nimport { AddressChip, AddressChipRemove } from '@h-k-dev/angular-email-editor/address-chip';\nimport { NgTemplateOutlet } from '@angular/common';\nimport { AddressInputLabel } from './address-input.slots';\n\nlet nextId = 0;\n\n/**\n * An address field the way Gmail's works: committed addresses as chips,\n * free typing after them. Enter, comma, semicolon or a paste commits what\n * was typed — a comma or semicolon inside a quoted name or angle brackets is\n * just typed, and no key commits while an IME is composing; Backspace on the empty input takes the chip before the caret\n * back for editing; `limit` caps the count (From takes one) and hides the\n * input once reached.\n *\n * **Only an address becomes a chip while typing.** Enter, comma, semicolon,\n * Tab and a paste commit the addresses in what was typed and leave the rest —\n * what is not an address yet — in the input, flagged, for the user to\n * finish. Leaving the field commits everything, so the form sees the typo\n * and flags it; and focus coming back hands the malformed entries at the\n * end of the list straight back to the input, as plain typing again.\n *\n * **The input is always at the end, and editing happens there.** A chip\n * taken back for editing — a double click, Enter on a picked chip,\n * Backspace, `edit()` — leaves its place: its address goes into the input,\n * after the last chip, exactly like a typo the field handed back — and what\n * is committed from it joins the end of the list. There is one place where\n * text is typed, and it never moves.\n *\n * **One pending edit at a time.** There is only ever one thing being fixed,\n * and it is what the caret is on. Starting another edit — `edit()`, Enter\n * on a picked chip, Backspace taking the chip before the caret back — ends\n * the one pending: a typo left in the input and any chip that is not an\n * address go.\n *\n * **Chips while focused, a line of text otherwise.** With focus elsewhere\n * the addresses read as a comma-separated line — no surface, no buttons;\n * focus in the input turns them into chips.\n *\n * **The arrow keys rove the chips; the caret stays in the input.** With\n * the caret at the start of the typing, ← puts a highlight on the last chip\n * and walks back along the list; → walks forward, and past the last chip\n * returns to the caret. Enter or F2 — or a double click on\n * any chip — edits it,\n * Backspace or Delete removes it, Escape drops the highlight, and so does\n * typing. A click on a chip highlights it. Reaching a chip either way is\n * being done with the typing: an address in the input becomes a chip first,\n * as Enter would make it. The highlight is\n * `aria-activedescendant` on the input and `aria-current` on the chip, and the\n * chips' remove buttons stay out of the tab order — Tab lands on the input —\n * except when the field is full and has no input to land on.\n *\n * A display name is kept — `Ada Lovelace <ada@example.com>` is one chip\n * that shows \"Ada Lovelace\" — and the value stays `string[]` in header\n * form, ready for a `To:` line. Typed bare, `Ada Lovelace ada@example.com`\n * becomes that same chip. An address is in the list once: another entry\n * with the same address — in any case, under any name — is dropped.\n *\n * **The control, not the row.** By default it owns no label and draws no row: the\n * template that holds the form puts it in a row of its own making, beside a\n * label of its own making, exactly as it does for a plain `<input>` — and\n * names the control through `aria-labelledby` (the label's id) or\n * `aria-label`, which land on the text input inside, the element assistive\n * tech reaches. Clicking anywhere on the control puts the caret in; a row\n * that wants its label to do the same calls `focus()`.\n *\n * **A signal-forms control, optionally.** It implements `FormValueControl`\n * for `string[]`: bind a field with `[formField]=\"envelope.to\"` and the\n * directive drives `value` both ways, pushes `invalid`, `touched`,\n * `disabled`, `readonly`, `required` and `name` in, and hears `touch` when\n * focus leaves the input. Without a form, `[(value)]` alone is the whole\n * contract; the state inputs are optional and the chips still flag a\n * malformed address on their own. The rules that go with it — `addressList`\n * — live beside it, because the built-in `required` and `email` know\n * nothing of an array of mailboxes.\n *\n * **No messages of its own.** The control reflects the field's state —\n * invalid *and* touched, so nothing shouts before the user has left it —\n * and a malformed address is flagged on its chip; wording what is wrong is\n * the job of the component that owns the form, which has the errors.\n *\n * **Parts are `data-slot`s** — `chips`, `entry`, `input` — plus the chips'\n * own; that is how the control is styled from outside: theme it through\n * the `--email-*` tokens, and reach a part for a structural override with\n * two attributes.\n *\n * **The selection and its commands are public.** A host's own controls —\n * a bar over the writer, the way a phone's action bar sits over the app\n * bar — work the picked chip through `current()` and `select()` for the\n * state and `edit()`, `remove()` and `copy()` for the commands, each on the\n * current chip unless given another. Such a bar's buttons must decline\n * their mousedown (`(mousedown)=\"$event.preventDefault()\"`): focus stays in\n * the input, and the selection with it — focus leaving the control clears\n * the selection.\n *\n * **The chips' remove control is a template slot.** An\n * `ng-template[emailAddressChipRemove]` in the input's content is handed to\n * every chip it renders, in place of the default × button.\n *\n * **State on the host.** `aria-disabled` while disabled; `data-invalid`\n * while invalid and touched; `data-full` once `limit` is reached;\n * `data-focused` while focus is anywhere in the control. The text input\n * carries `data-refused` while it holds text a commit left behind.\n *\n * No Material, no icon font, no headless library. It holds the list it\n * shows and nothing else: contacts, lookups and sending are the host's.\n */\n@Component({\n selector: '[email-address-input]',\n imports: [AddressChip, NgTemplateOutlet],\n templateUrl: './address-input.html',\n styleUrl: './address-input.scss',\n host: {\n '[attr.aria-disabled]': 'disabled() || null',\n '[attr.data-invalid]': 'flagged() || null',\n '[attr.data-full]': 'full() || null',\n '[attr.data-focused]': 'focused() || null',\n '(pointerdown)': 'onPointerdown($event)',\n '(mousedown)': 'keepCaret($event)',\n '(click)': 'focus()',\n '(focusin)': 'onFocusin()',\n '(focusout)': 'onFocusout($event)',\n },\n})\nexport class AddressInput implements FormValueControl<string[]> {\n /** The committed addresses, in header form. Two-way; the form's value. */\n readonly value = model<string[]>([]);\n\n readonly placeholder = input('');\n\n /** The id of the row's label, passed through to the text input — the\n host's label, wherever the host put it. */\n readonly ariaLabelledby = input<string | null>(null, { alias: 'aria-labelledby' });\n\n /** A name for the text input when there is no visible label. */\n readonly ariaLabel = input<string | null>(null, { alias: 'aria-label' });\n\n /** The ids of whatever describes the field — a hint, an error line —\n passed through to the text input, where assistive tech reads them. */\n readonly ariaDescribedby = input<string | null>(null, { alias: 'aria-describedby' });\n\n readonly #frameIds = signal<readonly string[]>([]);\n\n /** What the text input's `aria-describedby` says: the host's own ids and a\n frame's, each once. */\n protected readonly describedBy = computed(() => {\n const ids = new Set([...(this.ariaDescribedby()?.split(/\\s+/) ?? []), ...this.#frameIds()]);\n ids.delete('');\n return ids.size ? [...ids].join(' ') : null;\n });\n\n /** Adds the ids of a frame's own lines — a form field's hint and error —\n to what describes the text input, beside the host's `aria-describedby`;\n each call replaces the frame's previous ids. */\n describe(ids: readonly string[]): void {\n this.#frameIds.set(ids);\n }\n\n /** Most addresses the field takes; the input hides once reached. Named\n `limit`, not `max`: the form contract keeps that name for the `max` rule. */\n readonly limit = input(Infinity, { transform: numberAttribute });\n\n /** Prefix for each chip's remove button — \"Remove ada@example.com\". */\n readonly removeLabel = input('Remove');\n\n /** What a malformed address is flagged as. */\n readonly invalidLabel = input('not an email address');\n\n /** The chips' note on a placeholder a template fills in later. */\n readonly pendingLabel = input('filled in when sent');\n\n // ── the form contract: pushed in by the field directive ───────────────\n\n /** The input's `name` attribute; the directive derives one from the path. */\n readonly name = input('');\n\n readonly disabled = input(false, { transform: booleanAttribute });\n readonly readonly = input(false, { transform: booleanAttribute });\n readonly required = input(false, { transform: booleanAttribute });\n readonly invalid = input(false, { transform: booleanAttribute });\n readonly touched = input(false, { transform: booleanAttribute });\n\n /** Focus left the input. The directive marks the field touched on it. */\n readonly touch = output<void>();\n\n /** The text input's id, for a host label's `for`. */\n readonly id = `email-address-input-${nextId++}`;\n\n /** The host's label template, if it opted into one — rendered first in\n the row; the text input is named by it. */\n protected readonly labelSlot = contentChild(AddressInputLabel);\n\n /** The label box's id, for the text input's `aria-labelledby`. */\n protected readonly labelId = `${this.id}-label`;\n\n /** What names the text input: the host's own `aria-labelledby`; else the\n label slot — unless the host gave an `aria-label` instead. */\n protected readonly labelledBy = computed(\n () => this.ariaLabelledby() ?? (this.labelSlot() && !this.ariaLabel() ? this.labelId : null),\n );\n\n /** The host's remove template, passed on to every chip. */\n protected readonly removeSlot = contentChild(AddressChipRemove);\n\n protected readonly field = viewChild.required<ElementRef<HTMLInputElement>>('field');\n\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef);\n\n /** The address rule in force — ours, or the host's (`provideAddressRules`):\n how typing splits, what is an address, what is one recipient. */\n readonly #rules = inject(ADDRESS_RULES);\n /** What becomes a chip: a well-formed mailbox, or a placeholder a\n template fills in later. Everything else is a typo to hand back. */\n #accepts = (raw: string) => isMailbox(raw, this.#rules) || isPending(raw, this.#rules);\n #key = (raw: string) => addressKey(raw, this.#rules);\n\n readonly #focused = signal(false);\n\n /** Focus is somewhere in the control — the input or a chip's remove\n button. The chips are chips only then. Read-only; for a host's own\n frame (a form field whose label floats on it). */\n readonly focused = this.#focused.asReadonly();\n\n readonly #text = signal('');\n\n /** What is typed in the input and not committed yet — for a host's own\n frame, where a field with typing in it is not empty. */\n readonly text = this.#text.asReadonly();\n\n /** The input holds text a commit left behind: not an address yet. */\n protected readonly refused = signal(false);\n\n /** The chip the arrow keys or a click picked, by index in the value — the\n one Enter, Backspace and Delete act on while the caret stays in the\n input. */\n protected readonly active = signal<number | null>(null);\n\n /** The picked chip's address — the one the arrow keys or a click reached\n and the commands act on — or null. Public, for a host's own controls. */\n readonly current = computed<string | null>(() => {\n const index = this.active();\n return index === null ? null : (this.value()[index] ?? null);\n });\n\n /** Picks a chip by address, or none. */\n select(address: string | null): void {\n const index = address === null ? -1 : this.value().indexOf(address);\n this.active.set(index < 0 ? null : index);\n }\n\n /** The chips as rendered, for the commands that are the chip's own. */\n protected readonly chips = viewChildren(AddressChip);\n\n /** The active chip's id, for the input's `aria-activedescendant`. */\n protected readonly activeId = computed(() => {\n const index = this.active();\n return index !== null && index < this.value().length ? this.chipId(index) : null;\n });\n\n protected chipId(index: number): string {\n return `${this.id}-chip-${index}`;\n }\n\n /** The cap is reached: a further address is refused. */\n readonly full = computed(() => this.value().length >= this.limit());\n\n /** The malformed addresses at the end of the list — what focus hands back\n to the input. */\n readonly #trailingMalformed = computed(() => {\n const value = this.value();\n let start = value.length;\n while (start > 0 && !this.#accepts(value[start - 1])) start--;\n return value.slice(start);\n });\n\n /** Full, and nothing in it to fix: the input hides — the chips say\n everything. A full list ending in a typo keeps it, so focus can hand\n the typo back. */\n protected readonly closed = computed(() => this.full() && !this.#trailingMalformed().length);\n\n /** Nothing may change: disabled or read-only. Chips lose their remove\n button, the input is out of play. */\n protected readonly locked = computed(() => this.disabled() || this.readonly());\n\n /** Invalid *and* touched — the moment the state becomes the user's business. */\n protected readonly flagged = computed(() => this.invalid() && this.touched());\n\n /** Splits a run into addresses and adds the new ones to the end of the\n list, up to `limit`. Duplicates — by address, case-insensitively —\n are dropped; a malformed one is kept and\n flagged — this is the host's way in, and the host decides what it\n holds. */\n commit(raw: string): void {\n this.#insert(this.#rules.split(raw));\n }\n\n /** Drops one address — the picked chip's by default. Identity by string:\n the list never holds the same header form twice, so this takes exactly\n the chip that asked. */\n remove(address: string | null = this.current()): void {\n if (this.locked() || address === null) return;\n this.active.set(null);\n const index = this.value().indexOf(address);\n if (index < 0) return;\n this.value.update((current) => current.filter((a) => a !== address));\n }\n\n /** A chip's remove control was used: the address goes, and the caret\n comes back to the input — the focused button went with its chip, and\n focus left on nothing would strand a keyboard user and read to a host\n as the field being left. */\n protected removeChip(address: string): void {\n this.remove(address);\n this.focus();\n }\n\n /** Takes a chip — the picked one by default — back for editing: it\n leaves the list and the input, at the end, holds its address, caret at\n the end. The edit pending until now ends first. A locked list edits\n nothing. */\n edit(\n address: string | null = this.current(),\n input: HTMLInputElement = this.field().nativeElement,\n ): void {\n if (this.locked() || address === null) return;\n this.active.set(null);\n this.#endPending(input, address);\n if (!this.value().includes(address)) return;\n this.remove(address);\n this.#write(input, address);\n input.focus();\n input.setSelectionRange(input.value.length, input.value.length);\n }\n\n /** Ends the pending edit so another can start: the addresses typed so far\n become chips, the rest of the typing goes, and so\n does every chip that is not an address — but `keep`, the one about to\n be edited. */\n #endPending(input: HTMLInputElement, keep?: string): void {\n this.#insert(this.#rules.split(input.value).filter((token) => this.#accepts(token)));\n this.#write(input, '');\n this.refused.set(false);\n const value = this.value();\n const kept = value.filter((address) => this.#accepts(address) || address === keep);\n if (kept.length !== value.length) this.value.set(kept);\n }\n\n /** Puts the caret in the input — the whole control is the field, and a\n host's label row may forward its own clicks here. A full field has no\n input to put it in: focus goes to the last chip's remove control. */\n focus(): void {\n if (this.locked()) return;\n if (!this.closed()) {\n this.field().nativeElement.focus();\n return;\n }\n const controls = this.#host.nativeElement.querySelectorAll<HTMLElement>(\n '[data-slot=trailing] :is(button, [href], input, [tabindex]:not([tabindex=\"-1\"]))',\n );\n controls[controls.length - 1]?.focus();\n }\n\n /** A press anywhere on the control is the input's from that moment: it\n takes focus at the press, not at the click after the release — so a\n chip pressed in a line of text turns the line to chips at once, and a\n hold on a chip runs with the document focused, which the clipboard\n insists on. `keepCaret` then declines the press's own default, which\n would move focus off again. */\n protected onPointerdown(event: PointerEvent): void {\n const input = this.field().nativeElement;\n if (event.target === input || this.locked() || this.closed()) return;\n input.focus();\n }\n\n /** A press anywhere on the control but the text input itself — a chip,\n its button, the gap between — leaves the caret where it is. The\n browser would otherwise move focus to the body for the press and back\n on the click, and in that instant the row would drop to text and\n reflow: a flash, and a blur that commits and touches for nothing. */\n protected keepCaret(event: MouseEvent): void {\n if (event.target !== this.field().nativeElement) event.preventDefault();\n }\n\n /** A click on a chip — not on its remove control — picks it, and only\n that: a click on the picked chip picks it again. The caret is in the\n input either way. */\n protected onChipClick(event: MouseEvent, index: number, input: HTMLInputElement): void {\n if ((event.target as Element).closest('[data-slot=trailing]') || this.locked()) return;\n this.#pick(index, input);\n input.focus();\n }\n\n /** A double click on a chip — not on its remove control — takes it back\n for editing. */\n protected onChipDblclick(event: MouseEvent, address: string, input: HTMLInputElement): void {\n if ((event.target as Element).closest('[data-slot=trailing]')) return;\n this.edit(address, input);\n }\n\n /** Copies a chip's address — the picked one by default — to the\n clipboard, as a hold on the chip does; the chip shows and says so.\n Resolves to whether the copy went. */\n async copy(address: string | null = this.current()): Promise<boolean> {\n const chip = this.chips().find((candidate) => candidate.address() === address);\n return chip ? chip.copy() : false;\n }\n\n /** Picking a chip is being done with the typing: the addresses in it\n become chips first, as Enter would make them, and what is not an\n address stays behind, flagged. */\n #pick(index: number, input: HTMLInputElement): void {\n const address = this.value()[index];\n this.#settle(input, input.value);\n this.active.set(address === undefined ? null : this.value().indexOf(address));\n }\n\n protected onFocusin(): void {\n this.#focused.set(true);\n }\n\n protected onInput(input: HTMLInputElement): void {\n this.#text.set(input.value);\n this.refused.set(false);\n this.active.set(null);\n }\n\n protected onKeydown(event: KeyboardEvent, input: HTMLInputElement): void {\n // An IME's own Enter picks its candidate; nothing here may act on it.\n if (event.isComposing) return;\n const active = this.active();\n if (active !== null && this.#onActiveKey(event, active, input)) return;\n switch (event.key) {\n case 'ArrowLeft': {\n // From the start of the typing, ← reaches the last chip — the\n // typing becoming chips first, when it holds an address.\n if (input.selectionStart !== 0 || input.selectionEnd !== 0 || this.locked()) return;\n const typed = this.#rules.split(input.value).some((token) => this.#accepts(token));\n if (typed) this.#settle(input, input.value);\n const last = this.value().length - 1;\n if (typed || last >= 0) event.preventDefault();\n if (last >= 0) this.active.set(last);\n return;\n }\n case ',':\n case ';':\n // Inside a quoted name or angle brackets the character is the\n // mailbox's own: `\"Lovelace, Ada\"`.\n if (!separatesAt(input.value, input.selectionStart ?? input.value.length)) return;\n event.preventDefault();\n this.#settle(input, input.value);\n return;\n case 'Enter':\n // Swallowed even with nothing typed: Enter in an address row must\n // never submit the form around it. The subject line is where Enter\n // sends.\n event.preventDefault();\n this.#settle(input, input.value);\n return;\n case 'Tab':\n // Tab on an address commits it and keeps the caret here, ready for\n // the next one — the list is not left until there is nothing more\n // to commit. Tab on nothing, on a typo, or backwards leaves the\n // field as ever, and leaving commits and flags what was typed.\n if (event.shiftKey || !this.#rules.split(input.value).some((token) => this.#accepts(token))) {\n return;\n }\n event.preventDefault();\n this.#settle(input, input.value);\n return;\n case 'Backspace': {\n // On nothing typed, the last chip comes back to be edited — the one\n // pending edit.\n if (input.value) return;\n const previous = this.value().at(-1);\n if (previous === undefined || this.locked()) return;\n event.preventDefault();\n this.edit(previous, input);\n return;\n }\n }\n }\n\n /** The keys that act on the highlighted chip. True when one did. The\n arrows walk the chips: ← stops at the first, → past the last returns\n to the caret. */\n #onActiveKey(event: KeyboardEvent, active: number, input: HTMLInputElement): boolean {\n const chips = this.value();\n switch (event.key) {\n case 'ArrowLeft':\n this.active.set(Math.max(0, active - 1));\n break;\n case 'ArrowRight':\n if (active + 1 < chips.length) {\n this.active.set(active + 1);\n } else {\n this.active.set(null);\n input.setSelectionRange(0, 0);\n }\n break;\n case 'Escape':\n this.active.set(null);\n break;\n case 'Enter':\n case 'F2':\n this.edit(chips[active], input);\n break;\n case 'Backspace':\n case 'Delete':\n if (this.locked()) return false;\n this.remove(chips[active]);\n break;\n default:\n return false;\n }\n event.preventDefault();\n return true;\n }\n\n /** A paste of several addresses: the addresses become chips, the rest\n joins what the input already holds. A single token is left to the\n input, so a name with spaces can still be edited before it commits. */\n protected onPaste(event: ClipboardEvent, input: HTMLInputElement): void {\n const text = event.clipboardData?.getData('text') ?? '';\n if (this.#rules.split(text).length < 2) return;\n event.preventDefault();\n this.#settle(input, `${input.value}, ${text}`);\n }\n\n /** Focus arrived in the input: the typos at the end of the list come back\n into it, to be fixed — unless the user is already typing there. They\n come back as plain typing, not flagged: the caret is on them, and the\n next commit judges them again. */\n protected onFocus(input: HTMLInputElement): void {\n const typos = this.#trailingMalformed();\n if (input.value || !typos.length || this.locked()) return;\n this.value.update((current) => current.slice(0, current.length - typos.length));\n this.#write(input, typos.join(', '));\n input.setSelectionRange(input.value.length, input.value.length);\n this.refused.set(false);\n }\n\n /** Leaving the field commits everything typed — the addresses, then a\n typo at the end of the list, so the form sees it and the next focus\n hands it back — and is the touch. Moving to a chip's remove button is\n not leaving. */\n protected onBlur(event: FocusEvent, input: HTMLInputElement): void {\n if (this.#within(event)) return;\n const tokens = this.#rules.split(input.value);\n this.#insert(tokens.filter((token) => this.#accepts(token)));\n this.#insert(tokens.filter((token) => !this.#accepts(token)));\n this.#write(input, '');\n this.refused.set(false);\n this.touch.emit();\n }\n\n protected onFocusout(event: FocusEvent): void {\n if (this.#within(event)) return;\n this.#focused.set(false);\n this.active.set(null);\n }\n\n /** Commits the addresses in a run and leaves the rest in the input. */\n #settle(input: HTMLInputElement, raw: string): void {\n const tokens = this.#rules.split(raw);\n this.#insert(tokens.filter((token) => this.#accepts(token)));\n this.#write(input, tokens.filter((token) => !this.#accepts(token)).join(', '));\n this.refused.set(!!input.value);\n }\n\n /** Adds the new addresses to the end of the list, up to `limit` — each\n only if its address is not in the list yet; the entry already there\n keeps its name. */\n #insert(incoming: readonly string[]): void {\n if (!incoming.length) return;\n this.value.update((current) => {\n const next = [...current];\n const seen = new Set(next.map(this.#key));\n for (const address of incoming) {\n if (next.length >= this.limit()) break;\n if (seen.has(this.#key(address))) continue;\n seen.add(this.#key(address));\n next.push(address);\n }\n return next;\n });\n }\n\n /** Puts text in the input — the one way it is written, so `text` follows. */\n #write(input: HTMLInputElement, text: string): void {\n input.value = text;\n this.#text.set(text);\n }\n\n /** Whether focus is moving to somewhere else inside the control. */\n #within(event: FocusEvent): boolean {\n const destination = event.relatedTarget as Node | null;\n return !!destination && this.#host.nativeElement.contains(destination);\n }\n}\n","<!-- 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<ul data-slot=\"chips\" role=\"list\">\n <!-- The opt-in label (emailAddressLabel): first in the row, so the chips\n wrap under it. Hidden from assistive tech as text — 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 [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 (click)=\"onChipClick($event, $index, field)\"\n (dblclick)=\"onChipDblclick($event, address, field)\"\n ></li>\n }\n <!-- The entry is a list item too, so the chips and the typing sit in one\n wrapping row — 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 (input)=\"onInput(field)\"\n (mousedown)=\"active.set(null)\"\n (focus)=\"onFocus(field)\"\n (blur)=\"onBlur($event, field)\"\n />\n </li>\n</ul>\n","import { inject } from '@angular/core';\nimport {\n type PathKind,\n type SchemaPath,\n type SchemaPathRules,\n type ValidationError,\n validate,\n} from '@angular/forms/signals';\nimport {\n ADDRESS_RULES,\n AddressRules,\n defaultAddressRules,\n isMailbox,\n isPending,\n} from '@h-k-dev/angular-email-editor/address';\n\n/** The error kinds `addressList` reports, for a host that switches on them. */\nexport const ADDRESS_LIST_EMPTY = 'addressList.empty';\nexport const ADDRESS_LIST_INVALID = 'addressList.invalid';\nexport const ADDRESS_LIST_TOO_MANY = 'addressList.tooMany';\n\nexport interface AddressListOptions {\n /** Fewest addresses the list must hold. 1 by default; 0 for Cc and Bcc. */\n readonly min?: number;\n /** Most addresses the list may hold. Unbounded by default; 1 for From. */\n readonly max?: number;\n /** The address rule to judge by. By default the one in force where the\n form is made (`provideAddressRules`), else ours. */\n readonly rules?: AddressRules;\n /** The messages, for a host that words them itself or translates them. */\n readonly messages?: {\n readonly empty?: (min: number) => string;\n readonly invalid?: (offenders: readonly string[]) => string;\n readonly tooMany?: (max: number) => string;\n };\n}\n\nconst MESSAGES: Required<NonNullable<AddressListOptions['messages']>> = {\n empty: (min) => (min === 1 ? 'Add at least one address' : `Add at least ${min} addresses`),\n invalid: (offenders) => {\n const [first, ...rest] = offenders;\n if (!rest.length) return `“${first}” is not an email address`;\n return `“${first}” and ${rest.length} other${rest.length === 1 ? '' : 's'} are not email addresses`;\n },\n tooMany: (max) => (max === 1 ? 'Only one address here' : `At most ${max} addresses`),\n};\n\n/**\n * The rule an address field needs and the built-ins cannot give it:\n * `required` takes an empty array for a value, and `email` validates one\n * string. This validates a `string[]` of mailboxes in header form — the\n * address input's value — as a list: at least `min` of them (one, unless\n * told otherwise), at most `max`, and every one a well-formed address, with\n * the offenders named in the message so a chip can be found and fixed. A\n * placeholder a template fills in later (`{{contact.email}}`, by the rule's\n * `isPlaceholder`) is no offender — it counts toward `min` and `max`;\n * whether it may still be sent unresolved is the host's call.\n *\n * ```ts\n * const envelope = form(model, (p) => {\n * addressList(p.from, { max: 1 });\n * addressList(p.to);\n * addressList(p.cc, { min: 0 });\n * });\n * ```\n *\n * Errors carry a `kind` from the `ADDRESS_LIST_*` constants and a `message`\n * the input shows; pass `messages` to word or translate them.\n */\nexport function addressList<TPathKind extends PathKind = PathKind.Root>(\n path: SchemaPath<string[], SchemaPathRules.Supported, TPathKind>,\n options: AddressListOptions = {},\n): void {\n const { min = 1, max = Infinity } = options;\n const messages = { ...MESSAGES, ...options.messages };\n const rules = options.rules ?? rulesInForce();\n validate(path, ({ value }) => {\n const addresses = value();\n const errors: ValidationError[] = [];\n if (addresses.length < min) {\n errors.push({ kind: ADDRESS_LIST_EMPTY, message: messages.empty(min) });\n }\n const offenders = addresses.filter(\n (address) => !isMailbox(address, rules) && !isPending(address, rules),\n );\n if (offenders.length) {\n errors.push({ kind: ADDRESS_LIST_INVALID, message: messages.invalid(offenders) });\n }\n if (addresses.length > max) {\n errors.push({ kind: ADDRESS_LIST_TOO_MANY, message: messages.tooMany(max) });\n }\n return errors.length ? errors : null;\n });\n}\n\n/** The rule provided where the schema runs — the form's injection context,\n when it was made in one — or ours. */\nfunction rulesInForce(): AddressRules {\n try {\n return inject(ADDRESS_RULES);\n } catch {\n return defaultAddressRules;\n }\n}\n","/*\n * Public API Surface of @h-k-dev/angular-email-editor/address-input\n */\n\nexport * from './address-input';\nexport * from './address-input.slots';\nexport * from './address-rules';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAEA;;;;;;;;;;;;;;;AAeG;MAEU,iBAAiB,CAAA;AACnB,IAAA,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC;uGAD5B,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,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M,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI;AACtC,IAAA,CAAC,CAAC;AACJ;AAEA;AACyC;AACzC,SAAS,YAAY,GAAA;AACnB,IAAA,IAAI;AACF,QAAA,OAAO,MAAM,CAAC,aAAa,CAAC;IAC9B;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,mBAAmB;IAC5B;AACF;;ACvGA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **Our address rule** — the one place that decides what an email address
|
|
5
|
+
* is, how a mailbox is read and written, and how typed or pasted text splits
|
|
6
|
+
* into mailboxes. Everything else in the library asks through
|
|
7
|
+
* {@link AddressRules}; a host that wants another rule provides its own
|
|
8
|
+
* (`provideAddressRules`) and this file is simply not used.
|
|
9
|
+
*
|
|
10
|
+
* Kept as a living document: what it implements, and every place it
|
|
11
|
+
* deliberately does less or more than the RFCs, is listed here — change the
|
|
12
|
+
* list with the code.
|
|
13
|
+
*
|
|
14
|
+
* **Implements**
|
|
15
|
+
* - RFC 5322 §3.4 `mailbox`: `addr-spec` or `name-addr` — a phrase of atoms
|
|
16
|
+
* and quoted strings (quoted-pairs unescaped) in front of an `angle-addr`.
|
|
17
|
+
* - RFC 5322 §3.2.2 comments, nested, with quoted-pairs: skipped — and a
|
|
18
|
+
* comment after a bare address names it (`jane@x.io (Jane Doe)`), the
|
|
19
|
+
* de facto reading of the old form.
|
|
20
|
+
* - RFC 5322 §3.4 `group`: `Team: a@x.io, b@x.io;` yields its members; an
|
|
21
|
+
* empty group (`undisclosed-recipients:;`) yields nothing.
|
|
22
|
+
* - RFC 5322 §4.4 obsolete routes: `<@relay.io:jane@x.io>` is `jane@x.io`.
|
|
23
|
+
* - RFC 5322 §3.4.1 `addr-spec`: a dot-atom or quoted-string local part.
|
|
24
|
+
* - RFC 6532 / 6531: UTF-8 in local parts, names and domains (`jörg@müller.de`).
|
|
25
|
+
* - RFC 5321 §4.1.2 / 4.1.3 domains: LDH labels of 1–63 characters, no
|
|
26
|
+
* hyphen at either end; address literals `[192.0.2.1]` and `[IPv6:…]`.
|
|
27
|
+
* - RFC 5321 §4.5.3.1 lengths, in octets (UTF-8): local part ≤ 64,
|
|
28
|
+
* address ≤ 254 (the 256-octet path less its brackets, RFC 3696 errata).
|
|
29
|
+
* - RFC 2047 encoded words in names (`=?UTF-8?B?…?=`, `Q` too, any charset
|
|
30
|
+
* the platform's `TextDecoder` knows), adjacent words joined as §6.2 says.
|
|
31
|
+
*
|
|
32
|
+
* **Deliberately stricter than the RFCs** — the typo worth catching:
|
|
33
|
+
* - A domain needs a dot (`hans@gmail` is legal, and a typo every time).
|
|
34
|
+
* - A top-level label is not all digits (RFC 3696 §2) — `a@1.2.3.4` is an
|
|
35
|
+
* IP address missing its brackets.
|
|
36
|
+
* - General address literals (`[tag:content]`) are refused; only IPv4/IPv6.
|
|
37
|
+
*
|
|
38
|
+
* **Deliberately more lenient — people type these:**
|
|
39
|
+
* - `,` `;` and line breaks all separate (RFC 5322: only `,`).
|
|
40
|
+
* - A bare run is read as people type it: words in front of an address name
|
|
41
|
+
* it (`Ada Lovelace ada@x.io`), addresses only whitespace separates are
|
|
42
|
+
* several, words naming no address stay one token (one typo, not three).
|
|
43
|
+
* - A group needs whitespace, `;`, `,` or the end after its colon, so
|
|
44
|
+
* `hans:müller@x.de` stays one (invalid) address instead of silently
|
|
45
|
+
* becoming `müller@x.de` under a group called `hans`.
|
|
46
|
+
*
|
|
47
|
+
* **Placeholders** — not an RFC matter, a template one: an address holding
|
|
48
|
+
* a `{{…}}` token (`{{contact.email}}`, `"{{contact.name}}" <{{contact.email}}>`)
|
|
49
|
+
* is filled in later, so it is neither valid nor invalid yet
|
|
50
|
+
* (`isPlaceholder`), and a separator inside the braces is part of it
|
|
51
|
+
* (`{{join contacts ", "}}` is one entry). Only doubled braces count — a
|
|
52
|
+
* lone `{` is atext and stays an ordinary character.
|
|
53
|
+
*/
|
|
54
|
+
// ── characters ───────────────────────────────────────────────────────────
|
|
55
|
+
/** RFC 5322 `atext`, plus RFC 6532's UTF-8 beyond ASCII. */
|
|
56
|
+
const ATEXT = "A-Za-z0-9!#$%&'*+/=?^_`{|}~\\-\\u0080-\\u{10FFFF}";
|
|
57
|
+
const DOT_ATOM = new RegExp(`^[${ATEXT}]+(?:\\.[${ATEXT}]+)*$`, 'u');
|
|
58
|
+
/** RFC 5322 `quoted-string` as a whole local part: qtext, quoted-pairs, spaces. */
|
|
59
|
+
const QUOTED_LOCAL = /^"(?:[\x20\x21\x23-\x5B\x5D-\x7E\u0080-\u{10FFFF}]|\\[\x20-\x7E])*"$/u;
|
|
60
|
+
/** An RFC 5321 label, with RFC 6531 U-labels: letters and digits of any
|
|
61
|
+
script, hyphens inside. */
|
|
62
|
+
const LABEL = /^(?!-)[\p{L}\p{N}\p{M}-]{1,63}(?<!-)$/u;
|
|
63
|
+
/** Characters a display name must be quoted to carry: RFC 5322's specials. */
|
|
64
|
+
const SPECIALS = /[()<>[\]:;@\\,."]/;
|
|
65
|
+
const octets = (text) => new TextEncoder().encode(text).length;
|
|
66
|
+
// ── addr-spec ────────────────────────────────────────────────────────────
|
|
67
|
+
/** Whether a bare address — no name, no brackets — is well-formed by the
|
|
68
|
+
rule above. */
|
|
69
|
+
function isEmailAddress(address) {
|
|
70
|
+
const at = address.lastIndexOf('@');
|
|
71
|
+
if (at < 1 || at === address.length - 1)
|
|
72
|
+
return false;
|
|
73
|
+
const local = address.slice(0, at);
|
|
74
|
+
const domain = address.slice(at + 1);
|
|
75
|
+
if (octets(local) > 64 || octets(address) > 254)
|
|
76
|
+
return false;
|
|
77
|
+
if (!DOT_ATOM.test(local) && !QUOTED_LOCAL.test(local))
|
|
78
|
+
return false;
|
|
79
|
+
return isDomain(domain);
|
|
80
|
+
}
|
|
81
|
+
function isDomain(domain) {
|
|
82
|
+
if (domain.startsWith('['))
|
|
83
|
+
return isAddressLiteral(domain);
|
|
84
|
+
const labels = domain.split('.');
|
|
85
|
+
if (labels.length < 2 || !labels.every((label) => LABEL.test(label)))
|
|
86
|
+
return false;
|
|
87
|
+
return !/^\d+$/.test(labels[labels.length - 1]);
|
|
88
|
+
}
|
|
89
|
+
function isAddressLiteral(literal) {
|
|
90
|
+
const inner = /^\[(.*)\]$/.exec(literal)?.[1];
|
|
91
|
+
if (inner === undefined)
|
|
92
|
+
return false;
|
|
93
|
+
if (/^IPv6:/i.test(inner))
|
|
94
|
+
return isIPv6(inner.slice(5));
|
|
95
|
+
return isIPv4(inner);
|
|
96
|
+
}
|
|
97
|
+
function isIPv4(text) {
|
|
98
|
+
const parts = text.split('.');
|
|
99
|
+
return parts.length === 4 && parts.every((part) => /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/.test(part));
|
|
100
|
+
}
|
|
101
|
+
function isIPv6(text) {
|
|
102
|
+
// The platform's own parser is the reference; the shape check keeps a
|
|
103
|
+
// host name or a port from sneaking through it.
|
|
104
|
+
if (!/^[0-9A-Fa-f:.]+$/.test(text) || !text.includes(':'))
|
|
105
|
+
return false;
|
|
106
|
+
try {
|
|
107
|
+
return new URL(`http://[${text}]/`).hostname.length > 2;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const at_top = (state) => !state.quoted && !state.comment && !state.angled && !state.braced;
|
|
114
|
+
/** Steps the scan past one character; true when the character is structure
|
|
115
|
+
(a quote, a bracket, part of a comment or an escape), not content at the
|
|
116
|
+
top level. */
|
|
117
|
+
function step(state, char) {
|
|
118
|
+
const half = state.brace;
|
|
119
|
+
state.brace = false;
|
|
120
|
+
if (state.braced) {
|
|
121
|
+
if (char === '}' && half)
|
|
122
|
+
state.braced = false;
|
|
123
|
+
else
|
|
124
|
+
state.brace = char === '}';
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if (char === '{' && !state.quoted && !state.comment) {
|
|
128
|
+
if (half)
|
|
129
|
+
state.braced = true;
|
|
130
|
+
else
|
|
131
|
+
state.brace = true;
|
|
132
|
+
return half;
|
|
133
|
+
}
|
|
134
|
+
if (state.escaped) {
|
|
135
|
+
state.escaped = false;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if ((state.quoted || state.comment) && char === '\\') {
|
|
139
|
+
state.escaped = true;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
if (state.quoted) {
|
|
143
|
+
if (char === '"')
|
|
144
|
+
state.quoted = false;
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
if (state.comment) {
|
|
148
|
+
if (char === '(')
|
|
149
|
+
state.comment++;
|
|
150
|
+
else if (char === ')')
|
|
151
|
+
state.comment--;
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
if (char === '"' && !state.angled) {
|
|
155
|
+
state.quoted = true;
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
if (char === '(' && !state.angled) {
|
|
159
|
+
state.comment = 1;
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
if (char === '<')
|
|
163
|
+
state.angled = true;
|
|
164
|
+
else if (char === '>')
|
|
165
|
+
state.angled = false;
|
|
166
|
+
else
|
|
167
|
+
return state.angled;
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
const fresh = () => ({
|
|
171
|
+
quoted: false,
|
|
172
|
+
comment: 0,
|
|
173
|
+
angled: false,
|
|
174
|
+
escaped: false,
|
|
175
|
+
braced: false,
|
|
176
|
+
brace: false,
|
|
177
|
+
});
|
|
178
|
+
/** Whether a separator typed at `caret` would separate — false inside a
|
|
179
|
+
quoted name, a comment or angle brackets, where a comma is part of the
|
|
180
|
+
mailbox: `"Lovelace, Ada"`. */
|
|
181
|
+
function separatesAt(raw, caret) {
|
|
182
|
+
const state = fresh();
|
|
183
|
+
for (const char of raw.slice(0, caret))
|
|
184
|
+
step(state, char);
|
|
185
|
+
return at_top(state) && !state.escaped;
|
|
186
|
+
}
|
|
187
|
+
// ── parse ────────────────────────────────────────────────────────────────
|
|
188
|
+
/**
|
|
189
|
+
* Splits a header-form mailbox into name and address: quoted strings
|
|
190
|
+
* unquoted and unescaped, encoded words decoded, comments skipped — or, after
|
|
191
|
+
* a bare address, taken as its name — and an obsolete route dropped.
|
|
192
|
+
* Anything that is no mailbox comes back as its trimmed text, as the address,
|
|
193
|
+
* for the rule to refuse.
|
|
194
|
+
*/
|
|
195
|
+
function parseMailbox(raw) {
|
|
196
|
+
const text = raw.trim();
|
|
197
|
+
const words = [];
|
|
198
|
+
const comments = [];
|
|
199
|
+
let address = null;
|
|
200
|
+
let bare = '';
|
|
201
|
+
let i = 0;
|
|
202
|
+
while (i < text.length) {
|
|
203
|
+
const char = text[i];
|
|
204
|
+
if (char === '"') {
|
|
205
|
+
const end = closing(text, i, '"');
|
|
206
|
+
if (end < 0)
|
|
207
|
+
return { address: text };
|
|
208
|
+
words.push(unescape(text.slice(i + 1, end)));
|
|
209
|
+
i = end + 1;
|
|
210
|
+
}
|
|
211
|
+
else if (char === '(') {
|
|
212
|
+
const end = closingComment(text, i);
|
|
213
|
+
if (end < 0)
|
|
214
|
+
return { address: text };
|
|
215
|
+
comments.push(decodeEncodedWords(unescape(text.slice(i + 1, end)).trim()));
|
|
216
|
+
i = end + 1;
|
|
217
|
+
}
|
|
218
|
+
else if (char === '<') {
|
|
219
|
+
const end = text.indexOf('>', i);
|
|
220
|
+
if (end < 0 || address !== null)
|
|
221
|
+
return { address: text };
|
|
222
|
+
address = text.slice(i + 1, end).trim().replace(/^@[^:]*:/, '');
|
|
223
|
+
i = end + 1;
|
|
224
|
+
}
|
|
225
|
+
else if (/\s/.test(char)) {
|
|
226
|
+
i++;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
let end = i;
|
|
230
|
+
while (end < text.length && !/[\s"(<]/.test(text[end]))
|
|
231
|
+
end++;
|
|
232
|
+
const atom = text.slice(i, end);
|
|
233
|
+
if (address === null)
|
|
234
|
+
words.push(atom);
|
|
235
|
+
else
|
|
236
|
+
return { address: text }; // text after the angle-addr
|
|
237
|
+
bare += atom;
|
|
238
|
+
i = end;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (address !== null) {
|
|
242
|
+
const name = phrase(words) || comments.join(' ');
|
|
243
|
+
return name ? { name, address } : { address };
|
|
244
|
+
}
|
|
245
|
+
// No angle brackets: an addr-spec, as one run of text.
|
|
246
|
+
if (words.length !== 1 || !bare)
|
|
247
|
+
return { address: text };
|
|
248
|
+
const name = comments.join(' ');
|
|
249
|
+
return name ? { name, address: bare } : { address: bare };
|
|
250
|
+
}
|
|
251
|
+
/** A phrase's words as a display name: one space between words, encoded
|
|
252
|
+
words decoded — and two encoded words only whitespace separates joined
|
|
253
|
+
with none (RFC 2047 §6.2). */
|
|
254
|
+
function phrase(words) {
|
|
255
|
+
return decodeEncodedWords(words.join(' ')).trim();
|
|
256
|
+
}
|
|
257
|
+
function closing(text, from, quote) {
|
|
258
|
+
for (let i = from + 1; i < text.length; i++) {
|
|
259
|
+
if (text[i] === '\\')
|
|
260
|
+
i++;
|
|
261
|
+
else if (text[i] === quote)
|
|
262
|
+
return i;
|
|
263
|
+
}
|
|
264
|
+
return -1;
|
|
265
|
+
}
|
|
266
|
+
function closingComment(text, from) {
|
|
267
|
+
let depth = 0;
|
|
268
|
+
for (let i = from; i < text.length; i++) {
|
|
269
|
+
if (text[i] === '\\')
|
|
270
|
+
i++;
|
|
271
|
+
else if (text[i] === '(')
|
|
272
|
+
depth++;
|
|
273
|
+
else if (text[i] === ')' && --depth === 0)
|
|
274
|
+
return i;
|
|
275
|
+
}
|
|
276
|
+
return -1;
|
|
277
|
+
}
|
|
278
|
+
const unescape = (text) => text.replace(/\\([\s\S])/g, '$1');
|
|
279
|
+
// ── format ───────────────────────────────────────────────────────────────
|
|
280
|
+
/** The header form of a mailbox — the name quoted (and escaped) when it has
|
|
281
|
+
to be. UTF-8 stays as it is (RFC 6532); a mailer encodes for the wire. */
|
|
282
|
+
function formatMailbox(mailbox) {
|
|
283
|
+
const name = mailbox.name?.trim();
|
|
284
|
+
if (!name)
|
|
285
|
+
return mailbox.address;
|
|
286
|
+
const quoted = SPECIALS.test(name) || /\s{2}/.test(name) ? `"${name.replace(/["\\]/g, '\\$&')}"` : name;
|
|
287
|
+
return `${quoted} <${mailbox.address}>`;
|
|
288
|
+
}
|
|
289
|
+
// ── split ────────────────────────────────────────────────────────────────
|
|
290
|
+
/** What separates the mailboxes of a typed run. */
|
|
291
|
+
const SEPARATORS = ',;\n\r';
|
|
292
|
+
/**
|
|
293
|
+
* Splits a typed, pasted or header run into mailboxes — see the leniencies
|
|
294
|
+
* above. A well-formed mailbox comes back in its canonical header form
|
|
295
|
+
* (`<a@x.io>` → `a@x.io`, `Dr. Ada <a@x.io>` → `"Dr. Ada" <a@x.io>`, a
|
|
296
|
+
* comment or an encoded word turned into the name); anything else comes back
|
|
297
|
+
* as typed, for the user to fix. Empty tokens are dropped; duplicates are
|
|
298
|
+
* the caller's.
|
|
299
|
+
*/
|
|
300
|
+
function splitAddresses(raw) {
|
|
301
|
+
const tokens = [];
|
|
302
|
+
const state = fresh();
|
|
303
|
+
let current = '';
|
|
304
|
+
for (let i = 0; i < raw.length; i++) {
|
|
305
|
+
const char = raw[i];
|
|
306
|
+
if (step(state, char)) {
|
|
307
|
+
current += char;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (SEPARATORS.includes(char)) {
|
|
311
|
+
tokens.push(current);
|
|
312
|
+
current = '';
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
// A group's colon: what came before it is the group's name, not a
|
|
316
|
+
// mailbox — dropped; its members follow, up to the `;`.
|
|
317
|
+
if (char === ':' && !/[@<]/.test(current) && /^(?:[\s,;]|$)/.test(raw.slice(i + 1, i + 2))) {
|
|
318
|
+
current = '';
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
current += char;
|
|
322
|
+
}
|
|
323
|
+
tokens.push(current);
|
|
324
|
+
return tokens
|
|
325
|
+
.map((token) => token.trim())
|
|
326
|
+
.filter(Boolean)
|
|
327
|
+
.flatMap((token) => (/[<"(]/.test(token) ? [token] : bareRun(token)))
|
|
328
|
+
.map(canonical);
|
|
329
|
+
}
|
|
330
|
+
/** A bare run's mailboxes: each run of words names the address after it. */
|
|
331
|
+
function bareRun(token) {
|
|
332
|
+
const mailboxes = [];
|
|
333
|
+
let name = [];
|
|
334
|
+
for (const word of token.split(/\s+/)) {
|
|
335
|
+
if (!isEmailAddress(word)) {
|
|
336
|
+
name.push(word);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
mailboxes.push(formatMailbox({ name: name.join(' ') || undefined, address: word }));
|
|
340
|
+
name = [];
|
|
341
|
+
}
|
|
342
|
+
if (name.length)
|
|
343
|
+
mailboxes.push(name.join(' '));
|
|
344
|
+
return mailboxes;
|
|
345
|
+
}
|
|
346
|
+
/** A well-formed mailbox in its canonical header form; anything else as it is. */
|
|
347
|
+
function canonical(token) {
|
|
348
|
+
const mailbox = parseMailbox(token);
|
|
349
|
+
return isEmailAddress(mailbox.address) ? formatMailbox(mailbox) : token;
|
|
350
|
+
}
|
|
351
|
+
// ── identity ─────────────────────────────────────────────────────────────
|
|
352
|
+
/**
|
|
353
|
+
* What makes two entries one recipient. The domain is case-insensitive and
|
|
354
|
+
* compared in its ASCII form (`müller.de` is `xn--mller-kva.de`); the local
|
|
355
|
+
* part is lowercased too — RFC 5321 lets a server tell `Ada` from `ada`, no
|
|
356
|
+
* real one does, and one recipient twice is the mistake that matters. Both
|
|
357
|
+
* NFC-normalized, so a composed and a decomposed `ü` are one.
|
|
358
|
+
*/
|
|
359
|
+
function addressIdentity(address) {
|
|
360
|
+
const at = address.lastIndexOf('@');
|
|
361
|
+
if (at < 0)
|
|
362
|
+
return address.trim().normalize('NFC').toLowerCase();
|
|
363
|
+
const local = address.slice(0, at).normalize('NFC').toLowerCase();
|
|
364
|
+
return `${local}@${asciiDomain(address.slice(at + 1).normalize('NFC').toLowerCase())}`;
|
|
365
|
+
}
|
|
366
|
+
function asciiDomain(domain) {
|
|
367
|
+
if (domain.startsWith('[') || /^[\x00-\x7F]*$/.test(domain))
|
|
368
|
+
return domain;
|
|
369
|
+
try {
|
|
370
|
+
return new URL(`http://${domain}/`).hostname;
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return domain;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// ── RFC 2047 ─────────────────────────────────────────────────────────────
|
|
377
|
+
const ENCODED_WORD = /=\?([^?\s]+)\?([BbQq])\?([^?\s]*)\?=/g;
|
|
378
|
+
/** Decodes the RFC 2047 encoded words in a header text; one that cannot be
|
|
379
|
+
decoded stays as it is. Two encoded words only whitespace separates are
|
|
380
|
+
joined with none. */
|
|
381
|
+
function decodeEncodedWords(text) {
|
|
382
|
+
return text
|
|
383
|
+
.replace(/(=\?[^?\s]+\?[BbQq]\?[^?\s]*\?=)\s+(?==\?[^?\s]+\?[BbQq]\?[^?\s]*\?=)/g, '$1')
|
|
384
|
+
.replace(ENCODED_WORD, (word, charset, encoding, data) => {
|
|
385
|
+
try {
|
|
386
|
+
const bytes = encoding.toUpperCase() === 'B'
|
|
387
|
+
? Uint8Array.from(atob(data), (c) => c.charCodeAt(0))
|
|
388
|
+
: quotedPrintable(data);
|
|
389
|
+
// RFC 2231 lets a charset carry a language: `UTF-8*de`.
|
|
390
|
+
return new TextDecoder(charset.split('*')[0], { fatal: true }).decode(bytes);
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
return word;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
function quotedPrintable(data) {
|
|
398
|
+
const bytes = [];
|
|
399
|
+
for (let i = 0; i < data.length; i++) {
|
|
400
|
+
const char = data[i];
|
|
401
|
+
if (char === '_')
|
|
402
|
+
bytes.push(0x20);
|
|
403
|
+
else if (char === '=' && /^[0-9A-Fa-f]{2}$/.test(data.slice(i + 1, i + 3))) {
|
|
404
|
+
bytes.push(parseInt(data.slice(i + 1, i + 3), 16));
|
|
405
|
+
i += 2;
|
|
406
|
+
}
|
|
407
|
+
else
|
|
408
|
+
bytes.push(...new TextEncoder().encode(char));
|
|
409
|
+
}
|
|
410
|
+
return Uint8Array.from(bytes);
|
|
411
|
+
}
|
|
412
|
+
// ── placeholders ─────────────────────────────────────────────────────────
|
|
413
|
+
/** Whether an address holds a `{{…}}` placeholder — one a template fills
|
|
414
|
+
in later, so neither valid nor invalid yet. */
|
|
415
|
+
function isAddressPlaceholder(address) {
|
|
416
|
+
return /\{\{[^{}]*\}\}/.test(address);
|
|
417
|
+
}
|
|
418
|
+
/** Our rule, as the contract every part of the library asks through. */
|
|
419
|
+
const defaultAddressRules = {
|
|
420
|
+
split: splitAddresses,
|
|
421
|
+
parse: parseMailbox,
|
|
422
|
+
format: formatMailbox,
|
|
423
|
+
isValid: isEmailAddress,
|
|
424
|
+
isPlaceholder: isAddressPlaceholder,
|
|
425
|
+
identity: addressIdentity,
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/** The address rule in force — ours unless a host provides its own. */
|
|
429
|
+
const ADDRESS_RULES = new InjectionToken('ADDRESS_RULES', {
|
|
430
|
+
providedIn: 'root',
|
|
431
|
+
factory: () => defaultAddressRules,
|
|
432
|
+
});
|
|
433
|
+
/**
|
|
434
|
+
* Puts a host's address rule in force: the parts given replace ours, the
|
|
435
|
+
* rest stay ours. Keeping an existing validator is one line:
|
|
436
|
+
*
|
|
437
|
+
* ```ts
|
|
438
|
+
* providers: [provideAddressRules({ isValid: isValidEmail })]
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
function provideAddressRules(rules) {
|
|
442
|
+
return { provide: ADDRESS_RULES, useValue: { ...defaultAddressRules, ...rules } };
|
|
443
|
+
}
|
|
444
|
+
/** Whether a header-form string is a mailbox whose address is well-formed. */
|
|
445
|
+
function isMailbox(raw, rules = defaultAddressRules) {
|
|
446
|
+
return rules.isValid(rules.parse(raw).address);
|
|
447
|
+
}
|
|
448
|
+
/** Whether a header-form entry's address is a placeholder — pending: a
|
|
449
|
+
template fills it in later, so it is no mistake to flag. */
|
|
450
|
+
function isPending(raw, rules = defaultAddressRules) {
|
|
451
|
+
return rules.isPlaceholder(rules.parse(raw).address);
|
|
452
|
+
}
|
|
453
|
+
/** What makes two header-form entries one recipient — the name in front of
|
|
454
|
+
the address makes no second one. For a list that holds each recipient
|
|
455
|
+
once. */
|
|
456
|
+
function addressKey(raw, rules = defaultAddressRules) {
|
|
457
|
+
return rules.identity(rules.parse(raw).address);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* A list of header-form entries as one header value — `"Müller, Hans"
|
|
461
|
+
* <h@x.de>, b@c.de` — for a backend or a template that keeps To, Cc and Bcc
|
|
462
|
+
* as text. The way back is the rule's own `split`: `rules.split(joined)` is
|
|
463
|
+
* the list again, entry for entry. A well-formed mailbox is written in its
|
|
464
|
+
* canonical form (a name with a comma quoted); anything else — a typo, a
|
|
465
|
+
* `{{placeholder}}` — goes in as it is, for the backend to resolve or refuse.
|
|
466
|
+
*
|
|
467
|
+
* ```ts
|
|
468
|
+
* to: joinAddresses(form.to().value()), // out to the backend
|
|
469
|
+
* form.to().value.set(splitAddresses(template.to)) // back in
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
function joinAddresses(list, rules = defaultAddressRules) {
|
|
473
|
+
return list
|
|
474
|
+
.map((entry) => entry.trim())
|
|
475
|
+
.filter(Boolean)
|
|
476
|
+
.map((entry) => (isMailbox(entry, rules) ? rules.format(rules.parse(entry)) : entry))
|
|
477
|
+
.join(', ');
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/*
|
|
481
|
+
* Public API Surface of @h-k-dev/angular-email-editor/address
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Generated bundle index. Do not edit.
|
|
486
|
+
*/
|
|
487
|
+
|
|
488
|
+
export { ADDRESS_RULES, addressIdentity, addressKey, decodeEncodedWords, defaultAddressRules, formatMailbox, isAddressPlaceholder, isEmailAddress, isMailbox, isPending, joinAddresses, parseMailbox, provideAddressRules, separatesAt, splitAddresses };
|
|
489
|
+
//# sourceMappingURL=h-k-dev-angular-email-editor-address.mjs.map
|