@selectwin/kit 0.1.255 → 0.1.257

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.
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import { KeyboardEvent, ReactNode, Ref, SyntheticEvent } from 'react';
2
2
  import { attachmentExt } from './internal/fileKind';
3
3
  export interface SelectMailAddress {
4
4
  name: string | null;
@@ -241,7 +241,7 @@ export declare function SelectMailComposerInput({ value, onChange, placeholder,
241
241
  maxLength?: number;
242
242
  }): import("react").JSX.Element;
243
243
  /** O corpo: texto, sem moldura, que cresce até um teto e rola. */
244
- export declare function SelectMailComposerBody({ value, onChange, placeholder, rows, 'aria-label': ariaLabel, maxLength, onEnter, id, }: {
244
+ export declare function SelectMailComposerBody({ value, onChange, placeholder, rows, 'aria-label': ariaLabel, maxLength, onEnter, id, textareaRef, onKeyDown, onSelect, fieldProps, }: {
245
245
  value: string;
246
246
  onChange: (value: string) => void;
247
247
  placeholder?: string;
@@ -254,6 +254,21 @@ export declare function SelectMailComposerBody({ value, onChange, placeholder, r
254
254
  */
255
255
  onEnter?: () => void;
256
256
  id?: string;
257
+ /** 0.1.257: a caixa de texto, para quem precisa do cursor (a lista do "/" e da "@", o `SelectTriggerMenu`). */
258
+ textareaRef?: Ref<HTMLTextAreaElement>;
259
+ /**
260
+ * 0.1.257: as teclas de quem usa, ANTES do Enter de enviar: a tecla em que ele chama `preventDefault` é dele (com a
261
+ * lista aberta, o Enter escolhe a opção e não envia).
262
+ */
263
+ onKeyDown?: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
264
+ /** 0.1.257: o cursor mudou de lugar (o clique, as setas): quem acompanha o gatilho relê. */
265
+ onSelect?: (event: SyntheticEvent<HTMLTextAreaElement>) => void;
266
+ /** 0.1.257: as props da caixa que abre uma lista (`selectTriggerFieldProps`). */
267
+ fieldProps?: {
268
+ 'aria-autocomplete'?: 'list';
269
+ 'aria-controls'?: string;
270
+ 'aria-activedescendant'?: string;
271
+ };
257
272
  }): import("react").JSX.Element;
258
273
  /** O clipe do rodapé (0.1.149): abre o seletor de arquivos do sistema. Escolher o mesmo arquivo de novo também vale. */
259
274
  export declare function SelectMailAttachButton({ onFiles, accept, multiple, disabled, label, }: {
@@ -583,19 +583,22 @@ function K({ value: e, onChange: t, placeholder: n, "aria-label": r, maxLength:
583
583
  maxLength: i
584
584
  });
585
585
  }
586
- function q({ value: e, onChange: t, placeholder: n, rows: r = 6, "aria-label": i, maxLength: a, onEnter: o, id: s }) {
587
- let c = h().inbox;
586
+ function q({ value: e, onChange: t, placeholder: n, rows: r = 6, "aria-label": i, maxLength: a, onEnter: o, id: s, textareaRef: c, onKeyDown: l, onSelect: u, fieldProps: d }) {
587
+ let f = h().inbox;
588
588
  return /* @__PURE__ */ w("textarea", {
589
+ ...d,
590
+ ref: c,
589
591
  id: s,
590
592
  className: "select-mailcomposer__body",
591
593
  value: e,
592
594
  onChange: (e) => t(e.target.value),
593
- onKeyDown: o ? (e) => {
594
- e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && (e.preventDefault(), o());
595
- } : void 0,
595
+ onKeyDown: (e) => {
596
+ l == null || l(e), !e.defaultPrevented && o && e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && (e.preventDefault(), o());
597
+ },
598
+ onSelect: u,
596
599
  placeholder: n,
597
600
  rows: r,
598
- "aria-label": i ?? c.message,
601
+ "aria-label": i ?? f.message,
599
602
  maxLength: a
600
603
  });
601
604
  }
@@ -0,0 +1,19 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
2
+ export type SelectScrollAxis = 'y' | 'x' | 'both';
3
+ /** As tags de bloco que a área pode ser. */
4
+ export type SelectScrollAreaElement = 'div' | 'section' | 'article' | 'aside' | 'nav' | 'main' | 'header' | 'footer' | 'ul' | 'ol' | 'dl' | 'pre';
5
+ type SelectScrollAreaOwnProps = {
6
+ /** O eixo que rola (padrão `y`). */
7
+ axis?: SelectScrollAxis;
8
+ /** Rola sem a barra à vista (a tira que corre de lado). */
9
+ hideBar?: boolean;
10
+ /** O nome da área para o leitor de tela: com ele, ela vira `role="region"` e entra no Tab (`tabIndex={0}`). */
11
+ label?: string;
12
+ /** A tag (padrão `div`). */
13
+ as?: SelectScrollAreaElement;
14
+ };
15
+ export type SelectScrollAreaProps = SelectScrollAreaOwnProps & Omit<ComponentPropsWithoutRef<'div'>, keyof SelectScrollAreaOwnProps>;
16
+ /** As classes da área: a `.select-scroll` com o eixo e, sem a barra, o `--nobar`. */
17
+ export declare function selectScrollClass(axis?: SelectScrollAxis, hideBar?: boolean): string;
18
+ export declare const SelectScrollArea: import('react').ForwardRefExoticComponent<SelectScrollAreaOwnProps & Omit<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, keyof SelectScrollAreaOwnProps> & import('react').RefAttributes<HTMLDivElement>>;
19
+ export {};
@@ -0,0 +1,23 @@
1
+ import { forwardRef as e } from "react";
2
+ import { jsx as t } from "react/jsx-runtime";
3
+ //#region src/SelectScrollArea.tsx
4
+ function n(e = "y", t = !1) {
5
+ return `select-scroll select-scroll--${e}${t ? " select-scroll--nobar" : ""}`;
6
+ }
7
+ var r = e(function({ axis: e = "y", hideBar: r = !1, label: i, as: a = "div", className: o, children: s, ...c }, l) {
8
+ return /* @__PURE__ */ t(a, {
9
+ ref: l,
10
+ ...i ? {
11
+ role: "region",
12
+ "aria-label": i,
13
+ tabIndex: 0
14
+ } : null,
15
+ ...c,
16
+ className: `${n(e, r)}${o ? ` ${o}` : ""}`,
17
+ children: s
18
+ });
19
+ });
20
+ //#endregion
21
+ export { r as SelectScrollArea, n as selectScrollClass };
22
+
23
+ //# sourceMappingURL=SelectScrollArea.js.map
@@ -0,0 +1,77 @@
1
+ import { KeyboardEvent, ReactNode } from 'react';
2
+ export interface SelectTriggerMenuOption {
3
+ id: string;
4
+ /** O atalho ("/estorno") ou o nome ("Ricardo Santos"). */
5
+ label: ReactNode;
6
+ /** O texto da resposta, ou o detalhe da pessoa ("Comercial · Disponível"). */
7
+ description?: ReactNode;
8
+ /** De quem é ("Minha", "Da equipe"), na pílula do fim. */
9
+ tag?: ReactNode;
10
+ /** O que vem antes do nome (o avatar da pessoa). */
11
+ leading?: ReactNode;
12
+ }
13
+ export interface SelectTriggerMenuProps {
14
+ /** O id da lista (a caixa de texto aponta para ele). */
15
+ id: string;
16
+ /** O título ("Respostas prontas · o “/” abre"). */
17
+ title: ReactNode;
18
+ /** O nome da lista para o leitor de tela (padrão: o título, quando ele é texto). */
19
+ 'aria-label'?: string;
20
+ options: readonly SelectTriggerMenuOption[];
21
+ /** A opção acesa (a do teclado: o `active` do `useSelectTriggerMenu`). */
22
+ active: number;
23
+ /** O mouse em cima de uma opção a acende. */
24
+ onActiveChange?: (index: number) => void;
25
+ /** Escolheu a opção (o clique, ou Enter e Tab pelo `useSelectTriggerMenu`). */
26
+ onPick: (index: number) => void;
27
+ /** O atalho em fonte de código, numa coluna (as respostas prontas); sem ele, o nome em texto (as pessoas). */
28
+ code?: boolean;
29
+ /** Buscando: "Buscando…" no lugar das opções. */
30
+ loading?: boolean;
31
+ /** Nada achado (padrão: "Nada encontrado"). */
32
+ empty?: ReactNode;
33
+ /** A dica do teclado (padrão: "↑ ↓ escolhe · Enter insere · Esc fecha"). */
34
+ hint?: ReactNode;
35
+ }
36
+ /** O id de cada opção (o `aria-activedescendant` da caixa aponta para a acesa). */
37
+ export declare const selectTriggerOptionId: (listId: string, index: number) => string;
38
+ export declare function SelectTriggerMenu({ id, title, 'aria-label': ariaLabel, options, active, onActiveChange, onPick, code, loading, empty, hint, }: SelectTriggerMenuProps): import("react").JSX.Element;
39
+ /**
40
+ * As props da caixa de texto que abre a lista: aponta para ela, diz que ela completa, e qual opção está acesa (o leitor
41
+ * de tela lê a opção sem o foco sair da caixa).
42
+ */
43
+ export declare function selectTriggerFieldProps(listId: string, open: boolean, active: number, count: number): {
44
+ 'aria-autocomplete': "list";
45
+ 'aria-controls': string | undefined;
46
+ 'aria-activedescendant': string | undefined;
47
+ };
48
+ /**
49
+ * O teclado da lista, na caixa de texto: chame o `onKeyDown` dele antes do da caixa — quando ele devolve `true`, a tecla
50
+ * foi da lista (e o envio pelo Enter não acontece). A opção acesa volta para a primeira quando a lista abre ou muda.
51
+ */
52
+ export declare function useSelectTriggerMenu({ open, count, onPick, onClose, }: {
53
+ open: boolean;
54
+ count: number;
55
+ onPick: (index: number) => void;
56
+ onClose: () => void;
57
+ }): {
58
+ active: number;
59
+ setActive: import('react').Dispatch<import('react').SetStateAction<number>>;
60
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => boolean;
61
+ };
62
+ /** O gatilho no cursor: qual ("/" ou "@"), o que veio depois dele até o cursor, e onde ele começa no texto. */
63
+ export interface SelectTrigger {
64
+ trigger: string;
65
+ query: string;
66
+ start: number;
67
+ }
68
+ /**
69
+ * Acha o gatilho no cursor: a palavra em que o cursor está (do último espaço até ele) começa por um dos `triggers`. Só no
70
+ * começo da palavra — "http://x" e "joao@exemplo.com" não abrem a lista. Sem gatilho, `null`.
71
+ */
72
+ export declare function selectTriggerAt(text: string, caret: number, triggers: readonly string[]): SelectTrigger | null;
73
+ /** Troca o gatilho e a busca (de `start` até o cursor) pelo que foi escolhido; o cursor fica logo depois. */
74
+ export declare function selectReplaceTrigger(text: string, start: number, caret: number, insert: string): {
75
+ text: string;
76
+ caret: number;
77
+ };
@@ -0,0 +1,98 @@
1
+ import { useSelectMessages as e } from "./SelectLocale.js";
2
+ import { useEffect as t, useState as n } from "react";
3
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
4
+ //#region src/SelectTriggerMenu.tsx
5
+ var a = (...e) => e.filter(Boolean).join(" "), o = (e, t) => `${e}-opt-${t}`;
6
+ function s({ id: t, title: n, "aria-label": s, options: c, active: l, onActiveChange: u, onPick: d, code: f = !1, loading: p = !1, empty: m, hint: h }) {
7
+ let g = e().chat, _ = s ?? (typeof n == "string" ? n : void 0), v = !p && c.length > 0;
8
+ return /* @__PURE__ */ i("div", {
9
+ className: "select-trigger-menu",
10
+ children: [
11
+ /* @__PURE__ */ i("div", {
12
+ className: "select-trigger-menu__head",
13
+ children: [/* @__PURE__ */ r("span", {
14
+ className: "select-trigger-menu__title",
15
+ children: n
16
+ }), /* @__PURE__ */ r("span", {
17
+ className: "select-trigger-menu__hint",
18
+ children: h ?? g.triggerHint
19
+ })]
20
+ }),
21
+ /* @__PURE__ */ r("div", {
22
+ className: "select-trigger-menu__list",
23
+ role: "listbox",
24
+ id: t,
25
+ "aria-label": _,
26
+ children: v ? c.map((e, n) => /* @__PURE__ */ i("div", {
27
+ id: o(t, n),
28
+ role: "option",
29
+ "aria-selected": n === l,
30
+ className: a("select-trigger-menu__option", f && "select-trigger-menu__option--code", n === l && "is-active"),
31
+ onMouseDown: (e) => e.preventDefault(),
32
+ onMouseEnter: () => u == null ? void 0 : u(n),
33
+ onClick: () => d(n),
34
+ children: [
35
+ e.leading ? /* @__PURE__ */ r("span", {
36
+ className: "select-trigger-menu__leading",
37
+ children: e.leading
38
+ }) : null,
39
+ /* @__PURE__ */ r("span", {
40
+ className: "select-trigger-menu__label",
41
+ children: e.label
42
+ }),
43
+ e.description ? /* @__PURE__ */ r("span", {
44
+ className: "select-trigger-menu__desc",
45
+ children: e.description
46
+ }) : null,
47
+ e.tag ? /* @__PURE__ */ r("span", {
48
+ className: "select-trigger-menu__tag",
49
+ children: e.tag
50
+ }) : null
51
+ ]
52
+ }, e.id)) : null
53
+ }),
54
+ v ? null : /* @__PURE__ */ r("div", {
55
+ className: "select-trigger-menu__note",
56
+ role: "status",
57
+ children: p ? g.triggerLoading : m ?? g.triggerEmpty
58
+ })
59
+ ]
60
+ });
61
+ }
62
+ function c(e, t, n, r) {
63
+ return {
64
+ "aria-autocomplete": "list",
65
+ "aria-controls": t ? e : void 0,
66
+ "aria-activedescendant": t && r > 0 ? o(e, Math.min(n, r - 1)) : void 0
67
+ };
68
+ }
69
+ function l({ open: e, count: r, onPick: i, onClose: a }) {
70
+ let [o, s] = n(0);
71
+ return t(() => {
72
+ s(0);
73
+ }, [e, r]), {
74
+ active: Math.min(o, Math.max(0, r - 1)),
75
+ setActive: s,
76
+ onKeyDown: (t) => e ? t.key === "ArrowDown" || t.key === "ArrowUp" ? (t.preventDefault(), r > 0 && s((e) => (e + (t.key === "ArrowDown" ? 1 : r - 1)) % r), !0) : (t.key === "Enter" || t.key === "Tab") && !t.shiftKey && r > 0 ? (t.preventDefault(), i(Math.min(o, r - 1)), !0) : t.key === "Escape" && (t.preventDefault(), a(), !0) : !1
77
+ };
78
+ }
79
+ function u(e, t, n) {
80
+ let r = Math.max(0, Math.min(t, e.length)), i = r;
81
+ for (; i > 0 && !/\s/.test(e[i - 1]);) --i;
82
+ let a = e.slice(i, r), o = n.find((e) => e.length > 0 && a.startsWith(e));
83
+ return o ? {
84
+ trigger: o,
85
+ query: a.slice(o.length),
86
+ start: i
87
+ } : null;
88
+ }
89
+ function d(e, t, n, r) {
90
+ return {
91
+ text: e.slice(0, t) + r + e.slice(n),
92
+ caret: t + r.length
93
+ };
94
+ }
95
+ //#endregion
96
+ export { s as SelectTriggerMenu, d as selectReplaceTrigger, u as selectTriggerAt, c as selectTriggerFieldProps, o as selectTriggerOptionId, l as useSelectTriggerMenu };
97
+
98
+ //# sourceMappingURL=SelectTriggerMenu.js.map
package/dist/index.d.ts CHANGED
@@ -55,6 +55,8 @@ export { SelectPasswordStrength, passwordScore, type SelectPasswordRule } from '
55
55
  export { SelectLoader, type SelectLoaderProps } from './SelectLoader';
56
56
  export { SelectText } from './SelectText';
57
57
  export { SelectBox, SelectStack, SelectInline, SelectGrid } from './SelectLayout';
58
+ export { SelectScrollArea } from './SelectScrollArea';
59
+ export type { SelectScrollAreaProps, SelectScrollAreaElement, SelectScrollAxis } from './SelectScrollArea';
58
60
  export { SelectPage, SelectPageBackProvider, SelectPageHeader } from './SelectPage';
59
61
  export { SelectFormLayout } from './SelectFormLayout';
60
62
  export { SelectSkeleton } from './SelectSkeleton';
@@ -105,6 +107,10 @@ export type { SelectHtmlFrameProps } from './SelectHtmlFrame';
105
107
  export { SelectInbox, SelectInboxToolbar, SelectInboxEmpty, SelectInboxBanner, SelectMailboxStatus, SelectMailList, SelectMailListGroup, SelectMailListItem, SelectMailListSkeleton, SelectMailListNote, SelectMailReader, SelectMailMessage, SelectMailNotice, SelectMailAttachment, SelectLeadChip, SelectMailComposer, SelectMailComposerRow, SelectMailComposerInput, SelectMailComposerBody, SelectMailComposerFooter, SelectMailComposerAttachments, SelectMailAttachButton, SelectMailUpload, SelectRecipientInput, SelectTemplateMenu, attachmentExt, isMailAddress, mailName, } from './SelectMail';
106
108
  export { SelectConversation, SelectConversationBubble, SelectConversationDay, SelectConversationEvent, SelectConversationMedia, SelectConversationNewer, SelectUnreadDivider, } from './SelectConversation';
107
109
  export type { SelectConversationBubbleProps } from './SelectConversation';
110
+ export { SelectConversationNote, SelectMention, SelectMentionText, SelectNoteDot, SelectNoteField, selectMentionParts, } from './SelectConversationNote';
111
+ export type { SelectConversationNoteProps, SelectNoteFieldProps } from './SelectConversationNote';
112
+ export { SelectTriggerMenu, selectReplaceTrigger, selectTriggerAt, selectTriggerFieldProps, selectTriggerOptionId, useSelectTriggerMenu, } from './SelectTriggerMenu';
113
+ export type { SelectTrigger, SelectTriggerMenuOption, SelectTriggerMenuProps } from './SelectTriggerMenu';
108
114
  export { SelectMessageTicks } from './SelectMessageTicks';
109
115
  export type { SelectMessageStatus, SelectMessageTicksProps } from './SelectMessageTicks';
110
116
  export { SelectConversationQuote } from './SelectConversationQuote';