wimui 0.75.2 → 0.76.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/dist/components/_internal/OverlayBase.cjs +1 -1
- package/dist/components/_internal/OverlayBase.js +13 -23
- package/dist/components/_internal/escapeStack.cjs +2 -0
- package/dist/components/_internal/escapeStack.d.ts +4 -0
- package/dist/components/_internal/escapeStack.js +23 -0
- package/dist/components/data-display/Calendar/Calendar.cjs +1 -1
- package/dist/components/data-display/Calendar/Calendar.js +12 -0
- package/dist/components/data-display/Kanban/Kanban.cjs +1 -1
- package/dist/components/data-display/Kanban/Kanban.js +10 -0
- package/dist/components/form/Combobox/Combobox.cjs +1 -1
- package/dist/components/form/Combobox/Combobox.js +2 -1
- package/dist/components/form/DatePicker/DatePicker.cjs +1 -1
- package/dist/components/form/DatePicker/DatePicker.js +62 -64
- package/dist/components/form/RangeSlider/RangeSlider.cjs +1 -1
- package/dist/components/form/RangeSlider/RangeSlider.js +113 -111
- package/dist/components/form/Select/Select.cjs +1 -1
- package/dist/components/form/Select/Select.js +12 -0
- package/dist/components/form/Select/useSelect.cjs +1 -1
- package/dist/components/form/Select/useSelect.js +1 -0
- package/dist/components/form/Slider/Slider.cjs +1 -1
- package/dist/components/form/Slider/Slider.js +77 -75
- package/dist/components/form/TagInput/TagInput.cjs +1 -1
- package/dist/components/form/TagInput/TagInput.d.ts +1 -1
- package/dist/components/form/TagInput/TagInput.js +50 -46
- package/dist/components/overlay/Confirm/Confirm.cjs +2 -0
- package/dist/components/overlay/Confirm/Confirm.d.ts +60 -0
- package/dist/components/overlay/Confirm/Confirm.js +63 -0
- package/dist/components/overlay/Dropdown/Dropdown.cjs +1 -1
- package/dist/components/overlay/Dropdown/Dropdown.js +120 -121
- package/dist/i18n/generated/common.cjs +1 -1
- package/dist/i18n/generated/common.d.ts +1 -1
- package/dist/i18n/generated/common.js +3 -0
- package/dist/i18n/generated/components.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +33 -32
- package/dist/llms/Alert.md +2 -0
- package/dist/llms/Calendar.md +4 -0
- package/dist/llms/ColorPicker.md +2 -0
- package/dist/llms/Confirm.md +13 -0
- package/dist/llms/Drawer.md +1 -1
- package/dist/llms/Dropdown.md +1 -1
- package/dist/llms/FieldTemplate.md +2 -0
- package/dist/llms/HamburgerMenu.md +1 -1
- package/dist/llms/Kanban.md +4 -0
- package/dist/llms/MultiSelect.md +2 -0
- package/dist/llms/OverflowList.md +2 -0
- package/dist/llms/Popover.md +2 -0
- package/dist/llms/Progress.md +2 -0
- package/dist/llms/Rating.md +1 -1
- package/dist/llms/SearchInput.md +1 -1
- package/dist/llms/Select.md +4 -0
- package/dist/llms/Sidebar.md +1 -1
- package/dist/llms/Tabs.md +2 -0
- package/dist/llms/Tag.md +2 -0
- package/dist/llms/Toast.md +1 -1
- package/dist/llms/Tour.md +2 -0
- package/dist/llms/TreeView.md +1 -1
- package/dist/llms-full.txt +29 -19
- package/dist/llms.txt +21 -19
- package/dist/locales/en/common.json +1 -0
- package/dist/locales/en/components.json +2 -1
- package/dist/locales/ja/common.json +1 -0
- package/dist/locales/ja/components.json +2 -1
- package/dist/locales/pt/common.json +1 -0
- package/dist/locales/pt/components.json +2 -1
- package/dist/overlay.cjs +1 -1
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.js +2 -1
- package/dist/utilities/slider-utils.cjs +1 -1
- package/dist/utilities/slider-utils.d.ts +5 -0
- package/dist/utilities/slider-utils.js +2 -2
- package/dist/wimui.umd.js +5 -5
- package/package.json +13 -6
|
@@ -2,106 +2,108 @@
|
|
|
2
2
|
import { Root as e, Slottable as t } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
3
|
import { composeEventHandlers as n } from "../../_internal/composeEventHandlers.js";
|
|
4
4
|
import { FieldTemplate as r } from "../FieldTemplate/FieldTemplate.js";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { forwardRef as
|
|
8
|
-
import
|
|
9
|
-
import { jsx as
|
|
5
|
+
import { largeStepOf as i, useSliderCommon as a } from "../../../utilities/slider-utils.js";
|
|
6
|
+
import o from "./slider.module.js";
|
|
7
|
+
import { forwardRef as s, useCallback as c, useEffect as l, useId as u, useRef as d, useState as f } from "react";
|
|
8
|
+
import p from "classnames";
|
|
9
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
10
10
|
//#region src/components/form/Slider/Slider.tsx
|
|
11
|
-
var
|
|
12
|
-
let
|
|
11
|
+
var g = s(({ value: s, defaultValue: g = 0, min: _ = 0, max: v = 100, step: y = 1, disabled: b = !1, onChange: x, onAfterChange: S, className: C, name: w, label: T, error: E, required: ee, layout: te = "vertical", id: ne, "aria-label": re, "aria-labelledby": D, "aria-describedby": O, asChild: k = !1, styles: A, children: j, ...M }, N) => {
|
|
12
|
+
let P = s !== void 0, [F, I] = f(g), L = P ? s : F, R = d(null), z = d(null), B = d(null), V = d(null), H = d(!1), U = d(L), ie = u(), W = ne || ie, G = `wim-slider-label-${W}`, K = `wim-slider-error-${W}`, { calculateValue: q } = a(_, v, y), J = c((e) => (e - _) / (v - _) * 100, [_, v]), Y = c((e) => {
|
|
13
13
|
let t = J(e);
|
|
14
|
-
|
|
14
|
+
B.current && (B.current.style.width = `${t}%`), z.current && (z.current.style.left = `${t}%`, z.current.setAttribute("aria-valuenow", String(e))), V.current && (V.current.value = String(e));
|
|
15
15
|
}, [J]);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}, [
|
|
16
|
+
l(() => {
|
|
17
|
+
H.current || Y(L);
|
|
18
|
+
}, [L, Y]);
|
|
19
19
|
let X = (e) => {
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n = q(t,
|
|
23
|
-
|
|
24
|
-
}, Z =
|
|
25
|
-
if (!
|
|
26
|
-
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n = q(t,
|
|
27
|
-
|
|
20
|
+
if (b) return;
|
|
21
|
+
H.current = !0;
|
|
22
|
+
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n = q(t, R.current);
|
|
23
|
+
U.current = n, Y(n), x?.(n), e.preventDefault();
|
|
24
|
+
}, Z = c((e) => {
|
|
25
|
+
if (!H.current || b) return;
|
|
26
|
+
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n = q(t, R.current);
|
|
27
|
+
U.current = n, Y(n), x?.(n);
|
|
28
28
|
}, [
|
|
29
|
-
y,
|
|
30
|
-
q,
|
|
31
29
|
b,
|
|
30
|
+
q,
|
|
31
|
+
x,
|
|
32
32
|
Y
|
|
33
|
-
]), Q =
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
let e =
|
|
37
|
-
|
|
33
|
+
]), Q = c(() => {
|
|
34
|
+
if (H.current) {
|
|
35
|
+
H.current = !1;
|
|
36
|
+
let e = U.current;
|
|
37
|
+
P || I(e), S?.(e);
|
|
38
38
|
}
|
|
39
|
-
}, [
|
|
40
|
-
|
|
39
|
+
}, [P, S]);
|
|
40
|
+
l(() => (document.addEventListener("mousemove", Z), document.addEventListener("mouseup", Q), document.addEventListener("touchmove", Z, { passive: !1 }), document.addEventListener("touchend", Q), () => {
|
|
41
41
|
document.removeEventListener("mousemove", Z), document.removeEventListener("mouseup", Q), document.removeEventListener("touchmove", Z), document.removeEventListener("touchend", Q);
|
|
42
42
|
}), [Z, Q]);
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
43
|
+
let ae = (e) => {
|
|
44
|
+
if (b) return;
|
|
45
45
|
let t;
|
|
46
|
-
if (e.key === "ArrowLeft" || e.key === "ArrowDown") t = Math.max(
|
|
47
|
-
else if (e.key === "ArrowRight" || e.key === "ArrowUp") t = Math.min(
|
|
48
|
-
else if (e.key === "
|
|
49
|
-
else if (e.key === "
|
|
46
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowDown") t = Math.max(_, L - y);
|
|
47
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowUp") t = Math.min(v, L + y);
|
|
48
|
+
else if (e.key === "PageDown") t = Math.max(_, L - i(_, v, y));
|
|
49
|
+
else if (e.key === "PageUp") t = Math.min(v, L + i(_, v, y));
|
|
50
|
+
else if (e.key === "Home") t = _;
|
|
51
|
+
else if (e.key === "End") t = v;
|
|
50
52
|
else return;
|
|
51
|
-
|
|
52
|
-
}, $ = J(
|
|
53
|
-
return /* @__PURE__ */
|
|
54
|
-
label:
|
|
55
|
-
error:
|
|
56
|
-
required:
|
|
57
|
-
layout:
|
|
53
|
+
P || I(t), x?.(t), e.preventDefault();
|
|
54
|
+
}, $ = J(L);
|
|
55
|
+
return /* @__PURE__ */ m(r, {
|
|
56
|
+
label: T,
|
|
57
|
+
error: E,
|
|
58
|
+
required: ee,
|
|
59
|
+
layout: te,
|
|
58
60
|
labelId: G,
|
|
59
61
|
errorId: K,
|
|
60
|
-
className:
|
|
61
|
-
styles:
|
|
62
|
-
children: /* @__PURE__ */
|
|
62
|
+
className: C,
|
|
63
|
+
styles: A,
|
|
64
|
+
children: /* @__PURE__ */ h(k ? e : "div", {
|
|
63
65
|
role: "presentation",
|
|
64
|
-
className:
|
|
65
|
-
ref:
|
|
66
|
-
...
|
|
67
|
-
onMouseDown: n(
|
|
68
|
-
onTouchStart: n(
|
|
66
|
+
className: p("wim-slider", o.root, b && o.disabled, E && o.danger),
|
|
67
|
+
ref: N,
|
|
68
|
+
...M,
|
|
69
|
+
onMouseDown: n(M.onMouseDown, X),
|
|
70
|
+
onTouchStart: n(M.onTouchStart, X),
|
|
69
71
|
children: [
|
|
70
|
-
/* @__PURE__ */
|
|
71
|
-
className:
|
|
72
|
-
ref:
|
|
73
|
-
children: [/* @__PURE__ */
|
|
74
|
-
ref:
|
|
75
|
-
className:
|
|
72
|
+
/* @__PURE__ */ h("div", {
|
|
73
|
+
className: o.trackContainer,
|
|
74
|
+
ref: R,
|
|
75
|
+
children: [/* @__PURE__ */ m("div", {
|
|
76
|
+
ref: B,
|
|
77
|
+
className: o.track,
|
|
76
78
|
style: { width: `${$}%` }
|
|
77
|
-
}), /* @__PURE__ */
|
|
78
|
-
ref:
|
|
79
|
-
className:
|
|
79
|
+
}), /* @__PURE__ */ m("div", {
|
|
80
|
+
ref: z,
|
|
81
|
+
className: o.thumb,
|
|
80
82
|
style: { left: `${$}%` },
|
|
81
83
|
role: "slider",
|
|
82
|
-
"aria-valuemin":
|
|
83
|
-
"aria-valuemax":
|
|
84
|
-
"aria-valuenow":
|
|
85
|
-
"aria-disabled":
|
|
86
|
-
"aria-labelledby":
|
|
87
|
-
"aria-label":
|
|
88
|
-
"aria-describedby": [
|
|
89
|
-
"aria-invalid":
|
|
90
|
-
tabIndex:
|
|
91
|
-
onKeyDown:
|
|
84
|
+
"aria-valuemin": _,
|
|
85
|
+
"aria-valuemax": v,
|
|
86
|
+
"aria-valuenow": L,
|
|
87
|
+
"aria-disabled": b,
|
|
88
|
+
"aria-labelledby": T ? G : D,
|
|
89
|
+
"aria-label": T ? void 0 : re,
|
|
90
|
+
"aria-describedby": [O, E ? K : void 0].filter(Boolean).join(" ") || void 0,
|
|
91
|
+
"aria-invalid": E ? !0 : void 0,
|
|
92
|
+
tabIndex: b ? -1 : 0,
|
|
93
|
+
onKeyDown: ae
|
|
92
94
|
})]
|
|
93
95
|
}),
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
ref:
|
|
96
|
+
/* @__PURE__ */ m("input", {
|
|
97
|
+
ref: V,
|
|
96
98
|
type: "hidden",
|
|
97
|
-
name:
|
|
98
|
-
value:
|
|
99
|
+
name: w,
|
|
100
|
+
value: L
|
|
99
101
|
}),
|
|
100
|
-
|
|
102
|
+
k ? /* @__PURE__ */ m(t, { children: j }) : null
|
|
101
103
|
]
|
|
102
104
|
})
|
|
103
105
|
});
|
|
104
106
|
});
|
|
105
|
-
|
|
107
|
+
g.displayName = "Slider";
|
|
106
108
|
//#endregion
|
|
107
|
-
export {
|
|
109
|
+
export { g as Slider, g as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../InputBase/InputBase.cjs"),r=require("../../../i18n/generated/form.cjs"),i=require("../FieldTemplate/FieldTemplate.cjs"),a=require("../../data-display/Tag/Tag.cjs"),o=require("./tag-input.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=s.default.forwardRef(({value:e,defaultValue:
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../InputBase/InputBase.cjs"),r=require("../../../i18n/generated/form.cjs"),i=require("../FieldTemplate/FieldTemplate.cjs"),a=require("../../data-display/Tag/Tag.cjs"),o=require("./tag-input.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=/[,\r\n\t]/,d=s.default.forwardRef(({value:e,defaultValue:d=[],onChange:f,placeholder:p,disabled:m=!1,intent:h=`default`,variant:g=`outline`,fullWidth:_=!1,width:v,label:y,error:b,required:x,layout:S,allowDelete:C=!0,maxTags:w,className:T,id:E,"aria-label":D,"aria-labelledby":O,"aria-describedby":k,...A},j)=>{let[M,N]=(0,s.useState)(d),[P,F]=(0,s.useState)(``),I=(0,s.useRef)(null),L=e!==void 0,R=L?e:M,z=p,B=e=>{F(e.target.value)},V=e=>{let t=[...R],n=[];for(let r of e.split(u)){let e=r.trim();e&&!t.includes(e)&&(w&&t.length>=w?n.push(e):t.push(e))}F(n.join(`, `)),t.length!==R.length&&(L||N(t),f?.(t))},H=e=>{let t=e.clipboardData.getData(`text`);if(!u.test(t))return;e.preventDefault();let n=e.currentTarget,r=n.selectionStart??P.length,i=n.selectionEnd??P.length;V(P.slice(0,r)+t+P.slice(i))},U=e=>{if(m||!C)return;let t=R.filter(t=>t!==e);L||N(t),f?.(t)},W=e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),V(P)):e.key===`Backspace`&&P===``&&R.length>0&&U(R[R.length-1])},G=()=>{I.current?.focus()},{t:K}=t.useWimTranslation(r.formNs),q=(0,s.useId)(),J=E||`wim-tag-input-${q}`,Y=b?`${J}-error`:void 0,X=y?`${J}-label`:void 0,Z=b?`danger`:h;return(0,l.jsx)(i.FieldTemplate,{...A,ref:j,label:y,error:b,required:x,layout:S,labelId:X,htmlFor:J,errorId:Y,className:(0,c.default)(`wim-tag-input`,T),children:(0,l.jsx)(n.InputBase,{intent:Z,variant:g,fullWidth:_,width:v,disabled:m,className:o.default.inputBase,styles:{inner:o.default.inputBaseInner},children:(0,l.jsx)(`div`,{className:(0,c.default)(o.default.container,{[o.default.disabled]:m}),onClick:G,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&G()},role:`presentation`,children:(0,l.jsxs)(`div`,{className:o.default.tagList,children:[R.map(e=>(0,l.jsx)(a.Tag,{variant:`solid`,intent:`neutral`,size:`sm`,disabled:m,onDelete:C&&!m?()=>U(e):void 0,className:o.default.tag,children:e},e)),(0,l.jsx)(`input`,{id:J,ref:I,type:`text`,value:P,onChange:B,onKeyDown:W,onPaste:H,disabled:m,placeholder:R.length===0?z:``,className:o.default.input,"aria-invalid":Z===`danger`,"aria-describedby":[k,Y].filter(Boolean).join(` `)||void 0,"aria-labelledby":y?X:O,"aria-label":y||O?void 0:D??K(`tag_input.input_label`),"aria-required":x})]})})})})});d.displayName=`TagInput`,exports.TagInput=d;
|
|
@@ -34,6 +34,6 @@ export interface TagInputProps extends Omit<React.ComponentPropsWithoutRef<"div"
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Input component for managing free-form tags.
|
|
37
|
-
* Tags are committed with the Enter key or a comma.
|
|
37
|
+
* Tags are committed with the Enter key or a comma. Pasted text is split on commas, line breaks and tabs.
|
|
38
38
|
*/
|
|
39
39
|
export declare const TagInput: React.ForwardRefExoticComponent<TagInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -9,52 +9,55 @@ import o, { useId as s, useRef as c, useState as l } from "react";
|
|
|
9
9
|
import u from "classnames";
|
|
10
10
|
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
11
11
|
//#region src/components/form/TagInput/TagInput.tsx
|
|
12
|
-
var p = o.forwardRef(({ value: o, defaultValue:
|
|
13
|
-
let [P, F] = l(
|
|
12
|
+
var p = /[,\r\n\t]/, m = o.forwardRef(({ value: o, defaultValue: m = [], onChange: h, placeholder: g, disabled: _ = !1, intent: v = "default", variant: y = "outline", fullWidth: b = !1, width: x, label: S, error: C, required: w, layout: T, allowDelete: E = !0, maxTags: D, className: O, id: k, "aria-label": A, "aria-labelledby": j, "aria-describedby": M, ...N }, ee) => {
|
|
13
|
+
let [P, F] = l(m), [I, L] = l(""), R = c(null), z = o !== void 0, B = z ? o : P, V = g, H = (e) => {
|
|
14
14
|
L(e.target.value);
|
|
15
15
|
}, U = (e) => {
|
|
16
|
-
let t =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return;
|
|
16
|
+
let t = [...B], n = [];
|
|
17
|
+
for (let r of e.split(p)) {
|
|
18
|
+
let e = r.trim();
|
|
19
|
+
e && !t.includes(e) && (D && t.length >= D ? n.push(e) : t.push(e));
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
let n = [...B, t];
|
|
24
|
-
z || F(n), m?.(n), L("");
|
|
21
|
+
L(n.join(", ")), t.length !== B.length && (z || F(t), h?.(t));
|
|
25
22
|
}, W = (e) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
let t = e.clipboardData.getData("text");
|
|
24
|
+
if (!p.test(t)) return;
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
let n = e.currentTarget, r = n.selectionStart ?? I.length, i = n.selectionEnd ?? I.length;
|
|
27
|
+
U(I.slice(0, r) + t + I.slice(i));
|
|
29
28
|
}, G = (e) => {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (_ || !E) return;
|
|
30
|
+
let t = B.filter((t) => t !== e);
|
|
31
|
+
z || F(t), h?.(t);
|
|
32
|
+
}, K = (e) => {
|
|
33
|
+
e.key === "Enter" || e.key === "," ? (e.preventDefault(), U(I)) : e.key === "Backspace" && I === "" && B.length > 0 && G(B[B.length - 1]);
|
|
34
|
+
}, q = () => {
|
|
32
35
|
R.current?.focus();
|
|
33
|
-
}, { t:
|
|
36
|
+
}, { t: J } = e(n), Y = s(), X = k || `wim-tag-input-${Y}`, Z = C ? `${X}-error` : void 0, Q = S ? `${X}-label` : void 0, $ = C ? "danger" : v;
|
|
34
37
|
return /* @__PURE__ */ d(r, {
|
|
35
|
-
...
|
|
36
|
-
ref:
|
|
37
|
-
label:
|
|
38
|
-
error:
|
|
39
|
-
required:
|
|
40
|
-
layout:
|
|
41
|
-
labelId:
|
|
42
|
-
htmlFor:
|
|
43
|
-
errorId:
|
|
44
|
-
className: u("wim-tag-input",
|
|
38
|
+
...N,
|
|
39
|
+
ref: ee,
|
|
40
|
+
label: S,
|
|
41
|
+
error: C,
|
|
42
|
+
required: w,
|
|
43
|
+
layout: T,
|
|
44
|
+
labelId: Q,
|
|
45
|
+
htmlFor: X,
|
|
46
|
+
errorId: Z,
|
|
47
|
+
className: u("wim-tag-input", O),
|
|
45
48
|
children: /* @__PURE__ */ d(t, {
|
|
46
|
-
intent:
|
|
47
|
-
variant:
|
|
48
|
-
fullWidth:
|
|
49
|
-
width:
|
|
50
|
-
disabled:
|
|
49
|
+
intent: $,
|
|
50
|
+
variant: y,
|
|
51
|
+
fullWidth: b,
|
|
52
|
+
width: x,
|
|
53
|
+
disabled: _,
|
|
51
54
|
className: a.inputBase,
|
|
52
55
|
styles: { inner: a.inputBaseInner },
|
|
53
56
|
children: /* @__PURE__ */ d("div", {
|
|
54
|
-
className: u(a.container, { [a.disabled]:
|
|
55
|
-
onClick:
|
|
57
|
+
className: u(a.container, { [a.disabled]: _ }),
|
|
58
|
+
onClick: q,
|
|
56
59
|
onKeyDown: (e) => {
|
|
57
|
-
(e.key === "Enter" || e.key === " ") &&
|
|
60
|
+
(e.key === "Enter" || e.key === " ") && q();
|
|
58
61
|
},
|
|
59
62
|
role: "presentation",
|
|
60
63
|
children: /* @__PURE__ */ f("div", {
|
|
@@ -63,31 +66,32 @@ var p = o.forwardRef(({ value: o, defaultValue: p = [], onChange: m, placeholder
|
|
|
63
66
|
variant: "solid",
|
|
64
67
|
intent: "neutral",
|
|
65
68
|
size: "sm",
|
|
66
|
-
disabled:
|
|
67
|
-
onDelete:
|
|
69
|
+
disabled: _,
|
|
70
|
+
onDelete: E && !_ ? () => G(e) : void 0,
|
|
68
71
|
className: a.tag,
|
|
69
72
|
children: e
|
|
70
73
|
}, e)), /* @__PURE__ */ d("input", {
|
|
71
|
-
id:
|
|
74
|
+
id: X,
|
|
72
75
|
ref: R,
|
|
73
76
|
type: "text",
|
|
74
77
|
value: I,
|
|
75
78
|
onChange: H,
|
|
76
|
-
onKeyDown:
|
|
77
|
-
|
|
79
|
+
onKeyDown: K,
|
|
80
|
+
onPaste: W,
|
|
81
|
+
disabled: _,
|
|
78
82
|
placeholder: B.length === 0 ? V : "",
|
|
79
83
|
className: a.input,
|
|
80
|
-
"aria-invalid":
|
|
81
|
-
"aria-describedby": [
|
|
82
|
-
"aria-labelledby":
|
|
83
|
-
"aria-label":
|
|
84
|
-
"aria-required":
|
|
84
|
+
"aria-invalid": $ === "danger",
|
|
85
|
+
"aria-describedby": [M, Z].filter(Boolean).join(" ") || void 0,
|
|
86
|
+
"aria-labelledby": S ? Q : j,
|
|
87
|
+
"aria-label": S || j ? void 0 : A ?? J("tag_input.input_label"),
|
|
88
|
+
"aria-required": w
|
|
85
89
|
})]
|
|
86
90
|
})
|
|
87
91
|
})
|
|
88
92
|
})
|
|
89
93
|
});
|
|
90
94
|
});
|
|
91
|
-
|
|
95
|
+
m.displayName = "TagInput";
|
|
92
96
|
//#endregion
|
|
93
|
-
export {
|
|
97
|
+
export { m as TagInput };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../i18n/generated/common.cjs"),r=require("../../form/Button/Button.cjs"),i=require("../Dialog/Dialog.cjs");let a=require("react");a=e.__toESM(a,1);let o=require("react/jsx-runtime");var s=(0,a.createContext)(void 0),c=({children:e})=>{let{t:c}=t.useWimTranslation(n.commonNs),[l,u]=(0,a.useState)(null),[d,f]=(0,a.useState)(!1),p=(0,a.useRef)([]),m=(0,a.useRef)(0),h=(0,a.useRef)(null),g=(0,a.useCallback)(e=>new Promise(t=>{let n={id:m.current++,options:e,resolve:t};p.current.push(n),p.current.length===1&&(h.current=document.activeElement,u(n),f(!0))}),[]),_=(0,a.useCallback)(e=>{p.current.shift()?.resolve(e);let t=p.current[0];t?u(t):f(!1)},[]);(0,a.useEffect)(()=>{if(d)return;let e=h.current,t=document.activeElement;e?.isConnected&&(!t||t===document.body||t.closest(`.wim-confirm`))&&e.focus()},[d]),(0,a.useEffect)(()=>()=>{p.current.splice(0).forEach(e=>e.resolve(!1))},[]);let v=l?.options,y=v?.intent===`danger`;return(0,o.jsxs)(s.Provider,{value:g,children:[e,l&&v&&(0,o.jsx)(i.Dialog,{open:d,onOpenChange:e=>{e||_(!1)},role:`alertdialog`,children:(0,o.jsxs)(i.DialogContent,{className:`wim-confirm`,children:[(0,o.jsxs)(i.DialogHeader,{children:[(0,o.jsx)(i.DialogTitle,{children:v.title}),v.description&&(0,o.jsx)(i.DialogDescription,{children:v.description})]}),(0,o.jsxs)(i.DialogFooter,{children:[(0,o.jsx)(r.Button,{variant:`outline`,onClick:()=>_(!1),"data-autofocus":y?``:void 0,children:v.cancelLabel??c(`action.cancel`)}),(0,o.jsx)(r.Button,{variant:`solid`,intent:v.intent??`default`,onClick:()=>_(!0),"data-autofocus":y?void 0:``,children:v.confirmLabel??c(`action.ok`)})]})]})},l.id)]})};c.displayName=`ConfirmProvider`;var l=()=>{let e=(0,a.useContext)(s);if(!e)throw Error(`useConfirm must be used within a ConfirmProvider`);return e};exports.ConfirmProvider=c,exports.useConfirm=l;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ButtonIntent } from '../../../types/tokens.js';
|
|
3
|
+
export interface ConfirmOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The question the dialog asks. Phrase it as the action, e.g. "Delete this file?".
|
|
6
|
+
*/
|
|
7
|
+
title: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* What happens if the user confirms, e.g. that it cannot be undone.
|
|
10
|
+
*/
|
|
11
|
+
description?: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Label of the confirm button. Name the action ("Delete") rather than leaving the generic default.
|
|
14
|
+
* @default "OK" (localized)
|
|
15
|
+
*/
|
|
16
|
+
confirmLabel?: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Label of the cancel button.
|
|
19
|
+
* @default "Cancel" (localized)
|
|
20
|
+
*/
|
|
21
|
+
cancelLabel?: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Color role of the confirm button. With "danger", the cancel button takes the initial focus,
|
|
24
|
+
* so pressing Enter right after the dialog opens does not run the destructive action.
|
|
25
|
+
* @default "default"
|
|
26
|
+
*/
|
|
27
|
+
intent?: ButtonIntent;
|
|
28
|
+
}
|
|
29
|
+
/** Opens a confirmation dialog and resolves to true when confirmed, false when cancelled or dismissed. */
|
|
30
|
+
export type ConfirmFunction = (options: ConfirmOptions) => Promise<boolean>;
|
|
31
|
+
export interface ConfirmProviderProps {
|
|
32
|
+
/**
|
|
33
|
+
* The part of the app that can call `useConfirm`. Place it once near the root, inside `WimProvider`.
|
|
34
|
+
*/
|
|
35
|
+
children: React.ReactNode;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Renders the confirmation dialog that `useConfirm` opens. Calls made while a dialog is open
|
|
39
|
+
* wait in order and open one after another.
|
|
40
|
+
*/
|
|
41
|
+
export declare const ConfirmProvider: {
|
|
42
|
+
({ children }: ConfirmProviderProps): React.JSX.Element;
|
|
43
|
+
displayName: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Ask the user to confirm an action and wait for the answer, from anywhere under `ConfirmProvider`.
|
|
47
|
+
* Resolves to true when the user confirms, and to false when they cancel, press Escape, or the
|
|
48
|
+
* provider unmounts. Use it before an action the user cannot easily undo; for an action that can be
|
|
49
|
+
* undone, run it and offer Undo in a `Snackbar` instead.
|
|
50
|
+
*
|
|
51
|
+
* Throws when called outside `ConfirmProvider`.
|
|
52
|
+
*
|
|
53
|
+
* @returns `confirm(options)` — `{ title, description?, confirmLabel?, cancelLabel?, intent? }` — which returns `Promise<boolean>`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const confirm = useConfirm();
|
|
57
|
+
* const ok = await confirm({ title: "Delete this file?", confirmLabel: "Delete", intent: "danger" });
|
|
58
|
+
* if (ok) await deleteFile(id);
|
|
59
|
+
*/
|
|
60
|
+
export declare const useConfirm: () => ConfirmFunction;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
|
|
3
|
+
import { commonNs as t } from "../../../i18n/generated/common.js";
|
|
4
|
+
import { Button as n } from "../../form/Button/Button.js";
|
|
5
|
+
import { Dialog as r, DialogContent as i, DialogDescription as a, DialogFooter as o, DialogHeader as s, DialogTitle as c } from "../Dialog/Dialog.js";
|
|
6
|
+
import { createContext as l, useCallback as u, useContext as d, useEffect as f, useRef as p, useState as m } from "react";
|
|
7
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
8
|
+
//#region src/components/overlay/Confirm/Confirm.tsx
|
|
9
|
+
var _ = l(void 0), v = ({ children: l }) => {
|
|
10
|
+
let { t: d } = e(t), [v, y] = m(null), [b, x] = m(!1), S = p([]), C = p(0), w = p(null), T = u((e) => new Promise((t) => {
|
|
11
|
+
let n = {
|
|
12
|
+
id: C.current++,
|
|
13
|
+
options: e,
|
|
14
|
+
resolve: t
|
|
15
|
+
};
|
|
16
|
+
S.current.push(n), S.current.length === 1 && (w.current = document.activeElement, y(n), x(!0));
|
|
17
|
+
}), []), E = u((e) => {
|
|
18
|
+
S.current.shift()?.resolve(e);
|
|
19
|
+
let t = S.current[0];
|
|
20
|
+
t ? y(t) : x(!1);
|
|
21
|
+
}, []);
|
|
22
|
+
f(() => {
|
|
23
|
+
if (b) return;
|
|
24
|
+
let e = w.current, t = document.activeElement;
|
|
25
|
+
e?.isConnected && (!t || t === document.body || t.closest(".wim-confirm")) && e.focus();
|
|
26
|
+
}, [b]), f(() => () => {
|
|
27
|
+
S.current.splice(0).forEach((e) => e.resolve(!1));
|
|
28
|
+
}, []);
|
|
29
|
+
let D = v?.options, O = D?.intent === "danger";
|
|
30
|
+
return /* @__PURE__ */ g(_.Provider, {
|
|
31
|
+
value: T,
|
|
32
|
+
children: [l, v && D && /* @__PURE__ */ h(r, {
|
|
33
|
+
open: b,
|
|
34
|
+
onOpenChange: (e) => {
|
|
35
|
+
e || E(!1);
|
|
36
|
+
},
|
|
37
|
+
role: "alertdialog",
|
|
38
|
+
children: /* @__PURE__ */ g(i, {
|
|
39
|
+
className: "wim-confirm",
|
|
40
|
+
children: [/* @__PURE__ */ g(s, { children: [/* @__PURE__ */ h(c, { children: D.title }), D.description && /* @__PURE__ */ h(a, { children: D.description })] }), /* @__PURE__ */ g(o, { children: [/* @__PURE__ */ h(n, {
|
|
41
|
+
variant: "outline",
|
|
42
|
+
onClick: () => E(!1),
|
|
43
|
+
"data-autofocus": O ? "" : void 0,
|
|
44
|
+
children: D.cancelLabel ?? d("action.cancel")
|
|
45
|
+
}), /* @__PURE__ */ h(n, {
|
|
46
|
+
variant: "solid",
|
|
47
|
+
intent: D.intent ?? "default",
|
|
48
|
+
onClick: () => E(!0),
|
|
49
|
+
"data-autofocus": O ? void 0 : "",
|
|
50
|
+
children: D.confirmLabel ?? d("action.ok")
|
|
51
|
+
})] })]
|
|
52
|
+
})
|
|
53
|
+
}, v.id)]
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
v.displayName = "ConfirmProvider";
|
|
57
|
+
var y = () => {
|
|
58
|
+
let e = d(_);
|
|
59
|
+
if (!e) throw Error("useConfirm must be used within a ConfirmProvider");
|
|
60
|
+
return e;
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { v as ConfirmProvider, y as useConfirm };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../layout/Transition/Transition.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../_internal/escapeStack.cjs"),r=require("../../layout/Transition/Transition.cjs"),i=require("../../_internal/BaseListItem/BaseListItem.cjs"),a=require("../../_internal/typeahead.cjs"),o=require("../../_internal/mergeRefs.cjs"),s=require("./dropdown.module.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("classnames");l=e.__toESM(l,1);let u=require("react/jsx-runtime"),d=require("@floating-ui/react");var f=c.default.createContext({isOpen:!1,toggle:()=>{},close:()=>{},menuId:``,triggerId:``,setTriggerIdOverride:()=>{},setMenuIdOverride:()=>{},focusedIndex:-1,setFocusedIndex:()=>{},registerItem:()=>0,containerRef:{current:null},setReference:()=>{},setFloating:()=>{},floatingStyles:{},floatingRef:{current:null},setAlign:()=>{}}),p=(0,c.forwardRef)(({children:e,className:r,asChild:i=!1,defaultOpen:p=!1,open:m,onOpenChange:h,...g},_)=>{let[v,y]=(0,c.useState)(p),b=m??v,x=(0,c.useCallback)(e=>{m===void 0&&y(e),h?.(e)},[m,h]),[S,C]=(0,c.useState)(-1),w=(0,c.useRef)(null),T=(0,c.useRef)(0),[E,D]=(0,c.useState)(`left`),{refs:O,floatingStyles:k}=(0,d.useFloating)({open:b,placement:E===`right`?`bottom-end`:`bottom-start`,whileElementsMounted:d.autoUpdate,middleware:[(0,d.offset)(4),(0,d.flip)(),(0,d.shift)({padding:8})]}),A=o.mergeRefs(w,_);(0,c.useEffect)(()=>{T.current=0});let j=()=>{let e=T.current;return T.current+=1,e},M=(0,c.useId)(),[N,P]=(0,c.useState)(void 0),[F,I]=(0,c.useState)(void 0),L=F??`wim-dropdown-menu-${M}`,R=N??`wim-dropdown-trigger-${M}`,z=()=>{let e=!b;x(e),C(e?0:-1)},B=(0,c.useCallback)(()=>{let e=O.floating.current,t=!!e&&e.contains(document.activeElement);x(!1),C(-1),t&&O.reference.current?.focus?.({preventScroll:!0})},[x,O.floating,O.reference]);(0,c.useEffect)(()=>{let e=e=>{let t=e.target,n=O.floating.current?.contains(t)??!1;w.current&&!w.current.contains(t)&&!n&&B()};return b&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[b,O.floating,B]),n.useEscapeLayer(b,B);let V=a.useTypeahead(),H=e=>{if(!b)return;let t=Array.from((O.floating.current??w.current)?.querySelectorAll(`[role="menuitem"]:not([aria-disabled="true"])`)||[]);if(a.isTypeaheadKey(e,V.typing())){let n=a.findTypeaheadIndex({query:V.push(e.key),current:S,count:t.length,getText:e=>t[e].textContent??``});n>=0&&(e.preventDefault(),C(n))}else switch(e.key){case`ArrowDown`:e.preventDefault(),C(e=>e<t.length-1?e+1:0);break;case`ArrowUp`:e.preventDefault(),C(e=>e>0?e-1:t.length-1);break;case`Home`:e.preventDefault(),C(0);break;case`End`:e.preventDefault(),C(t.length-1);break;case`Tab`:B()}};(0,c.useEffect)(()=>{b&&S>=0&&Array.from((O.floating.current??w.current)?.querySelectorAll(`[role="menuitem"]:not([aria-disabled="true"])`)||[])[S]?.focus({preventScroll:!0})},[S,b,O.floating]);let U=i?t.Root:`div`;return(0,u.jsx)(f.Provider,{value:{isOpen:b,toggle:z,close:B,menuId:L,triggerId:R,setTriggerIdOverride:P,setMenuIdOverride:I,focusedIndex:S,setFocusedIndex:C,registerItem:j,containerRef:w,setReference:O.setReference,setFloating:O.setFloating,floatingStyles:k,floatingRef:O.floating,setAlign:D},children:(0,u.jsx)(U,{...g,role:`none`,className:(0,l.default)(`wim-dropdown`,s.default.root,r),ref:A,onKeyDown:H,children:(0,u.jsx)(t.Slottable,{children:e})})})});p.displayName=`Dropdown`;var m=(0,c.forwardRef)(({children:e,className:n,asChild:r=!1,id:i,...a},d)=>{let{toggle:p,isOpen:m,menuId:h,triggerId:g,setTriggerIdOverride:_,setReference:v}=c.default.useContext(f);(0,c.useEffect)(()=>(_(i),()=>_(void 0)),[i,_]);let y=r?t.Root:`div`,b=o.mergeRefs(v,d);return(0,u.jsx)(y,{...a,ref:b,id:i??g,className:(0,l.default)(s.default.trigger,n),onClick:p,"aria-haspopup":`menu`,"aria-expanded":m,"aria-controls":m?h:void 0,role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `||e.key===`ArrowDown`&&!m)&&(e.preventDefault(),p())},children:(0,u.jsx)(t.Slottable,{children:e})})});m.displayName=`Dropdown.Trigger`;var h=(0,c.forwardRef)(({children:e,className:t,align:n=`left`,show:i,style:a,id:p,"aria-labelledby":m,...h},g)=>{let{isOpen:_,menuId:v,triggerId:y,setMenuIdOverride:b,setFloating:x,floatingStyles:S,setAlign:C}=c.default.useContext(f);(0,c.useEffect)(()=>(b(p),()=>b(void 0)),[p,b]),(0,c.useEffect)(()=>{C(n)},[n,C]);let w=o.mergeRefs(x,g);return(0,u.jsx)(d.FloatingPortal,{children:(0,u.jsx)(r.Transition,{...h,ref:w,show:i===void 0?_:i,preset:`fade`,id:p??v,style:{...S,...a},className:(0,l.default)(s.default.menu,t),role:`menu`,"aria-labelledby":m??y,children:e})})});h.displayName=`Dropdown.Menu`;var g=(0,c.forwardRef)(({children:e,onClick:t,disabled:n=!1,className:r,...a},o)=>{let{close:d,focusedIndex:p,setFocusedIndex:m,registerItem:h}=c.default.useContext(f),[g]=(0,c.useState)(()=>h()),_=p===g,v=e=>{n||(e.stopPropagation(),t&&t(),d())};return(0,u.jsx)(i.BaseListItem,{...a,ref:o,className:(0,l.default)(s.default.item,r),onClick:v,onFocus:()=>m(g),disabled:n,role:`menuitem`,tabIndex:_?0:-1,onKeyDown:e=>{!n&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),v(e))},children:e})});g.displayName=`Dropdown.Item`;var _=(0,c.forwardRef)((e,t)=>(0,u.jsx)(p,{...e,ref:t}));_.displayName=`Dropdown`,_.Trigger=m,_.Menu=h,_.Item=g,exports.Dropdown=_,exports.default=_,exports.DropdownItem=g,exports.DropdownMenu=h,exports.DropdownTrigger=m;
|