@selectwin/kit 0.1.257 → 0.1.258

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 { ComponentPropsWithoutRef, ReactNode } from 'react';
1
+ import { ComponentPropsWithoutRef, FocusEvent, KeyboardEvent, PointerEvent, ReactNode } from 'react';
2
2
  type SelectSortableItemOwnProps = {
3
3
  /** O item que está sendo arrastado: sobe por cima dos outros, com sombra. */
4
4
  dragging?: boolean;
@@ -25,4 +25,50 @@ export declare const SelectDragHandle: import('react').ForwardRefExoticComponent
25
25
  export declare function SelectDragPreview({ children }: {
26
26
  children?: ReactNode;
27
27
  }): import("react").JSX.Element;
28
+ /** 0.1.258: a lista com o item de `from` no lugar `to` (a conta do arrasto e a de quem grava). PURA. */
29
+ export declare function selectSortableOrder<T>(items: readonly T[], from: number, to: number): T[];
30
+ export interface SelectSortableOptions {
31
+ /** Os ids na ordem de agora. */
32
+ ids: readonly string[];
33
+ /** O item de `from` vai para `to` (a tela grava; `selectSortableOrder` faz a conta). */
34
+ onMove: (from: number, to: number) => void;
35
+ /** O nome do item, para a alça e o leitor de tela ("Nome"). Padrão: "item 2". */
36
+ getLabel?: (id: string, index: number) => string;
37
+ /** O eixo da lista: `y` (o padrão, as setas para cima e para baixo) ou `x` (para os lados). */
38
+ axis?: 'y' | 'x';
39
+ /** Nada se move (o só para ler). */
40
+ disabled?: boolean;
41
+ }
42
+ /** O que o `handle(id)` devolve: as props do `SelectDragHandle`. */
43
+ export interface SelectSortableHandleProps {
44
+ ref: (el: HTMLButtonElement | null) => void;
45
+ label: string;
46
+ dragging: boolean;
47
+ disabled?: boolean;
48
+ 'aria-describedby': string;
49
+ 'aria-pressed': boolean;
50
+ onPointerDown: (event: PointerEvent<HTMLButtonElement>) => void;
51
+ onPointerMove: (event: PointerEvent<HTMLButtonElement>) => void;
52
+ onPointerUp: (event: PointerEvent<HTMLButtonElement>) => void;
53
+ onPointerCancel: (event: PointerEvent<HTMLButtonElement>) => void;
54
+ onKeyDown: (event: KeyboardEvent<HTMLButtonElement>) => void;
55
+ onBlur: (event: FocusEvent<HTMLButtonElement>) => void;
56
+ }
57
+ /** O que o `item(id)` devolve: as props do `SelectSortableItem`. */
58
+ export interface SelectSortableItemBinding {
59
+ ref: (el: HTMLDivElement | null) => void;
60
+ dragging: boolean;
61
+ }
62
+ export interface SelectSortable {
63
+ /** Os ids na ordem da prévia (com o item no lugar novo enquanto se move): desenhe nesta ordem. */
64
+ order: string[];
65
+ /** O id do item que se move agora, ou `null`. */
66
+ active: string | null;
67
+ item: (id: string) => SelectSortableItemBinding;
68
+ handle: (id: string) => SelectSortableHandleProps;
69
+ /** As instruções e a região que fala: desenhe uma vez, perto da lista. */
70
+ live: ReactNode;
71
+ }
72
+ /** 0.1.258: a lista que se ordena pelo ponteiro (o mouse e o dedo) e pelo teclado, com os avisos ao leitor de tela. */
73
+ export declare function useSelectSortable({ ids, onMove, getLabel, axis, disabled }: SelectSortableOptions): SelectSortable;
28
74
  export {};
@@ -1,31 +1,150 @@
1
1
  import { GripIcon as e } from "./icons.js";
2
- import { forwardRef as t } from "react";
3
- import { jsx as n, jsxs as r } from "react/jsx-runtime";
2
+ import { useSelectMessages as t } from "./SelectLocale.js";
3
+ import { forwardRef as n, useId as r, useLayoutEffect as i, useRef as a, useState as o } from "react";
4
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
4
5
  //#region src/SelectSortable.tsx
5
- var i = t(function({ dragging: e = !1, ghost: t = !1, className: r, ...i }, a) {
6
- return /* @__PURE__ */ n("div", {
7
- ref: a,
8
- ...i,
9
- className: `select-sortitem${e && !t ? " is-dragging" : ""}${t ? " is-ghost" : ""}${r ? " " + r : ""}`
6
+ var u = n(function({ dragging: e = !1, ghost: t = !1, className: n, ...r }, i) {
7
+ return /* @__PURE__ */ c("div", {
8
+ ref: i,
9
+ ...r,
10
+ className: `select-sortitem${e && !t ? " is-dragging" : ""}${t ? " is-ghost" : ""}${n ? " " + n : ""}`
10
11
  });
11
- }), a = t(function({ dragging: t = !1, variant: r = "inline", label: i = "Arrastar para reordenar", className: a, ...o }, s) {
12
- return /* @__PURE__ */ n("button", {
13
- ref: s,
12
+ }), d = n(function({ dragging: t = !1, variant: n = "inline", label: r = "Arrastar para reordenar", className: i, ...a }, o) {
13
+ return /* @__PURE__ */ c("button", {
14
+ ref: o,
14
15
  type: "button",
15
- "aria-label": i,
16
- title: i,
17
- ...o,
18
- className: `select-draghandle${r === "floating" ? " select-draghandle--floating" : ""}${t ? " is-dragging" : ""}${a ? " " + a : ""}`,
19
- children: /* @__PURE__ */ n(e, {})
16
+ "aria-label": r,
17
+ title: r,
18
+ ...a,
19
+ className: `select-draghandle${n === "floating" ? " select-draghandle--floating" : ""}${t ? " is-dragging" : ""}${i ? " " + i : ""}`,
20
+ children: /* @__PURE__ */ c(e, {})
20
21
  });
21
22
  });
22
- function o({ children: t }) {
23
- return /* @__PURE__ */ r("span", {
23
+ function f({ children: t }) {
24
+ return /* @__PURE__ */ l("span", {
24
25
  className: "select-dragpreview",
25
- children: [/* @__PURE__ */ n(e, {}), t]
26
+ children: [/* @__PURE__ */ c(e, {}), t]
26
27
  });
27
28
  }
29
+ function p(e, t, n) {
30
+ let r = e.slice();
31
+ if (t === n || t < 0 || t >= r.length) return r;
32
+ let [i] = r.splice(t, 1);
33
+ return r.splice(Math.max(0, Math.min(n, r.length)), 0, i), r;
34
+ }
35
+ function m({ ids: e, onMove: n, getLabel: u, axis: d = "y", disabled: f = !1 }) {
36
+ let m = t().sortable, h = r(), g = a(/* @__PURE__ */ new Map()), _ = a(/* @__PURE__ */ new Map()), v = a([]), y = a(null), [b, x] = o(null), [S, C] = o("");
37
+ i(() => {
38
+ let e = y.current;
39
+ if (!e) return;
40
+ y.current = null;
41
+ let t = _.current.get(e);
42
+ t && document.activeElement !== t && t.focus({ preventScroll: !0 });
43
+ });
44
+ let w = e.length, T = b ? e.indexOf(b.id) : -1, E = b && T >= 0 ? b : null, D = E ? p(e, T, E.to) : e.slice(), O = (t) => {
45
+ let n = e.indexOf(t);
46
+ return (u == null ? void 0 : u(t, n)) ?? m.item(n + 1);
47
+ }, k = (e) => {
48
+ if (!E) {
49
+ x(null);
50
+ return;
51
+ }
52
+ let t = O(E.id);
53
+ x(null), E.by === "keyboard" && (y.current = E.id), e && E.to !== T ? (n(T, E.to), C(m.dropped(t, E.to + 1, w))) : e ? E.by === "keyboard" && C(m.dropped(t, T + 1, w)) : C(m.canceled(t, T + 1));
54
+ };
55
+ return {
56
+ order: D,
57
+ active: (E == null ? void 0 : E.id) ?? null,
58
+ item: (e) => ({
59
+ ref: (t) => {
60
+ t ? g.current.set(e, t) : g.current.delete(e);
61
+ },
62
+ dragging: (E == null ? void 0 : E.id) === e
63
+ }),
64
+ handle: (t) => {
65
+ let n = e.indexOf(t), r = (E == null ? void 0 : E.id) === t, i = r && (E == null ? void 0 : E.by) === "keyboard";
66
+ return {
67
+ ref: (e) => {
68
+ e ? _.current.set(t, e) : _.current.delete(t);
69
+ },
70
+ label: m.handle(O(t)),
71
+ dragging: r,
72
+ ...f ? { disabled: !0 } : {},
73
+ "aria-describedby": h,
74
+ "aria-pressed": i,
75
+ onPointerDown: (r) => {
76
+ if (!(f || r.button !== 0 || E)) {
77
+ try {
78
+ var i, a;
79
+ (i = (a = r.currentTarget).setPointerCapture) == null || i.call(a, r.pointerId);
80
+ } catch {}
81
+ v.current = e.map((e) => {
82
+ var t;
83
+ let n = (t = g.current.get(e)) == null ? void 0 : t.getBoundingClientRect();
84
+ return n ? d === "y" ? n.top + n.height / 2 : n.left + n.width / 2 : 0;
85
+ }), x({
86
+ id: t,
87
+ to: n,
88
+ by: "pointer"
89
+ });
90
+ }
91
+ },
92
+ onPointerMove: (e) => {
93
+ if (!r || (E == null ? void 0 : E.by) !== "pointer") return;
94
+ let t = d === "y" ? e.clientY : e.clientX, n = v.current.filter((e, n) => n !== T && e < t).length;
95
+ n !== E.to && x({
96
+ ...E,
97
+ to: n
98
+ });
99
+ },
100
+ onPointerUp: () => {
101
+ r && (E == null ? void 0 : E.by) === "pointer" && k(!0);
102
+ },
103
+ onPointerCancel: () => {
104
+ r && (E == null ? void 0 : E.by) === "pointer" && k(!1);
105
+ },
106
+ onKeyDown: (e) => {
107
+ if (f) return;
108
+ if (e.key === " " || e.key === "Enter") {
109
+ e.preventDefault(), i ? k(!0) : E || (x({
110
+ id: t,
111
+ to: n,
112
+ by: "keyboard"
113
+ }), C(m.grabbed(O(t), n + 1, w)));
114
+ return;
115
+ }
116
+ if (!i || !E) return;
117
+ if (e.key === "Escape") {
118
+ e.preventDefault(), k(!1);
119
+ return;
120
+ }
121
+ let r = d === "y" ? e.key === "ArrowUp" : e.key === "ArrowLeft", a = d === "y" ? e.key === "ArrowDown" : e.key === "ArrowRight";
122
+ if (!r && !a) return;
123
+ e.preventDefault();
124
+ let o = Math.max(0, Math.min(w - 1, E.to + (a ? 1 : -1)));
125
+ o !== E.to && (y.current = t, x({
126
+ ...E,
127
+ to: o
128
+ }), C(m.moved(O(t), o + 1, w)));
129
+ },
130
+ onBlur: () => {
131
+ i && y.current !== t && k(!1);
132
+ }
133
+ };
134
+ },
135
+ live: /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("span", {
136
+ id: h,
137
+ className: "select-visually-hidden",
138
+ children: m.instructions
139
+ }), /* @__PURE__ */ c("span", {
140
+ className: "select-visually-hidden",
141
+ "aria-live": "assertive",
142
+ "aria-atomic": "true",
143
+ children: S
144
+ })] })
145
+ };
146
+ }
28
147
  //#endregion
29
- export { a as SelectDragHandle, o as SelectDragPreview, i as SelectSortableItem };
148
+ export { d as SelectDragHandle, f as SelectDragPreview, u as SelectSortableItem, p as selectSortableOrder, m as useSelectSortable };
30
149
 
31
150
  //# sourceMappingURL=SelectSortable.js.map
@@ -4,11 +4,14 @@ export type SelectStepState = 'done' | 'current' | 'error' | 'pending';
4
4
  /**
5
5
  * Um passo: só o rótulo, ou rótulo + descrição (a descrição só aparece na vertical) + o
6
6
  * `state`, que vence o que sai do `current` (antes = feito, ele = atual, depois = pendente).
7
+ * 0.1.258: `locked` (o cadeado: a etapa automática) e `lockedLabel` (o que o leitor de tela ouve; padrão "automática").
7
8
  */
8
9
  export type SelectStepItem = string | {
9
10
  label: string;
10
11
  description?: string;
11
12
  state?: SelectStepState;
13
+ locked?: boolean;
14
+ lockedLabel?: string;
12
15
  };
13
16
  type SelectStepsOwnProps = {
14
17
  steps: SelectStepItem[];
@@ -1,62 +1,73 @@
1
- import { CheckIcon as e } from "./icons.js";
2
- import { useSelectMessages as t } from "./SelectLocale.js";
3
- import { forwardRef as n } from "react";
4
- import { Fragment as r, jsx as i, jsxs as a } from "react/jsx-runtime";
1
+ import { CheckIcon as e, LockIcon as t } from "./icons.js";
2
+ import { useSelectMessages as n } from "./SelectLocale.js";
3
+ import { forwardRef as r } from "react";
4
+ import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
5
5
  //#region src/SelectSteps.tsx
6
- var o = n(function({ steps: n, current: o, onSelect: s, orientation: c = "horizontal", connected: l = !1, className: u, ...d }, f) {
7
- let p = t(), m = c === "vertical";
8
- return /* @__PURE__ */ i("ol", {
9
- ref: f,
10
- ...d,
11
- className: `select-steps${m ? " select-steps--vertical" : ""}${l && !m ? " select-steps--connected" : ""}${u ? " " + u : ""}`,
12
- children: n.map((t, n) => {
13
- let c = typeof t == "string" ? { label: t } : t, l = c.state ?? (n < o ? "done" : n === o ? "current" : "pending"), u = !!s && n !== o && (l === "done" || l === "error"), d = /* @__PURE__ */ a(r, { children: [/* @__PURE__ */ i("span", {
6
+ var s = r(function({ steps: r, current: s, onSelect: c, orientation: l = "horizontal", connected: u = !1, className: d, ...f }, p) {
7
+ let m = n(), h = l === "vertical";
8
+ return /* @__PURE__ */ a("ol", {
9
+ ref: p,
10
+ ...f,
11
+ className: `select-steps${h ? " select-steps--vertical" : ""}${u && !h ? " select-steps--connected" : ""}${d ? " " + d : ""}`,
12
+ children: r.map((n, r) => {
13
+ let l = typeof n == "string" ? { label: n } : n, u = l.state ?? (r < s ? "done" : r === s ? "current" : "pending"), d = !!c && r !== s && (u === "done" || u === "error"), f = /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ o("span", {
14
14
  className: "select-steps__num",
15
15
  "aria-hidden": "true",
16
- children: l === "done" ? /* @__PURE__ */ i(e, {}) : l === "error" ? "!" : n + 1
17
- }), /* @__PURE__ */ a("span", {
16
+ children: [u === "done" ? /* @__PURE__ */ a(e, {}) : u === "error" ? "!" : r + 1, l.locked ? /* @__PURE__ */ a("span", {
17
+ className: "select-steps__lock",
18
+ children: /* @__PURE__ */ a(t, {})
19
+ }) : null]
20
+ }), /* @__PURE__ */ o("span", {
18
21
  className: "select-steps__text",
19
22
  children: [
20
- /* @__PURE__ */ i("span", {
23
+ /* @__PURE__ */ a("span", {
21
24
  className: "select-steps__label",
22
- children: c.label
25
+ children: l.label
23
26
  }),
24
- l === "error" && /* @__PURE__ */ a("span", {
27
+ l.locked && /* @__PURE__ */ o("span", {
25
28
  className: "select-steps__sr",
26
29
  children: [
27
30
  "(",
28
- p.common.needsAttention,
31
+ l.lockedLabel ?? m.lock.label,
29
32
  ")"
30
33
  ]
31
34
  }),
32
- l === "done" && /* @__PURE__ */ a("span", {
35
+ u === "error" && /* @__PURE__ */ o("span", {
33
36
  className: "select-steps__sr",
34
37
  children: [
35
38
  "(",
36
- p.common.done,
39
+ m.common.needsAttention,
37
40
  ")"
38
41
  ]
39
42
  }),
40
- m && c.description && /* @__PURE__ */ i("span", {
43
+ u === "done" && /* @__PURE__ */ o("span", {
44
+ className: "select-steps__sr",
45
+ children: [
46
+ "(",
47
+ m.common.done,
48
+ ")"
49
+ ]
50
+ }),
51
+ h && l.description && /* @__PURE__ */ a("span", {
41
52
  className: "select-steps__desc",
42
- children: c.description
53
+ children: l.description
43
54
  })
44
55
  ]
45
56
  })] });
46
- return /* @__PURE__ */ i("li", {
47
- className: `select-steps__step select-steps__step--${l === "pending" ? "todo" : l}`,
48
- "aria-current": l === "current" ? "step" : void 0,
49
- children: u ? /* @__PURE__ */ i("button", {
57
+ return /* @__PURE__ */ a("li", {
58
+ className: `select-steps__step select-steps__step--${u === "pending" ? "todo" : u}`,
59
+ "aria-current": u === "current" ? "step" : void 0,
60
+ children: d ? /* @__PURE__ */ a("button", {
50
61
  type: "button",
51
62
  className: "select-steps__btn",
52
- onClick: () => s(n),
53
- children: d
54
- }) : d
55
- }, n);
63
+ onClick: () => c(r),
64
+ children: f
65
+ }) : f
66
+ }, r);
56
67
  })
57
68
  });
58
69
  });
59
70
  //#endregion
60
- export { o as SelectSteps };
71
+ export { s as SelectSteps };
61
72
 
62
73
  //# sourceMappingURL=SelectSteps.js.map
@@ -8,6 +8,10 @@ export interface SelectTimelineItem {
8
8
  tone?: SelectTimelineTone;
9
9
  /** Selo ao lado do título. */
10
10
  badge?: ReactNode;
11
+ /** 0.1.258: o ícone do marcador (o tipo do evento), no lugar do ponto, no tom do evento. */
12
+ icon?: ReactNode;
13
+ /** 0.1.258: o tipo do evento para o leitor de tela, antes do título ("Ligação"). O ícone fica fora da leitura. */
14
+ iconLabel?: string;
11
15
  }
12
16
  type SelectTimelineOwnProps = {
13
17
  items: SelectTimelineItem[];
@@ -19,22 +19,26 @@ var r = {
19
19
  let f = {
20
20
  "--tl-final": r[e.length ? ((d = e[0]) == null ? void 0 : d.tone) ?? "default" : "default"],
21
21
  ...c
22
- }, p = a === "each", m = o === "start";
22
+ }, p = a === "each", m = o === "start", h = e.some((e) => e.icon != null && e.icon !== !1);
23
23
  return /* @__PURE__ */ t("ul", {
24
24
  ref: u,
25
25
  ...l,
26
- className: `select-timeline${p ? " select-timeline--each" : ""}${m ? " select-timeline--timestart" : ""}${s ? " " + s : ""}`,
26
+ className: `select-timeline${p ? " select-timeline--each" : ""}${m ? " select-timeline--timestart" : ""}${h ? " select-timeline--icons" : ""}${s ? " " + s : ""}`,
27
27
  style: f,
28
28
  children: e.map((e, r) => {
29
- let a = !p && r === 0, o = p ? { "--tl-dot": i[e.tone ?? "default"] } : void 0;
29
+ let a = !p && r === 0, o = p ? { "--tl-dot": i[e.tone ?? "default"] } : void 0, s = e.icon != null && e.icon !== !1;
30
30
  return /* @__PURE__ */ n("li", {
31
- className: "select-timeline__item",
31
+ className: `select-timeline__item${s ? " select-timeline__item--icon" : ""}`,
32
32
  children: [
33
33
  m && e.timestamp != null && /* @__PURE__ */ t("span", {
34
34
  className: "select-timeline__when",
35
35
  children: e.timestamp
36
36
  }),
37
- /* @__PURE__ */ t("span", {
37
+ s ? /* @__PURE__ */ t("span", {
38
+ className: `select-timeline__marker select-timeline__marker--${e.tone ?? "default"}`,
39
+ "aria-hidden": "true",
40
+ children: e.icon
41
+ }) : /* @__PURE__ */ t("span", {
38
42
  className: `select-timeline__dot${a ? " select-timeline__dot--final" : ""}${p ? " select-timeline__dot--toned" : ""}`,
39
43
  style: o,
40
44
  "aria-hidden": "true"
@@ -46,10 +50,17 @@ var r = {
46
50
  className: "select-timeline__head",
47
51
  children: [/* @__PURE__ */ n("span", {
48
52
  className: "select-timeline__title",
49
- children: [e.title, e.badge != null && /* @__PURE__ */ t("span", {
50
- className: "select-timeline__badge",
51
- children: e.badge
52
- })]
53
+ children: [
54
+ e.iconLabel ? /* @__PURE__ */ t("span", {
55
+ className: "select-visually-hidden",
56
+ children: `${e.iconLabel}: `
57
+ }) : null,
58
+ e.title,
59
+ e.badge != null && /* @__PURE__ */ t("span", {
60
+ className: "select-timeline__badge",
61
+ children: e.badge
62
+ })
63
+ ]
53
64
  }), !m && e.timestamp != null && /* @__PURE__ */ t("span", {
54
65
  className: "select-timeline__time",
55
66
  children: e.timestamp
package/dist/index.d.ts CHANGED
@@ -57,6 +57,13 @@ export { SelectText } from './SelectText';
57
57
  export { SelectBox, SelectStack, SelectInline, SelectGrid } from './SelectLayout';
58
58
  export { SelectScrollArea } from './SelectScrollArea';
59
59
  export type { SelectScrollAreaProps, SelectScrollAreaElement, SelectScrollAxis } from './SelectScrollArea';
60
+ export { SelectAvatarGroup } from './SelectAvatarGroup';
61
+ export type { SelectAvatarGroupProps, SelectAvatarGroupPerson } from './SelectAvatarGroup';
62
+ export { SelectFieldset } from './SelectFieldset';
63
+ export type { SelectFieldsetProps } from './SelectFieldset';
64
+ export type { SelectNavCount } from './internal/navCount';
65
+ export { useSelectSortable, selectSortableOrder } from './SelectSortable';
66
+ export type { SelectSortable, SelectSortableOptions, SelectSortableHandleProps, SelectSortableItemBinding } from './SelectSortable';
60
67
  export { SelectPage, SelectPageBackProvider, SelectPageHeader } from './SelectPage';
61
68
  export { SelectFormLayout } from './SelectFormLayout';
62
69
  export { SelectSkeleton } from './SelectSkeleton';