@stackone/malachite 2.87.0 → 2.88.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/COMPONENTS.md +2 -2
- package/dist/components/Accordion.js +206 -179
- package/dist/components/Accordion.js.map +1 -1
- package/dist/components/Button.js +118 -81
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Chat/ChatModelPicker.js +70 -67
- package/dist/components/Chat/ChatModelPicker.js.map +1 -1
- package/dist/components/FilterSearch.js +92 -91
- package/dist/components/FilterSearch.js.map +1 -1
- package/dist/components/MultiSelect.js +190 -189
- package/dist/components/MultiSelect.js.map +1 -1
- package/dist/components/PinnedCornerCap.js +32 -19
- package/dist/components/PinnedCornerCap.js.map +1 -1
- package/dist/components/QueryInput.js +95 -92
- package/dist/components/QueryInput.js.map +1 -1
- package/dist/components/SplitButton.js +62 -61
- package/dist/components/SplitButton.js.map +1 -1
- package/dist/components/Surface.js +98 -94
- package/dist/components/Surface.js.map +1 -1
- package/dist/components/Tooltip.js +93 -90
- package/dist/components/Tooltip.js.map +1 -1
- package/dist/components/WizardLayout.js +49 -46
- package/dist/components/WizardLayout.js.map +1 -1
- package/dist/components/activeElement.js +5 -1
- package/dist/components/activeElement.js.map +1 -1
- package/dist/components/useFollowTrigger.js +28 -0
- package/dist/components/useFollowTrigger.js.map +1 -0
- package/dist/index.d.ts +8 -6
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
|
@@ -1,111 +1,148 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { ButtonSpinner as
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { jsx as t, jsxs as m, Fragment as p } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Q, useRef as d, useMemo as X, useLayoutEffect as Y } from "react";
|
|
3
|
+
import { ButtonSpinner as Z } from "./ButtonSpinner.js";
|
|
4
|
+
import P from "./Tooltip.js";
|
|
5
|
+
import { getDeepActiveNode as _ } from "./activeElement.js";
|
|
6
|
+
import { getIconOnlySizeClasses as z, getIconSizeClass as ee } from "./buttonSizing.js";
|
|
7
|
+
import { getSizeClasses as te, getVariantClasses as re, getIconGapClass as H, getRadiusClass as se, getDefaultRadiusClass as ne } from "./buttonStyles.js";
|
|
8
|
+
import { composeRefs as le } from "./composeRefs.js";
|
|
9
|
+
import { resolveRel as ae } from "./linkRel.js";
|
|
10
|
+
const ce = "-mx-[calc(var(--btn-px)+1px)]", oe = "-mx-[var(--btn-px)]", ie = (l) => {
|
|
11
|
+
try {
|
|
12
|
+
return l.matches(":focus-visible");
|
|
13
|
+
} catch {
|
|
14
|
+
return !0;
|
|
15
|
+
}
|
|
16
|
+
}, fe = Q(
|
|
9
17
|
({
|
|
10
|
-
variant:
|
|
11
|
-
size:
|
|
12
|
-
radius:
|
|
13
|
-
loading:
|
|
14
|
-
disabled:
|
|
15
|
-
icon:
|
|
16
|
-
iconPosition:
|
|
17
|
-
leading:
|
|
18
|
-
contentAlign:
|
|
19
|
-
flexGrow:
|
|
20
|
-
width:
|
|
21
|
-
fill:
|
|
22
|
-
tooltip:
|
|
23
|
-
tooltipPlacement:
|
|
24
|
-
iconOnly:
|
|
25
|
-
flush:
|
|
18
|
+
variant: l,
|
|
19
|
+
size: r = "large",
|
|
20
|
+
radius: v,
|
|
21
|
+
loading: a = !1,
|
|
22
|
+
disabled: T = !1,
|
|
23
|
+
icon: c,
|
|
24
|
+
iconPosition: w = "start",
|
|
25
|
+
leading: y,
|
|
26
|
+
contentAlign: U = "center",
|
|
27
|
+
flexGrow: x = !1,
|
|
28
|
+
width: V = "auto",
|
|
29
|
+
fill: q = !1,
|
|
30
|
+
tooltip: g,
|
|
31
|
+
tooltipPlacement: G = "top",
|
|
32
|
+
iconOnly: b = !1,
|
|
33
|
+
flush: W = !1,
|
|
26
34
|
children: s,
|
|
27
|
-
className:
|
|
28
|
-
href:
|
|
29
|
-
target:
|
|
30
|
-
rel:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
className: J = "",
|
|
36
|
+
href: I,
|
|
37
|
+
target: j,
|
|
38
|
+
rel: K,
|
|
39
|
+
onBlur: h,
|
|
40
|
+
onFocus: C,
|
|
41
|
+
...k
|
|
42
|
+
}, A) => {
|
|
43
|
+
const R = d(null), L = X(
|
|
44
|
+
() => le(A, R),
|
|
45
|
+
[A]
|
|
46
|
+
), o = d(!1), N = d(!1), S = d(0);
|
|
47
|
+
Y(() => {
|
|
48
|
+
var u;
|
|
49
|
+
if (a) {
|
|
50
|
+
N.current = o.current;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!N.current)
|
|
54
|
+
return;
|
|
55
|
+
N.current = !1;
|
|
56
|
+
const e = _();
|
|
57
|
+
(!e || e === document.body) && ((u = R.current) == null || u.focus({ preventScroll: !0 }), _() === R.current && (o.current = !0));
|
|
58
|
+
}, [a]);
|
|
59
|
+
const B = (e) => {
|
|
60
|
+
S.current += 1, o.current = ie(e.currentTarget), C == null || C(e);
|
|
61
|
+
}, F = (e) => {
|
|
62
|
+
const u = S.current;
|
|
63
|
+
queueMicrotask(() => {
|
|
64
|
+
S.current === u && (o.current = !1);
|
|
65
|
+
}), h == null || h(e);
|
|
66
|
+
}, O = v ? se(v) : ne(r, b), n = T || a, M = U === "start", D = [
|
|
67
|
+
M ? "flex items-center justify-start text-left" : "flex items-center justify-center",
|
|
68
|
+
b ? `p-0 ${z(r)}` : te(r),
|
|
69
|
+
re(l, O),
|
|
70
|
+
x ? "w-full" : "",
|
|
71
|
+
V === "wide" ? "min-w-[120px]" : "",
|
|
72
|
+
q ? "max-w-full" : "",
|
|
40
73
|
n ? "cursor-not-allowed" : "",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
].filter(Boolean).join(" "),
|
|
74
|
+
g && n ? "pointer-events-none" : "",
|
|
75
|
+
W && !b ? l === "no-style" ? oe : ce : "",
|
|
76
|
+
J
|
|
77
|
+
].filter(Boolean).join(" "), i = M ? /* @__PURE__ */ t("span", { className: "flex min-w-0 flex-1 items-center", children: s }) : s, f = y ? /* @__PURE__ */ t(
|
|
45
78
|
"span",
|
|
46
79
|
{
|
|
47
80
|
className: s ? "btn-leading inline-flex shrink-0 items-center me-2" : "btn-leading inline-flex shrink-0 items-center",
|
|
48
|
-
children:
|
|
81
|
+
children: y
|
|
49
82
|
}
|
|
50
|
-
) : null,
|
|
51
|
-
if (
|
|
52
|
-
return /* @__PURE__ */
|
|
53
|
-
|
|
54
|
-
/* @__PURE__ */
|
|
55
|
-
|
|
83
|
+
) : null, E = () => {
|
|
84
|
+
if (a)
|
|
85
|
+
return /* @__PURE__ */ m(p, { children: [
|
|
86
|
+
f,
|
|
87
|
+
/* @__PURE__ */ t(Z, {}),
|
|
88
|
+
i
|
|
56
89
|
] });
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
/* @__PURE__ */
|
|
90
|
+
const e = `inline-flex items-center shrink-0 ${ee(r)}`;
|
|
91
|
+
return c && w === "start" ? /* @__PURE__ */ m(p, { children: [
|
|
92
|
+
f,
|
|
93
|
+
/* @__PURE__ */ t(
|
|
61
94
|
"span",
|
|
62
95
|
{
|
|
63
|
-
className: `${
|
|
64
|
-
children:
|
|
96
|
+
className: `${e}${s ? ` ${H(r, "start")}` : ""}`,
|
|
97
|
+
children: c
|
|
65
98
|
}
|
|
66
99
|
),
|
|
67
|
-
|
|
68
|
-
] }) :
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/* @__PURE__ */
|
|
100
|
+
i
|
|
101
|
+
] }) : c && w === "end" ? /* @__PURE__ */ m(p, { children: [
|
|
102
|
+
f,
|
|
103
|
+
i,
|
|
104
|
+
/* @__PURE__ */ t(
|
|
72
105
|
"span",
|
|
73
106
|
{
|
|
74
|
-
className: `${
|
|
75
|
-
children:
|
|
107
|
+
className: `${e}${s ? ` ${H(r, "end")}` : ""}`,
|
|
108
|
+
children: c
|
|
76
109
|
}
|
|
77
110
|
)
|
|
78
|
-
] }) : /* @__PURE__ */
|
|
79
|
-
|
|
80
|
-
|
|
111
|
+
] }) : /* @__PURE__ */ m(p, { children: [
|
|
112
|
+
f,
|
|
113
|
+
i
|
|
81
114
|
] });
|
|
82
|
-
},
|
|
115
|
+
}, $ = I && !n ? /* @__PURE__ */ t(
|
|
83
116
|
"a",
|
|
84
117
|
{
|
|
85
|
-
ref:
|
|
86
|
-
href:
|
|
87
|
-
target:
|
|
88
|
-
rel:
|
|
89
|
-
className:
|
|
90
|
-
|
|
91
|
-
|
|
118
|
+
ref: L,
|
|
119
|
+
href: I,
|
|
120
|
+
target: j,
|
|
121
|
+
rel: ae(K, j),
|
|
122
|
+
className: D,
|
|
123
|
+
onFocus: B,
|
|
124
|
+
onBlur: F,
|
|
125
|
+
...k,
|
|
126
|
+
children: E()
|
|
92
127
|
}
|
|
93
|
-
) : /* @__PURE__ */
|
|
128
|
+
) : /* @__PURE__ */ t(
|
|
94
129
|
"button",
|
|
95
130
|
{
|
|
96
|
-
ref:
|
|
131
|
+
ref: L,
|
|
97
132
|
disabled: n,
|
|
98
|
-
className:
|
|
99
|
-
|
|
100
|
-
|
|
133
|
+
className: D,
|
|
134
|
+
onFocus: B,
|
|
135
|
+
onBlur: F,
|
|
136
|
+
...k,
|
|
137
|
+
children: E()
|
|
101
138
|
}
|
|
102
139
|
);
|
|
103
|
-
return
|
|
140
|
+
return g ? /* @__PURE__ */ t(P, { text: g, placement: G, fill: x, children: n ? /* @__PURE__ */ t("span", { className: `inline-flex cursor-not-allowed${x ? " w-full" : ""}`, children: $ }) : $ }) : $;
|
|
104
141
|
}
|
|
105
142
|
);
|
|
106
|
-
|
|
143
|
+
fe.displayName = "Button";
|
|
107
144
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
145
|
+
fe as Button,
|
|
146
|
+
fe as default
|
|
110
147
|
};
|
|
111
148
|
//# sourceMappingURL=Button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../src/components/Button.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport ButtonSpinner from './ButtonSpinner';\nimport Tooltip from './Tooltip';\nimport { getIconOnlySizeClasses, getIconSizeClass } from './buttonSizing';\nimport {\n getDefaultRadiusClass,\n getIconGapClass,\n getRadiusClass,\n getSizeClasses,\n getVariantClasses,\n} from './buttonStyles';\nimport { resolveRel } from './linkRel';\n\n// Button variant types matching the old component\nexport type ButtonVariant =\n | 'filled'\n | 'outline'\n /**\n * `outline`'s geometry on a ground of its own. For a button sitting on a tinted or\n * patterned surface, where `outline`'s transparent background lets that surface through\n * and the control stops reading as a button.\n */\n | 'surface'\n /**\n * The violet the assistant is named in elsewhere — for a control that hands work to it, or\n * acts on what it produced. Provenance, not a severity: it says who is being asked, not\n * that anything is wrong.\n */\n | 'assistant'\n | 'destructive'\n | 'success'\n | 'warning'\n | 'error'\n | 'ghost'\n /** `ghost` until its `Surface.Row` is hovered or focused, or its menu opens. For `trailing` only. */\n | 'row-outline'\n /** Text only, in the accent colour, for a secondary action beside a primary one. */\n | 'quiet'\n /**\n * A recessed grey with secondary text, for a control whose subject is switched off, such as\n * an account set to Not allowed. It stays clickable: `disabled` is for a control that is not.\n */\n | 'muted'\n | 'no-style';\n\nexport type ButtonSize = 'xsmall' | 'small' | 'medium' | 'large';\n\nexport type ButtonRadius = 'md' | 'lg' | 'xl';\n\ninterface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n variant: ButtonVariant;\n size?: ButtonSize;\n radius?: ButtonRadius;\n loading?: boolean;\n disabled?: boolean;\n icon?: React.ReactNode;\n iconPosition?: 'start' | 'end';\n /** Before the label at its own size, never squeezed (an avatar); pairs with an end `icon`. */\n leading?: React.ReactNode;\n /** `start` aligns the label to the leading edge and pins an end `icon` to the far edge. */\n contentAlign?: 'center' | 'start';\n /** Fills the container's width. */\n flexGrow?: boolean;\n /** `wide` holds a 120px floor for a primary action. */\n width?: 'auto' | 'wide';\n fill?: boolean;\n tooltip?: string;\n tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';\n iconOnly?: boolean;\n /** Pulls a borderless button out by its own padding, so its label lines up with the text around it. */\n flush?: boolean;\n children?: React.ReactNode;\n onClick?: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement>;\n /** Renders the button as a real anchor, so a link action is never an <a> nested in a <button>. */\n href?: string;\n target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n}\n\n// The 1px is the transparent border, which `no-style` drops.\nconst FLUSH_MARGIN = '-mx-[calc(var(--btn-px)+1px)]';\nconst FLUSH_MARGIN_BORDERLESS = '-mx-[var(--btn-px)]';\n\nexport const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(\n (\n {\n variant,\n size = 'large',\n radius,\n loading = false,\n disabled = false,\n icon,\n iconPosition = 'start',\n leading,\n contentAlign = 'center',\n flexGrow = false,\n width = 'auto',\n fill = false,\n tooltip,\n tooltipPlacement = 'top',\n iconOnly = false,\n flush = false,\n children,\n className = '',\n href,\n target,\n rel,\n ...props\n },\n ref,\n ) => {\n const radiusClass = radius ? getRadiusClass(radius) : getDefaultRadiusClass(size, iconOnly);\n const isInactive = disabled || loading;\n const alignStart = contentAlign === 'start';\n const baseClasses = [\n alignStart\n ? 'flex items-center justify-start text-left'\n : 'flex items-center justify-center',\n iconOnly ? `p-0 ${getIconOnlySizeClasses(size)}` : getSizeClasses(size),\n getVariantClasses(variant, radiusClass),\n flexGrow ? 'w-full' : '',\n width === 'wide' ? 'min-w-[120px]' : '',\n fill ? 'max-w-full' : '',\n isInactive ? 'cursor-not-allowed' : '',\n tooltip && isInactive ? 'pointer-events-none' : '',\n flush && !iconOnly\n ? variant === 'no-style'\n ? FLUSH_MARGIN_BORDERLESS\n : FLUSH_MARGIN\n : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const label = alignStart ? (\n <span className=\"flex min-w-0 flex-1 items-center\">{children}</span>\n ) : (\n children\n );\n\n const leadingSlot = leading ? (\n <span\n className={\n children\n ? 'btn-leading inline-flex shrink-0 items-center me-2'\n : 'btn-leading inline-flex shrink-0 items-center'\n }\n >\n {leading}\n </span>\n ) : null;\n\n const renderContent = () => {\n if (loading) {\n return (\n <>\n {leadingSlot}\n <ButtonSpinner />\n {label}\n </>\n );\n }\n\n const iconWrapperClasses = `inline-flex items-center shrink-0 ${getIconSizeClass(size)}`;\n\n if (icon && iconPosition === 'start') {\n return (\n <>\n {leadingSlot}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'start')}` : ''}`}\n >\n {icon}\n </span>\n {label}\n </>\n );\n }\n\n if (icon && iconPosition === 'end') {\n return (\n <>\n {leadingSlot}\n {label}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'end')}` : ''}`}\n >\n {icon}\n </span>\n </>\n );\n }\n\n return (\n <>\n {leadingSlot}\n {label}\n </>\n );\n };\n\n // An anchor cannot be disabled, so an inactive link still renders as a <button>.\n const button =\n href && !isInactive ? (\n <a\n ref={ref as React.Ref<HTMLAnchorElement>}\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n className={baseClasses}\n {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}\n >\n {renderContent()}\n </a>\n ) : (\n <button\n ref={ref as React.Ref<HTMLButtonElement>}\n disabled={isInactive}\n className={baseClasses}\n {...props}\n >\n {renderContent()}\n </button>\n );\n\n if (tooltip) {\n const trigger = isInactive ? (\n <span className={`inline-flex cursor-not-allowed${flexGrow ? ' w-full' : ''}`}>\n {button}\n </span>\n ) : (\n button\n );\n return (\n <Tooltip text={tooltip} placement={tooltipPlacement} fill={flexGrow}>\n {trigger}\n </Tooltip>\n );\n }\n\n return button;\n },\n);\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"names":["FLUSH_MARGIN","FLUSH_MARGIN_BORDERLESS","Button","forwardRef","variant","size","radius","loading","disabled","icon","iconPosition","leading","contentAlign","flexGrow","width","fill","tooltip","tooltipPlacement","iconOnly","flush","children","className","href","target","rel","props","ref","radiusClass","getRadiusClass","getDefaultRadiusClass","isInactive","alignStart","baseClasses","getIconOnlySizeClasses","getSizeClasses","getVariantClasses","label","jsx","leadingSlot","renderContent","jsxs","Fragment","ButtonSpinner","iconWrapperClasses","getIconSizeClass","getIconGapClass","button","resolveRel","Tooltip"],"mappings":";;;;;;;AAgFA,MAAMA,IAAe,iCACfC,IAA0B,uBAEnBC,IAASC;AAAA,EAClB,CACI;AAAA,IACI,SAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,QAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC,IAAW;AAAA,IACX,MAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,SAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,MAAAC,IAAO;AAAA,IACP,SAAAC;AAAA,IACA,kBAAAC,IAAmB;AAAA,IACnB,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,UAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,MAAAC;AAAA,IACA,QAAAC;AAAA,IACA,KAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,GAEPC,MACC;AACD,UAAMC,IAAcrB,IAASsB,EAAetB,CAAM,IAAIuB,EAAsBxB,GAAMa,CAAQ,GACpFY,IAAatB,KAAYD,GACzBwB,IAAanB,MAAiB,SAC9BoB,IAAc;AAAA,MAChBD,IACM,8CACA;AAAA,MACNb,IAAW,OAAOe,EAAuB5B,CAAI,CAAC,KAAK6B,EAAe7B,CAAI;AAAA,MACtE8B,EAAkB/B,GAASuB,CAAW;AAAA,MACtCd,IAAW,WAAW;AAAA,MACtBC,MAAU,SAAS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AA,EACK,UAAA;AAAA,QAAAH;AAAA,QACAF;AAAA,MAAA,GACL;AAAA,IAER,GAGMU,IACFxB,KAAQ,CAACQ,IACL,gBAAAO;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,KAAAX;AAAA,QACA,MAAAJ;AAAA,QACA,QAAAC;AAAA,QACA,KAAKwB,EAAWvB,GAAKD,CAAM;AAAA,QAC3B,WAAWS;AAAA,QACV,GAAIP;AAAA,QAEJ,UAAAc,EAAA;AAAA,MAAc;AAAA,IAAA,IAGnB,gBAAAF;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,KAAAX;AAAA,QACA,UAAUI;AAAA,QACV,WAAWE;AAAA,QACV,GAAGP;AAAA,QAEH,UAAAc,EAAA;AAAA,MAAc;AAAA,IAAA;AAI3B,WAAIvB,IASI,gBAAAqB,EAACW,KAAQ,MAAMhC,GAAS,WAAWC,GAAkB,MAAMJ,GACtD,UATOiB,IACZ,gBAAAO,EAAC,QAAA,EAAK,WAAW,iCAAiCxB,IAAW,YAAY,EAAE,IACtE,UAAAiC,EAAA,CACL,IAEAA,EAIK,CACL,IAIDA;AAAA,EACX;AACJ;AAEA5C,EAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../src/components/Button.tsx"],"sourcesContent":["import React, { forwardRef, useLayoutEffect, useMemo, useRef } from 'react';\nimport ButtonSpinner from './ButtonSpinner';\nimport Tooltip from './Tooltip';\nimport { getDeepActiveNode } from './activeElement';\nimport { getIconOnlySizeClasses, getIconSizeClass } from './buttonSizing';\nimport {\n getDefaultRadiusClass,\n getIconGapClass,\n getRadiusClass,\n getSizeClasses,\n getVariantClasses,\n} from './buttonStyles';\nimport { composeRefs } from './composeRefs';\nimport { resolveRel } from './linkRel';\n\n// Button variant types matching the old component\nexport type ButtonVariant =\n | 'filled'\n | 'outline'\n /**\n * `outline`'s geometry on a ground of its own. For a button sitting on a tinted or\n * patterned surface, where `outline`'s transparent background lets that surface through\n * and the control stops reading as a button.\n */\n | 'surface'\n /**\n * The violet the assistant is named in elsewhere — for a control that hands work to it, or\n * acts on what it produced. Provenance, not a severity: it says who is being asked, not\n * that anything is wrong.\n */\n | 'assistant'\n | 'destructive'\n | 'success'\n | 'warning'\n | 'error'\n | 'ghost'\n /** `ghost` until its `Surface.Row` is hovered or focused, or its menu opens. For `trailing` only. */\n | 'row-outline'\n /** Text only, in the accent colour, for a secondary action beside a primary one. */\n | 'quiet'\n /**\n * A recessed grey with secondary text, for a control whose subject is switched off, such as\n * an account set to Not allowed. It stays clickable: `disabled` is for a control that is not.\n */\n | 'muted'\n | 'no-style';\n\nexport type ButtonSize = 'xsmall' | 'small' | 'medium' | 'large';\n\nexport type ButtonRadius = 'md' | 'lg' | 'xl';\n\ninterface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n variant: ButtonVariant;\n size?: ButtonSize;\n radius?: ButtonRadius;\n loading?: boolean;\n disabled?: boolean;\n icon?: React.ReactNode;\n iconPosition?: 'start' | 'end';\n /** Before the label at its own size, never squeezed (an avatar); pairs with an end `icon`. */\n leading?: React.ReactNode;\n /** `start` aligns the label to the leading edge and pins an end `icon` to the far edge. */\n contentAlign?: 'center' | 'start';\n /** Fills the container's width. */\n flexGrow?: boolean;\n /** `wide` holds a 120px floor for a primary action. */\n width?: 'auto' | 'wide';\n fill?: boolean;\n tooltip?: string;\n tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';\n iconOnly?: boolean;\n /** Pulls a borderless button out by its own padding, so its label lines up with the text around it. */\n flush?: boolean;\n children?: React.ReactNode;\n onClick?: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement>;\n /** Renders the button as a real anchor, so a link action is never an <a> nested in a <button>. */\n href?: string;\n target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n}\n\n// The 1px is the transparent border, which `no-style` drops.\nconst FLUSH_MARGIN = '-mx-[calc(var(--btn-px)+1px)]';\nconst FLUSH_MARGIN_BORDERLESS = '-mx-[var(--btn-px)]';\n\n// Only keyboard focus is handed back: a mouse user never asked for focus to stay there.\nconst isFocusVisible = (element: Element) => {\n try {\n return element.matches(':focus-visible');\n } catch {\n return true;\n }\n};\n\nexport const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(\n (\n {\n variant,\n size = 'large',\n radius,\n loading = false,\n disabled = false,\n icon,\n iconPosition = 'start',\n leading,\n contentAlign = 'center',\n flexGrow = false,\n width = 'auto',\n fill = false,\n tooltip,\n tooltipPlacement = 'top',\n iconOnly = false,\n flush = false,\n children,\n className = '',\n href,\n target,\n rel,\n onBlur,\n onFocus,\n ...props\n },\n ref,\n ) => {\n const elementRef = useRef<HTMLElement | null>(null);\n // Memoised: a fresh callback ref each render would detach and re-attach the consumer's.\n const composedRef = useMemo(\n () => composeRefs(ref as React.Ref<HTMLElement>, elementRef),\n [ref],\n );\n // Loading disables the button, or swaps the element (a tooltip wrapper, a link), and\n // either drops a keyboard user's focus to <body>. It is handed back when loading ends.\n const keyboardFocus = useRef(false);\n const refocusAfterLoading = useRef(false);\n // Counts focus events, so a blur's deferred clear can tell focus came back meanwhile.\n const focusCount = useRef(0);\n\n // A layout effect, so it reads `keyboardFocus` at commit: the blur that commit causes\n // only clears it from a microtask, after this has run.\n useLayoutEffect(() => {\n if (loading) {\n refocusAfterLoading.current = keyboardFocus.current;\n return;\n }\n if (!refocusAfterLoading.current) {\n return;\n }\n refocusAfterLoading.current = false;\n const active = getDeepActiveNode();\n if (!active || active === document.body) {\n elementRef.current?.focus({ preventScroll: true });\n // Scripted focus from <body> need not match :focus-visible, yet it is still the\n // keyboard user's: the next send must hand it back too.\n if (getDeepActiveNode() === elementRef.current) {\n keyboardFocus.current = true;\n }\n }\n }, [loading]);\n\n const handleFocus = (event: React.FocusEvent<HTMLElement>) => {\n focusCount.current += 1;\n keyboardFocus.current = isFocusVisible(event.currentTarget);\n onFocus?.(event as React.FocusEvent<HTMLButtonElement>);\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLElement>) => {\n // A focus trap can put focus straight back within this task; that focus wins.\n const blurredAfter = focusCount.current;\n queueMicrotask(() => {\n if (focusCount.current === blurredAfter) {\n keyboardFocus.current = false;\n }\n });\n onBlur?.(event as React.FocusEvent<HTMLButtonElement>);\n };\n\n const radiusClass = radius ? getRadiusClass(radius) : getDefaultRadiusClass(size, iconOnly);\n const isInactive = disabled || loading;\n const alignStart = contentAlign === 'start';\n const baseClasses = [\n alignStart\n ? 'flex items-center justify-start text-left'\n : 'flex items-center justify-center',\n iconOnly ? `p-0 ${getIconOnlySizeClasses(size)}` : getSizeClasses(size),\n getVariantClasses(variant, radiusClass),\n flexGrow ? 'w-full' : '',\n width === 'wide' ? 'min-w-[120px]' : '',\n fill ? 'max-w-full' : '',\n isInactive ? 'cursor-not-allowed' : '',\n tooltip && isInactive ? 'pointer-events-none' : '',\n flush && !iconOnly\n ? variant === 'no-style'\n ? FLUSH_MARGIN_BORDERLESS\n : FLUSH_MARGIN\n : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n const label = alignStart ? (\n <span className=\"flex min-w-0 flex-1 items-center\">{children}</span>\n ) : (\n children\n );\n\n const leadingSlot = leading ? (\n <span\n className={\n children\n ? 'btn-leading inline-flex shrink-0 items-center me-2'\n : 'btn-leading inline-flex shrink-0 items-center'\n }\n >\n {leading}\n </span>\n ) : null;\n\n const renderContent = () => {\n if (loading) {\n return (\n <>\n {leadingSlot}\n <ButtonSpinner />\n {label}\n </>\n );\n }\n\n const iconWrapperClasses = `inline-flex items-center shrink-0 ${getIconSizeClass(size)}`;\n\n if (icon && iconPosition === 'start') {\n return (\n <>\n {leadingSlot}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'start')}` : ''}`}\n >\n {icon}\n </span>\n {label}\n </>\n );\n }\n\n if (icon && iconPosition === 'end') {\n return (\n <>\n {leadingSlot}\n {label}\n <span\n className={`${iconWrapperClasses}${children ? ` ${getIconGapClass(size, 'end')}` : ''}`}\n >\n {icon}\n </span>\n </>\n );\n }\n\n return (\n <>\n {leadingSlot}\n {label}\n </>\n );\n };\n\n // An anchor cannot be disabled, so an inactive link still renders as a <button>.\n const button =\n href && !isInactive ? (\n <a\n ref={composedRef}\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n className={baseClasses}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}\n >\n {renderContent()}\n </a>\n ) : (\n <button\n ref={composedRef}\n disabled={isInactive}\n className={baseClasses}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...props}\n >\n {renderContent()}\n </button>\n );\n\n if (tooltip) {\n const trigger = isInactive ? (\n <span className={`inline-flex cursor-not-allowed${flexGrow ? ' w-full' : ''}`}>\n {button}\n </span>\n ) : (\n button\n );\n return (\n <Tooltip text={tooltip} placement={tooltipPlacement} fill={flexGrow}>\n {trigger}\n </Tooltip>\n );\n }\n\n return button;\n },\n);\n\nButton.displayName = 'Button';\n\nexport default Button;\n"],"names":["FLUSH_MARGIN","FLUSH_MARGIN_BORDERLESS","isFocusVisible","element","Button","forwardRef","variant","size","radius","loading","disabled","icon","iconPosition","leading","contentAlign","flexGrow","width","fill","tooltip","tooltipPlacement","iconOnly","flush","children","className","href","target","rel","onBlur","onFocus","props","ref","elementRef","useRef","composedRef","useMemo","composeRefs","keyboardFocus","refocusAfterLoading","focusCount","useLayoutEffect","active","getDeepActiveNode","_a","handleFocus","event","handleBlur","blurredAfter","radiusClass","getRadiusClass","getDefaultRadiusClass","isInactive","alignStart","baseClasses","getIconOnlySizeClasses","getSizeClasses","getVariantClasses","label","jsx","leadingSlot","renderContent","jsxs","Fragment","ButtonSpinner","iconWrapperClasses","getIconSizeClass","getIconGapClass","button","resolveRel","Tooltip"],"mappings":";;;;;;;;;AAkFA,MAAMA,KAAe,iCACfC,KAA0B,uBAG1BC,KAAiB,CAACC,MAAqB;AACzC,MAAI;AACA,WAAOA,EAAQ,QAAQ,gBAAgB;AAAA,EAC3C,QAAQ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UATOmC,IACZ,gBAAAO,EAAC,QAAA,EAAK,WAAW,iCAAiC1C,IAAW,YAAY,EAAE,IACtE,UAAAmD,EAAA,CACL,IAEAA,EAIK,CACL,IAIDA;AAAA,EACX;AACJ;AAEA9D,GAAO,cAAc;"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { createPortal as
|
|
1
|
+
import { jsxs as v, Fragment as k, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { useState as L, useRef as R, useCallback as S, useEffect as ee, useInsertionEffect as te } from "react";
|
|
3
|
+
import { createPortal as ne } from "react-dom";
|
|
4
4
|
import { Avatar as B } from "../Avatar.js";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import re from "../CustomIcons/CaretDownIcon.js";
|
|
6
|
+
import oe from "../CustomIcons/CaretRightIcon.js";
|
|
7
|
+
import ie from "../CustomIcons/CaretUpIcon.js";
|
|
8
8
|
import D from "../CustomIcons/CheckIcon.js";
|
|
9
|
-
import { PillButton as
|
|
10
|
-
import { pushEscapeLayer as
|
|
9
|
+
import { PillButton as le } from "../PillButton.js";
|
|
10
|
+
import { pushEscapeLayer as se } from "../escapeLayers.js";
|
|
11
11
|
import { usePopupLayer as M } from "../overlayLayers.js";
|
|
12
|
-
import { useOwnedByPopover as
|
|
13
|
-
import { ensureOverlayStyles as
|
|
14
|
-
import { useTopLayer as
|
|
15
|
-
|
|
12
|
+
import { useOwnedByPopover as ae } from "../popoverTree.js";
|
|
13
|
+
import { ensureOverlayStyles as ce } from "../portalOverlay.js";
|
|
14
|
+
import { useTopLayer as ue } from "../topLayer.js";
|
|
15
|
+
import { useFollowTrigger as fe } from "../useFollowTrigger.js";
|
|
16
|
+
const h = 8, _ = 220, P = 240, N = (r, c) => ({
|
|
16
17
|
position: "fixed",
|
|
17
18
|
top: (r == null ? void 0 : r.top) ?? 0,
|
|
18
19
|
left: (r == null ? void 0 : r.left) ?? 0,
|
|
@@ -40,84 +41,86 @@ const h = 8, _ = 220, z = 240, N = (r, c) => ({
|
|
|
40
41
|
cursor: "pointer",
|
|
41
42
|
fontSize: "var(--malachite-font-size-small, 13px)",
|
|
42
43
|
color: "var(--malachite-text-primary, rgb(10, 10, 10))"
|
|
43
|
-
},
|
|
44
|
+
}, me = {
|
|
44
45
|
fontSize: "var(--malachite-font-size-xsmall, 11px)",
|
|
45
46
|
color: "var(--malachite-text-dimmed, rgb(161, 161, 161))"
|
|
46
47
|
}, A = {
|
|
47
48
|
marginLeft: "auto",
|
|
48
49
|
display: "inline-flex",
|
|
49
50
|
color: "var(--malachite-text-success, rgb(2, 122, 66))"
|
|
50
|
-
},
|
|
51
|
+
}, Pe = ({
|
|
51
52
|
models: r,
|
|
52
53
|
value: c,
|
|
53
|
-
optionValue:
|
|
54
|
-
onChange:
|
|
54
|
+
optionValue: F,
|
|
55
|
+
onChange: H,
|
|
55
56
|
disabled: U = !1,
|
|
56
|
-
openUp:
|
|
57
|
+
openUp: E = !0,
|
|
57
58
|
"aria-label": Y = "Model"
|
|
58
59
|
}) => {
|
|
59
60
|
var O;
|
|
60
|
-
const [l,
|
|
61
|
+
const [l, g] = L(!1), [j, G] = L(null), [K, x] = L(null), [V, C] = L(
|
|
61
62
|
null
|
|
62
|
-
),
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
), y = R(null), u = R(null), w = R(null), $ = M("actionmenu", l, u), q = M("actionmenu", l, w);
|
|
64
|
+
ue(u, l), ae(
|
|
65
|
+
S(() => w.current, []),
|
|
65
66
|
l
|
|
66
67
|
);
|
|
67
|
-
const s = r.find((e) => e.value === c),
|
|
68
|
-
const e =
|
|
68
|
+
const s = r.find((e) => e.value === c), b = S(() => {
|
|
69
|
+
const e = y.current, t = u.current;
|
|
69
70
|
if (!e)
|
|
70
71
|
return;
|
|
71
|
-
const o = e.getBoundingClientRect(), i = (t == null ? void 0 : t.offsetWidth) || _, a = (t == null ? void 0 : t.offsetHeight) || 0,
|
|
72
|
-
G({ top:
|
|
73
|
-
}, [
|
|
74
|
-
|
|
72
|
+
const o = e.getBoundingClientRect(), i = (t == null ? void 0 : t.offsetWidth) || _, a = (t == null ? void 0 : t.offsetHeight) || 0, I = window.innerWidth - i - h, m = Math.max(h, Math.min(o.right - i, I)), p = o.top - a - 4, d = o.bottom + 4, X = p >= h, Z = a === 0 || d + a <= window.innerHeight - h;
|
|
73
|
+
G({ top: E ? X ? p : d : Z ? d : p, left: m });
|
|
74
|
+
}, [E]), J = S(() => {
|
|
75
|
+
x(null), C(null), b();
|
|
76
|
+
}, [b]), Q = S(() => g(!1), []);
|
|
77
|
+
fe(l, y, J, Q), ee(() => {
|
|
75
78
|
if (!l) {
|
|
76
|
-
|
|
79
|
+
x(null), C(null);
|
|
77
80
|
return;
|
|
78
81
|
}
|
|
79
|
-
|
|
80
|
-
const e = () =>
|
|
82
|
+
b();
|
|
83
|
+
const e = () => b(), t = (i) => {
|
|
81
84
|
const a = i.composedPath();
|
|
82
|
-
[
|
|
85
|
+
[y.current, u.current, w.current].some(
|
|
83
86
|
(m) => m !== null && a.includes(m)
|
|
84
|
-
) ||
|
|
85
|
-
}, o =
|
|
86
|
-
return window.addEventListener("
|
|
87
|
-
window.removeEventListener("
|
|
87
|
+
) || g(!1);
|
|
88
|
+
}, o = se(() => g(!1));
|
|
89
|
+
return window.addEventListener("resize", e), document.addEventListener("mousedown", t, !0), () => {
|
|
90
|
+
window.removeEventListener("resize", e), document.removeEventListener("mousedown", t, !0), o();
|
|
88
91
|
};
|
|
89
|
-
}, [l,
|
|
90
|
-
l &&
|
|
92
|
+
}, [l, b]), te(() => {
|
|
93
|
+
l && ce();
|
|
91
94
|
}, [l]);
|
|
92
|
-
const
|
|
93
|
-
var m,
|
|
95
|
+
const T = (e, t) => {
|
|
96
|
+
var m, p, d;
|
|
94
97
|
if (!((m = e.options) != null && m.length)) {
|
|
95
|
-
|
|
98
|
+
x(null);
|
|
96
99
|
return;
|
|
97
100
|
}
|
|
98
|
-
const o = t.getBoundingClientRect(), a = (((
|
|
99
|
-
(((
|
|
100
|
-
window.innerWidth -
|
|
101
|
+
const o = t.getBoundingClientRect(), a = (((p = u.current) == null ? void 0 : p.getBoundingClientRect().left) ?? o.left) - P - 4, I = a >= h ? a : Math.min(
|
|
102
|
+
(((d = u.current) == null ? void 0 : d.getBoundingClientRect().right) ?? o.right) + 4,
|
|
103
|
+
window.innerWidth - P - h
|
|
101
104
|
);
|
|
102
|
-
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
+
x(e.value), C({ top: o.top, left: I });
|
|
106
|
+
}, z = (e, t) => {
|
|
107
|
+
H(e.value, t == null ? void 0 : t.value), g(!1);
|
|
105
108
|
}, f = r.find((e) => e.value === K);
|
|
106
|
-
return /* @__PURE__ */
|
|
107
|
-
/* @__PURE__ */ n("div", { ref:
|
|
108
|
-
|
|
109
|
+
return /* @__PURE__ */ v(k, { children: [
|
|
110
|
+
/* @__PURE__ */ n("div", { ref: y, className: "inline-flex", children: /* @__PURE__ */ n(
|
|
111
|
+
le,
|
|
109
112
|
{
|
|
110
113
|
label: (s == null ? void 0 : s.label) ?? c,
|
|
111
114
|
icon: s != null && s.iconSrc ? /* @__PURE__ */ n(B, { src: s.iconSrc, name: s.label, size: 14 }) : void 0,
|
|
112
|
-
trailingIcon:
|
|
115
|
+
trailingIcon: E ? /* @__PURE__ */ n(ie, { size: 10 }) : /* @__PURE__ */ n(re, { size: 10 }),
|
|
113
116
|
shape: "tab",
|
|
114
117
|
size: "small",
|
|
115
118
|
disabled: U,
|
|
116
|
-
onClick: () =>
|
|
119
|
+
onClick: () => g((e) => !e)
|
|
117
120
|
}
|
|
118
121
|
) }),
|
|
119
|
-
l &&
|
|
120
|
-
/* @__PURE__ */
|
|
122
|
+
l && ne(
|
|
123
|
+
/* @__PURE__ */ v(k, { children: [
|
|
121
124
|
/* @__PURE__ */ n(
|
|
122
125
|
"div",
|
|
123
126
|
{
|
|
@@ -128,18 +131,18 @@ const h = 8, _ = 220, z = 240, N = (r, c) => ({
|
|
|
128
131
|
style: N(j, _),
|
|
129
132
|
children: r.map((e) => {
|
|
130
133
|
var t, o;
|
|
131
|
-
return /* @__PURE__ */
|
|
134
|
+
return /* @__PURE__ */ v(
|
|
132
135
|
"button",
|
|
133
136
|
{
|
|
134
137
|
type: "button",
|
|
135
138
|
role: "menuitem",
|
|
136
139
|
"aria-haspopup": (t = e.options) != null && t.length ? "menu" : void 0,
|
|
137
140
|
style: W,
|
|
138
|
-
onMouseEnter: (i) =>
|
|
139
|
-
onFocus: (i) =>
|
|
141
|
+
onMouseEnter: (i) => T(e, i.currentTarget),
|
|
142
|
+
onFocus: (i) => T(e, i.currentTarget),
|
|
140
143
|
onClick: () => {
|
|
141
144
|
var i;
|
|
142
|
-
return (i = e.options) != null && i.length ?
|
|
145
|
+
return (i = e.options) != null && i.length ? z(e, e.options[0]) : z(e);
|
|
143
146
|
},
|
|
144
147
|
children: [
|
|
145
148
|
e.iconSrc ? /* @__PURE__ */ n(B, { src: e.iconSrc, name: e.label, size: 14 }) : null,
|
|
@@ -153,7 +156,7 @@ const h = 8, _ = 220, z = 240, N = (r, c) => ({
|
|
|
153
156
|
display: "inline-flex",
|
|
154
157
|
color: "var(--malachite-text-dimmed, rgb(161, 161, 161))"
|
|
155
158
|
},
|
|
156
|
-
children: /* @__PURE__ */ n(
|
|
159
|
+
children: /* @__PURE__ */ n(oe, { size: 10 })
|
|
157
160
|
}
|
|
158
161
|
) : null
|
|
159
162
|
]
|
|
@@ -166,20 +169,20 @@ const h = 8, _ = 220, z = 240, N = (r, c) => ({
|
|
|
166
169
|
(O = f == null ? void 0 : f.options) != null && O.length ? /* @__PURE__ */ n(
|
|
167
170
|
"div",
|
|
168
171
|
{
|
|
169
|
-
ref:
|
|
172
|
+
ref: w,
|
|
170
173
|
role: "menu",
|
|
171
174
|
"aria-label": `${f.label} options`,
|
|
172
175
|
...q,
|
|
173
|
-
style: N(V,
|
|
174
|
-
children: f.options.map((e) => /* @__PURE__ */
|
|
176
|
+
style: N(V, P),
|
|
177
|
+
children: f.options.map((e) => /* @__PURE__ */ v(
|
|
175
178
|
"button",
|
|
176
179
|
{
|
|
177
180
|
type: "button",
|
|
178
181
|
role: "menuitem",
|
|
179
182
|
style: { ...W, alignItems: "flex-start" },
|
|
180
|
-
onClick: () =>
|
|
183
|
+
onClick: () => z(f, e),
|
|
181
184
|
children: [
|
|
182
|
-
/* @__PURE__ */
|
|
185
|
+
/* @__PURE__ */ v(
|
|
183
186
|
"span",
|
|
184
187
|
{
|
|
185
188
|
style: {
|
|
@@ -189,11 +192,11 @@ const h = 8, _ = 220, z = 240, N = (r, c) => ({
|
|
|
189
192
|
},
|
|
190
193
|
children: [
|
|
191
194
|
e.label,
|
|
192
|
-
e.description ? /* @__PURE__ */ n("span", { style:
|
|
195
|
+
e.description ? /* @__PURE__ */ n("span", { style: me, children: e.description }) : null
|
|
193
196
|
]
|
|
194
197
|
}
|
|
195
198
|
),
|
|
196
|
-
f.value === c && e.value ===
|
|
199
|
+
f.value === c && e.value === F ? /* @__PURE__ */ n("span", { style: A, children: /* @__PURE__ */ n(D, { size: 11 }) }) : null
|
|
197
200
|
]
|
|
198
201
|
},
|
|
199
202
|
e.value
|
|
@@ -206,7 +209,7 @@ const h = 8, _ = 220, z = 240, N = (r, c) => ({
|
|
|
206
209
|
] });
|
|
207
210
|
};
|
|
208
211
|
export {
|
|
209
|
-
|
|
210
|
-
|
|
212
|
+
Pe as ChatModelPicker,
|
|
213
|
+
Pe as default
|
|
211
214
|
};
|
|
212
215
|
//# sourceMappingURL=ChatModelPicker.js.map
|