@shortround/react 0.0.0-stage → 0.6.0
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/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +578 -2
- package/dist/react.es.js +652 -0
- package/package.json +69 -3
- package/src/index.d.ts +266 -0
package/dist/react.es.js
ADDED
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import { createPaletteStore as he, createSidekickStore as Q, cycleCorners as fe, RevertIntentionIds as me, NAVIGATE_GROUP as pe, ControlLabels as Se } from "@shortround/core";
|
|
2
|
+
import { useRef as m, useSyncExternalStore as H, useEffect as C, createContext as Z, useContext as ee, useMemo as F, useCallback as _, createElement as ge, useLayoutEffect as L, forwardRef as we, useState as ve } from "react";
|
|
3
|
+
import { jsx as i, jsxs as k, Fragment as Re } from "react/jsx-runtime";
|
|
4
|
+
import ye from "tiny-invariant";
|
|
5
|
+
import { motion as V } from "framer-motion";
|
|
6
|
+
import { Command as b, useCommandState as te } from "cmdk";
|
|
7
|
+
function ne({
|
|
8
|
+
palette: e,
|
|
9
|
+
defaultIntentions: t,
|
|
10
|
+
resolveDefaultInput: n,
|
|
11
|
+
resolveDefaultFallbackInput: o
|
|
12
|
+
}) {
|
|
13
|
+
const r = m(null);
|
|
14
|
+
r.current || (r.current = he({
|
|
15
|
+
palette: e,
|
|
16
|
+
defaultIntentions: t,
|
|
17
|
+
resolveDefaultInput: n,
|
|
18
|
+
resolveDefaultFallbackInput: o
|
|
19
|
+
}));
|
|
20
|
+
const c = r.current, s = H(c.subscribe, c.getState, c.getState);
|
|
21
|
+
return C(() => {
|
|
22
|
+
c.setDefaults({
|
|
23
|
+
palette: e,
|
|
24
|
+
defaultIntentions: t,
|
|
25
|
+
resolveDefaultInput: n,
|
|
26
|
+
resolveDefaultFallbackInput: o
|
|
27
|
+
});
|
|
28
|
+
}, [c, e, t, n, o]), C(() => c.watchResolver(), [c]), C(() => c.watchPalette(), [c, e]), { store: c, state: s, intentions: c.rows() };
|
|
29
|
+
}
|
|
30
|
+
function ft({
|
|
31
|
+
defaultIntentions: e,
|
|
32
|
+
resolveDefaultInput: t,
|
|
33
|
+
resolveDefaultFallbackInput: n
|
|
34
|
+
}) {
|
|
35
|
+
const { store: o, state: r, intentions: c } = ne({
|
|
36
|
+
defaultIntentions: e,
|
|
37
|
+
resolveDefaultInput: t,
|
|
38
|
+
resolveDefaultFallbackInput: n
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
inputValue: r.inputValue,
|
|
42
|
+
inputMessage: r.inputMessage,
|
|
43
|
+
onInputChange: o.changeInput,
|
|
44
|
+
intentions: c,
|
|
45
|
+
revertIntentions: r.revertIntentions,
|
|
46
|
+
dispatch: (s) => o.select(s),
|
|
47
|
+
reset: o.reset,
|
|
48
|
+
back: o.back,
|
|
49
|
+
dispatchedStack: r.dispatchedStack
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const U = 0.35, ke = "100vh", Oe = Object.freeze({
|
|
53
|
+
center: { top: "50%", left: "50%", transform: "translate(-50%, -50%)" },
|
|
54
|
+
"top-left": { top: 0, left: 0 },
|
|
55
|
+
top: { top: 0, left: "50%", transform: "translateX(-50%)" },
|
|
56
|
+
left: { top: "50%", left: 0, transform: "translateY(-50%)" },
|
|
57
|
+
"top-right": { top: 0, right: 0 },
|
|
58
|
+
right: { top: "50%", right: 0, transform: "translateY(-50%)" },
|
|
59
|
+
"bottom-right": { bottom: 0, right: 0 },
|
|
60
|
+
bottom: { bottom: 0, left: "50%", transform: "translateX(-50%)" },
|
|
61
|
+
"bottom-left": { bottom: 0, left: 0 }
|
|
62
|
+
}), q = Object.freeze({
|
|
63
|
+
compact: { height: "auto" },
|
|
64
|
+
medium: { height: "50vh" },
|
|
65
|
+
full: { height: ke }
|
|
66
|
+
}), oe = "ShortRound", Ie = ({ onOpen: e, installKeyboardShortcuts: t = !0 }) => {
|
|
67
|
+
const n = m({ onOpen: e });
|
|
68
|
+
n.current = { onOpen: e }, C(() => {
|
|
69
|
+
if (!t)
|
|
70
|
+
return;
|
|
71
|
+
const o = (r) => {
|
|
72
|
+
(r.metaKey || r.ctrlKey) && r.key === "k" && n.current.onOpen();
|
|
73
|
+
};
|
|
74
|
+
return document.addEventListener("keydown", o, { capture: !0 }), () => document.removeEventListener("keydown", o, { capture: !0 });
|
|
75
|
+
}, [t]);
|
|
76
|
+
}, re = Z(null), W = () => ee(re);
|
|
77
|
+
function Ee({ store: e, initial: t, children: n }) {
|
|
78
|
+
const o = W(), r = m(null);
|
|
79
|
+
!e && !o && !r.current && (r.current = Q(t));
|
|
80
|
+
const c = e ?? o ?? r.current;
|
|
81
|
+
return /* @__PURE__ */ i(re.Provider, { value: c, children: n });
|
|
82
|
+
}
|
|
83
|
+
function j(e = {}) {
|
|
84
|
+
const t = W();
|
|
85
|
+
let n = e.store || t;
|
|
86
|
+
const o = m(null);
|
|
87
|
+
n || (o.current || (o.current = Q(e.initial)), n = o.current);
|
|
88
|
+
const r = H(n.subscribe, n.get, n.get), c = F(() => {
|
|
89
|
+
const { maxTotalWidth: s, commandWidth: a, anchorOrigin: d, internalSidecarRenderer: h, size: l } = r, { height: p } = q[l], w = `calc(${s} - ${a})`, v = (f) => n.set({ anchorOrigin: f }), R = () => {
|
|
90
|
+
v(fe(d));
|
|
91
|
+
}, y = () => {
|
|
92
|
+
if (h)
|
|
93
|
+
return h();
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
// Worked out from the origin, so a store created with only `anchorOrigin` opens there; a position stored
|
|
97
|
+
// beside it (a 0.3.0 workaround) is ignored.
|
|
98
|
+
anchorPosition: Oe[d],
|
|
99
|
+
onOpen: () => n.set({ isOpen: !0 }),
|
|
100
|
+
setIsOpen: (f) => {
|
|
101
|
+
n.set({ isOpen: f });
|
|
102
|
+
},
|
|
103
|
+
onClose: () => {
|
|
104
|
+
n.clearSidecar(), n.set({ isOpen: !1 });
|
|
105
|
+
},
|
|
106
|
+
height: p,
|
|
107
|
+
setSize: (f) => {
|
|
108
|
+
ye(q[f], `Unknown size: ${f}`), n.set({ size: f });
|
|
109
|
+
},
|
|
110
|
+
setAnchorOrigin: v,
|
|
111
|
+
cycleAnchorOrigin: R,
|
|
112
|
+
// The app's own calls: through the reducer, with the reason `app`.
|
|
113
|
+
setSidecarRenderer: n.openSidecar,
|
|
114
|
+
commandWidth: a,
|
|
115
|
+
sidecarWidth: w,
|
|
116
|
+
closeSidecar: n.closeSidecar,
|
|
117
|
+
renderSidecar: y
|
|
118
|
+
};
|
|
119
|
+
}, [n, r]);
|
|
120
|
+
return { ...r, ...c };
|
|
121
|
+
}
|
|
122
|
+
const ce = Z(null), N = () => ee(ce), mt = () => N()?.components ?? null;
|
|
123
|
+
function pt() {
|
|
124
|
+
const e = N();
|
|
125
|
+
if (!e)
|
|
126
|
+
throw new Error("useShortRoundToast needs a <ShortRoundProvider theme={…}> above it");
|
|
127
|
+
return { showToast: e.showToast };
|
|
128
|
+
}
|
|
129
|
+
function X(e) {
|
|
130
|
+
(e.querySelector("[cmdk-input]") ?? e).focus();
|
|
131
|
+
}
|
|
132
|
+
function be() {
|
|
133
|
+
const e = m(null), t = m(null), n = _((r) => {
|
|
134
|
+
if (r) {
|
|
135
|
+
t.current = document.activeElement, e.current = r, X(r);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const c = e.current, s = t.current;
|
|
139
|
+
e.current = null, t.current = null;
|
|
140
|
+
const a = document.activeElement;
|
|
141
|
+
(!a || a === document.body || c?.contains(a)) && s && s !== document.body && s.isConnected && s.focus();
|
|
142
|
+
}, []), o = _(() => {
|
|
143
|
+
e.current && X(e.current);
|
|
144
|
+
}, []);
|
|
145
|
+
return { attachDialog: n, focusInside: o };
|
|
146
|
+
}
|
|
147
|
+
const Ce = { subscribe: () => () => {
|
|
148
|
+
}, getState: () => null };
|
|
149
|
+
function Te({ palette: e, disableLineHints: t, store: n }) {
|
|
150
|
+
const o = typeof e?.commandLine == "function" && !t, r = o ? n.commandLine() : null, c = r ?? Ce, s = H(c.subscribe, c.getState, c.getState);
|
|
151
|
+
return { canShowHints: o, lineState: r ? s : null, complete: () => !n.commandLine() || !n.completeFirst() ? null : n.commandLine()?.getState().caret ?? null };
|
|
152
|
+
}
|
|
153
|
+
const Le = new Set(Object.values(me)), J = (e, t) => t[e] ?? t.unknown, A = (e, t) => e ? ge(e, t) : void 0;
|
|
154
|
+
function xe(e, { registry: t = {}, themeIcons: n = {} }) {
|
|
155
|
+
const o = t.intentions?.[e.id];
|
|
156
|
+
if (o)
|
|
157
|
+
return A(o);
|
|
158
|
+
if (!e.icon)
|
|
159
|
+
return;
|
|
160
|
+
if (Le.has(e.id))
|
|
161
|
+
return A(J(e.icon, n));
|
|
162
|
+
const r = t.names?.[e.icon] ?? e.icon;
|
|
163
|
+
return t.Icon ? A(t.Icon, { name: r }) : A(J(r, n));
|
|
164
|
+
}
|
|
165
|
+
const Pe = [
|
|
166
|
+
"fontFamily",
|
|
167
|
+
"fontSize",
|
|
168
|
+
"fontWeight",
|
|
169
|
+
"fontStyle",
|
|
170
|
+
"lineHeight",
|
|
171
|
+
"letterSpacing",
|
|
172
|
+
"textIndent",
|
|
173
|
+
"paddingTop",
|
|
174
|
+
"paddingRight",
|
|
175
|
+
"paddingBottom",
|
|
176
|
+
"paddingLeft",
|
|
177
|
+
"borderTopWidth",
|
|
178
|
+
"borderRightWidth",
|
|
179
|
+
"borderBottomWidth",
|
|
180
|
+
"borderLeftWidth"
|
|
181
|
+
];
|
|
182
|
+
function De({ children: e, inputRef: t, lineState: n }) {
|
|
183
|
+
const o = m(null), r = !!n;
|
|
184
|
+
return L(() => {
|
|
185
|
+
const c = t.current, s = o.current;
|
|
186
|
+
if (!c)
|
|
187
|
+
return;
|
|
188
|
+
if (!r) {
|
|
189
|
+
c.style.color = "", c.style.caretColor = "";
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
Fe(c, s);
|
|
193
|
+
const a = () => {
|
|
194
|
+
s.scrollLeft = c.scrollLeft;
|
|
195
|
+
};
|
|
196
|
+
return a(), c.addEventListener("scroll", a), () => c.removeEventListener("scroll", a);
|
|
197
|
+
}), /* @__PURE__ */ k("div", { "data-testid": "shortround-line-input", style: Ae, children: [
|
|
198
|
+
r && /* @__PURE__ */ i("div", { "aria-hidden": !0, "data-testid": "shortround-line-shadow", ref: o, style: _e, children: /* @__PURE__ */ i(We, { state: n }) }),
|
|
199
|
+
e
|
|
200
|
+
] });
|
|
201
|
+
}
|
|
202
|
+
const Ae = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0 }, _e = {
|
|
203
|
+
position: "absolute",
|
|
204
|
+
pointerEvents: "none",
|
|
205
|
+
whiteSpace: "pre",
|
|
206
|
+
overflow: "hidden",
|
|
207
|
+
borderStyle: "solid",
|
|
208
|
+
borderColor: "transparent",
|
|
209
|
+
// The shadow is sized from the input's offset box, which includes padding and border.
|
|
210
|
+
boxSizing: "border-box"
|
|
211
|
+
};
|
|
212
|
+
function Fe(e, t) {
|
|
213
|
+
const n = window.getComputedStyle(e);
|
|
214
|
+
e.style.color !== "transparent" && (t.style.color = n.color, e.style.caretColor = n.color, e.style.color = "transparent"), Pe.forEach((o) => {
|
|
215
|
+
t.style[o] = n[o];
|
|
216
|
+
}), Object.assign(t.style, {
|
|
217
|
+
left: `${e.offsetLeft}px`,
|
|
218
|
+
top: `${e.offsetTop}px`,
|
|
219
|
+
width: `${e.offsetWidth}px`,
|
|
220
|
+
height: `${e.offsetHeight}px`
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function We({ state: e }) {
|
|
224
|
+
const t = [];
|
|
225
|
+
let n = 0;
|
|
226
|
+
for (const o of e.roles)
|
|
227
|
+
o.start > n && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n, o.start) }, `gap-${n}`)), t.push(
|
|
228
|
+
/* @__PURE__ */ i("span", { "data-role": o.role, title: o.reason, children: e.text.slice(o.start, o.end) }, o.start)
|
|
229
|
+
), n = o.end;
|
|
230
|
+
return n < e.text.length && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n) }, `tail-${n}`)), /* @__PURE__ */ k(Re, { children: [
|
|
231
|
+
t,
|
|
232
|
+
e.ghost && /* @__PURE__ */ i("span", { "data-role": "ghost", children: e.ghost })
|
|
233
|
+
] });
|
|
234
|
+
}
|
|
235
|
+
const Ne = "Type a intention or search...", Ge = { display: "flex", flexDirection: "column" }, $e = { order: -1 }, ze = "shortround::navigate", Ke = "shortround::no-group";
|
|
236
|
+
function He(e) {
|
|
237
|
+
const t = document.activeElement;
|
|
238
|
+
e && t !== e && e.closest("[cmdk-root]")?.contains(t) && e.focus();
|
|
239
|
+
}
|
|
240
|
+
function Ve({ intention: e, onSelect: t, Item: n, iconSources: o }) {
|
|
241
|
+
const r = te((c) => c.value) === e.id.trim();
|
|
242
|
+
return /* @__PURE__ */ i(
|
|
243
|
+
b.Item,
|
|
244
|
+
{
|
|
245
|
+
"data-testid": `shortround-item-${e.id}`,
|
|
246
|
+
disabled: e.disabled,
|
|
247
|
+
keywords: e.keywords,
|
|
248
|
+
onSelect: () => t(e.id),
|
|
249
|
+
value: e.id,
|
|
250
|
+
children: /* @__PURE__ */ i(
|
|
251
|
+
n,
|
|
252
|
+
{
|
|
253
|
+
icon: xe(e, o),
|
|
254
|
+
intention: e,
|
|
255
|
+
isSelected: r
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
const Ue = (e) => e.reduce((t, n) => {
|
|
262
|
+
const o = n.group ?? void 0;
|
|
263
|
+
let r = t.find((c) => c.name === o);
|
|
264
|
+
return r || (r = { name: o, intentions: [] }, t.push(r)), r.intentions.push(n), t;
|
|
265
|
+
}, []);
|
|
266
|
+
function je({ groupRef: e, rowIds: t }) {
|
|
267
|
+
const n = te((r) => r.value), o = t.includes(n);
|
|
268
|
+
return C(() => {
|
|
269
|
+
if (!o)
|
|
270
|
+
return;
|
|
271
|
+
const r = requestAnimationFrame(
|
|
272
|
+
() => e.current?.scrollIntoView({ block: "nearest" })
|
|
273
|
+
);
|
|
274
|
+
return () => cancelAnimationFrame(r);
|
|
275
|
+
}, [n, o, e]), null;
|
|
276
|
+
}
|
|
277
|
+
function Ye(e) {
|
|
278
|
+
const t = m(null);
|
|
279
|
+
return L(() => {
|
|
280
|
+
t.current !== null && e.current && (e.current.setSelectionRange(t.current, t.current), t.current = null);
|
|
281
|
+
}), t;
|
|
282
|
+
}
|
|
283
|
+
function Me({
|
|
284
|
+
palette: e,
|
|
285
|
+
defaultIntentions: t,
|
|
286
|
+
resolveDefaultInput: n,
|
|
287
|
+
resolveDefaultFallbackInput: o,
|
|
288
|
+
defaultSidecarRenderer: r,
|
|
289
|
+
IntentionPalette: c,
|
|
290
|
+
iconSources: s = {},
|
|
291
|
+
showToast: a,
|
|
292
|
+
label: d,
|
|
293
|
+
disableLineHints: h = !1
|
|
294
|
+
}) {
|
|
295
|
+
const { store: l, state: p, intentions: w } = ne({
|
|
296
|
+
palette: e,
|
|
297
|
+
defaultIntentions: t,
|
|
298
|
+
resolveDefaultInput: n,
|
|
299
|
+
resolveDefaultFallbackInput: o
|
|
300
|
+
}), { inputValue: v, inputMessage: R, revertIntentions: y } = p, { height: f, onClose: O } = j(), I = W(), S = m(null), x = m(null), G = Ye(S), T = Te({ palette: e, disableLineHints: h, store: l }), $ = F(() => Ue(w), [w]), z = p.highlightedId?.trim() ?? "", K = (u) => {
|
|
301
|
+
const g = [...w, ...y].find(({ id: E }) => E.trim() === u);
|
|
302
|
+
l.highlight(g?.id ?? u);
|
|
303
|
+
}, P = (u) => l.changeInput(u, S.current?.selectionStart), se = (u) => {
|
|
304
|
+
const { value: g, selectionStart: E } = u.target, D = l.commandLine()?.getState();
|
|
305
|
+
D && g === l.getState().inputValue && D.caret !== E && l.changeInput(g, E);
|
|
306
|
+
}, ie = () => {
|
|
307
|
+
const u = T.complete();
|
|
308
|
+
return u !== null ? (G.current = u, !0) : l.completeFirst();
|
|
309
|
+
}, ae = (u) => {
|
|
310
|
+
u.key === "Tab" && ie() && (u.preventDefault(), S.current?.focus());
|
|
311
|
+
}, ue = async (u) => {
|
|
312
|
+
He(S.current);
|
|
313
|
+
const g = await l.select(u, { sidekickStore: I, defaultSidecarRenderer: r });
|
|
314
|
+
if (g.isCompletion) {
|
|
315
|
+
S.current?.focus();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
g.isRejected || (g.message && a?.({ message: g.message }), g.shouldReset && O());
|
|
319
|
+
}, Y = /* @__PURE__ */ i(
|
|
320
|
+
b.Input,
|
|
321
|
+
{
|
|
322
|
+
"data-testid": "shortround-input",
|
|
323
|
+
onKeyDown: ae,
|
|
324
|
+
onSelect: se,
|
|
325
|
+
onValueChange: P,
|
|
326
|
+
placeholder: Ne,
|
|
327
|
+
ref: S,
|
|
328
|
+
value: v
|
|
329
|
+
}
|
|
330
|
+
), le = T.canShowHints ? /* @__PURE__ */ i(De, { inputRef: S, lineState: T.lineState, children: Y }) : Y, M = ({ key: u, name: g, intentions: E, style: D, ref: de }) => /* @__PURE__ */ k(b.Group, { ref: de, style: D, children: [
|
|
331
|
+
/* @__PURE__ */ i(c.Group, { name: g }),
|
|
332
|
+
E.map((B) => /* @__PURE__ */ i(
|
|
333
|
+
Ve,
|
|
334
|
+
{
|
|
335
|
+
Item: c.Item,
|
|
336
|
+
iconSources: s,
|
|
337
|
+
intention: B,
|
|
338
|
+
onSelect: ue
|
|
339
|
+
},
|
|
340
|
+
B.id
|
|
341
|
+
))
|
|
342
|
+
] }, u);
|
|
343
|
+
return /* @__PURE__ */ i(c.Frame, { height: f, children: /* @__PURE__ */ k(
|
|
344
|
+
b,
|
|
345
|
+
{
|
|
346
|
+
label: d,
|
|
347
|
+
loop: !0,
|
|
348
|
+
onValueChange: K,
|
|
349
|
+
shouldFilter: !1,
|
|
350
|
+
value: z,
|
|
351
|
+
children: [
|
|
352
|
+
/* @__PURE__ */ i(c.Input, { input: le, inputMessage: R }),
|
|
353
|
+
/* @__PURE__ */ k(
|
|
354
|
+
b.List,
|
|
355
|
+
{
|
|
356
|
+
style: {
|
|
357
|
+
height: `calc(${f} - 107px)`,
|
|
358
|
+
// not sure why 107 works
|
|
359
|
+
overflowY: "auto",
|
|
360
|
+
padding: "8px 0"
|
|
361
|
+
},
|
|
362
|
+
children: [
|
|
363
|
+
/* @__PURE__ */ i(b.Empty, { children: /* @__PURE__ */ i(c.NoMatches, { inputValue: v }) }),
|
|
364
|
+
/* @__PURE__ */ k("div", { style: Ge, children: [
|
|
365
|
+
$.map((u) => M({ key: u.name ?? Ke, ...u })),
|
|
366
|
+
y.length > 0 && M({
|
|
367
|
+
key: ze,
|
|
368
|
+
name: pe,
|
|
369
|
+
intentions: y,
|
|
370
|
+
style: $e,
|
|
371
|
+
ref: x
|
|
372
|
+
})
|
|
373
|
+
] })
|
|
374
|
+
]
|
|
375
|
+
}
|
|
376
|
+
),
|
|
377
|
+
/* @__PURE__ */ i(
|
|
378
|
+
je,
|
|
379
|
+
{
|
|
380
|
+
groupRef: x,
|
|
381
|
+
rowIds: y.map(({ id: u }) => u)
|
|
382
|
+
}
|
|
383
|
+
)
|
|
384
|
+
]
|
|
385
|
+
}
|
|
386
|
+
) });
|
|
387
|
+
}
|
|
388
|
+
function Be({
|
|
389
|
+
title: e,
|
|
390
|
+
palette: t,
|
|
391
|
+
defaultIntentions: n,
|
|
392
|
+
resolveDefaultInput: o,
|
|
393
|
+
resolveDefaultFallbackInput: r,
|
|
394
|
+
SidekickComponents: c,
|
|
395
|
+
showToast: s,
|
|
396
|
+
defaultSidecarRenderer: a,
|
|
397
|
+
disableLineHints: d
|
|
398
|
+
}) {
|
|
399
|
+
const { onClose: h, setSize: l, anchorOrigin: p, cycleAnchorOrigin: w, height: v, size: R, commandWidth: y } = j(), { Sidekick: f, IntentionPalette: O } = c, I = N()?.icons, S = F(
|
|
400
|
+
() => ({ registry: I, themeIcons: c.icons }),
|
|
401
|
+
[I, c.icons]
|
|
402
|
+
);
|
|
403
|
+
return /* @__PURE__ */ i(V.div, { layout: !0, transition: { duration: U, ease: "easeInOut" }, children: /* @__PURE__ */ k(f.Frame, { commandWidth: y, height: v, children: [
|
|
404
|
+
/* @__PURE__ */ i(
|
|
405
|
+
f.ControlBar,
|
|
406
|
+
{
|
|
407
|
+
anchorOrigin: p,
|
|
408
|
+
cycleAnchorOrigin: w,
|
|
409
|
+
labels: Se,
|
|
410
|
+
onClose: h,
|
|
411
|
+
setSize: l,
|
|
412
|
+
size: R,
|
|
413
|
+
title: e
|
|
414
|
+
}
|
|
415
|
+
),
|
|
416
|
+
R !== "compact" && /* @__PURE__ */ i(
|
|
417
|
+
Me,
|
|
418
|
+
{
|
|
419
|
+
IntentionPalette: O,
|
|
420
|
+
defaultIntentions: n,
|
|
421
|
+
defaultSidecarRenderer: a,
|
|
422
|
+
disableLineHints: d,
|
|
423
|
+
iconSources: S,
|
|
424
|
+
label: e ?? oe,
|
|
425
|
+
palette: t,
|
|
426
|
+
resolveDefaultFallbackInput: r,
|
|
427
|
+
resolveDefaultInput: o,
|
|
428
|
+
showToast: s
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
] }) });
|
|
432
|
+
}
|
|
433
|
+
function qe({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
|
|
434
|
+
const c = {
|
|
435
|
+
open: { width: o, pointerEvents: "auto" },
|
|
436
|
+
closed: { width: 0, pointerEvents: "none" }
|
|
437
|
+
};
|
|
438
|
+
return /* @__PURE__ */ i(
|
|
439
|
+
V.div,
|
|
440
|
+
{
|
|
441
|
+
animate: e ? "open" : "closed",
|
|
442
|
+
layout: !0,
|
|
443
|
+
style: { display: "flex", overflow: "hidden", opacity: 1 },
|
|
444
|
+
transition: { duration: U, ease: "easeInOut" },
|
|
445
|
+
variants: c,
|
|
446
|
+
children: /* @__PURE__ */ i(r, { height: n, isOpen: e, renderSidecar: t })
|
|
447
|
+
}
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
function Xe(e, t) {
|
|
451
|
+
const n = m(e), o = m(t);
|
|
452
|
+
o.current = t, C(() => {
|
|
453
|
+
n.current && !e && o.current?.(), n.current = e;
|
|
454
|
+
}, [e]);
|
|
455
|
+
}
|
|
456
|
+
function Je(e, t, { sidecarReducer: n, defaultSidecarRenderer: o, palette: r }) {
|
|
457
|
+
const c = m(n);
|
|
458
|
+
c.current = n;
|
|
459
|
+
const s = m(!1), a = () => r ? r.current().sidecarRenderer : o, d = m(a);
|
|
460
|
+
d.current = a, L(() => (e.setSidecarReducer(
|
|
461
|
+
(...h) => (c.current ?? ((l, p) => p))(...h)
|
|
462
|
+
), () => e.setSidecarReducer(void 0)), [e]), L(() => {
|
|
463
|
+
t && !s.current ? e.changeSidecar({ renderer: d.current() ?? null }, "open") : !t && s.current && e.clearSidecar(), s.current = t;
|
|
464
|
+
}, [e, t]);
|
|
465
|
+
}
|
|
466
|
+
function Qe(e, t) {
|
|
467
|
+
L(() => {
|
|
468
|
+
document.activeElement === document.body && t();
|
|
469
|
+
}, [e, t]);
|
|
470
|
+
}
|
|
471
|
+
const Ze = {
|
|
472
|
+
display: "flex",
|
|
473
|
+
flexDirection: "inherit",
|
|
474
|
+
alignItems: "inherit",
|
|
475
|
+
width: "100%",
|
|
476
|
+
height: "100%"
|
|
477
|
+
}, et = we(function({ name: t, onClose: n, children: o }, r) {
|
|
478
|
+
return /* @__PURE__ */ i(
|
|
479
|
+
"div",
|
|
480
|
+
{
|
|
481
|
+
"aria-label": t,
|
|
482
|
+
"aria-modal": "false",
|
|
483
|
+
onKeyDown: (s) => {
|
|
484
|
+
s.key === "Escape" && !s.defaultPrevented && n();
|
|
485
|
+
},
|
|
486
|
+
ref: r,
|
|
487
|
+
role: "dialog",
|
|
488
|
+
style: Ze,
|
|
489
|
+
tabIndex: -1,
|
|
490
|
+
children: o
|
|
491
|
+
}
|
|
492
|
+
);
|
|
493
|
+
});
|
|
494
|
+
function tt({
|
|
495
|
+
title: e,
|
|
496
|
+
palette: t,
|
|
497
|
+
defaultIntentions: n,
|
|
498
|
+
resolveDefaultInput: o,
|
|
499
|
+
resolveDefaultFallbackInput: r,
|
|
500
|
+
SidekickComponents: c,
|
|
501
|
+
showToast: s,
|
|
502
|
+
installKeyboardShortcuts: a,
|
|
503
|
+
notifyClose: d,
|
|
504
|
+
sidecarReducer: h,
|
|
505
|
+
defaultSidecarRenderer: l,
|
|
506
|
+
disableLineHints: p
|
|
507
|
+
}) {
|
|
508
|
+
const {
|
|
509
|
+
isSidecarOpen: w,
|
|
510
|
+
anchorOrigin: v,
|
|
511
|
+
renderSidecar: R,
|
|
512
|
+
height: y,
|
|
513
|
+
sidecarWidth: f,
|
|
514
|
+
isOpen: O,
|
|
515
|
+
anchorPosition: I,
|
|
516
|
+
totalWidth: S,
|
|
517
|
+
size: x,
|
|
518
|
+
onOpen: G,
|
|
519
|
+
onClose: T
|
|
520
|
+
} = j(), { Sidekick: $, SidecarContent: z } = c, { attachDialog: K, focusInside: P } = be();
|
|
521
|
+
return Ie({
|
|
522
|
+
onOpen: O ? P : G,
|
|
523
|
+
installKeyboardShortcuts: a
|
|
524
|
+
}), Qe(x, P), Xe(O, d), Je(W(), O, {
|
|
525
|
+
sidecarReducer: h,
|
|
526
|
+
defaultSidecarRenderer: l,
|
|
527
|
+
palette: t
|
|
528
|
+
}), O ? /* @__PURE__ */ i(
|
|
529
|
+
V.div,
|
|
530
|
+
{
|
|
531
|
+
animate: {
|
|
532
|
+
width: S
|
|
533
|
+
},
|
|
534
|
+
layout: !0,
|
|
535
|
+
transition: { duration: U, ease: "easeInOut" },
|
|
536
|
+
children: /* @__PURE__ */ i(
|
|
537
|
+
$.Popover,
|
|
538
|
+
{
|
|
539
|
+
anchorOrigin: v,
|
|
540
|
+
anchorPosition: I,
|
|
541
|
+
height: y,
|
|
542
|
+
totalWidth: S,
|
|
543
|
+
children: /* @__PURE__ */ k(et, { name: e ?? oe, onClose: T, ref: K, children: [
|
|
544
|
+
/* @__PURE__ */ i(
|
|
545
|
+
Be,
|
|
546
|
+
{
|
|
547
|
+
SidekickComponents: c,
|
|
548
|
+
defaultIntentions: n,
|
|
549
|
+
defaultSidecarRenderer: l,
|
|
550
|
+
disableLineHints: p,
|
|
551
|
+
palette: t,
|
|
552
|
+
resolveDefaultFallbackInput: r,
|
|
553
|
+
resolveDefaultInput: o,
|
|
554
|
+
showToast: s,
|
|
555
|
+
title: e
|
|
556
|
+
}
|
|
557
|
+
),
|
|
558
|
+
/* @__PURE__ */ i(
|
|
559
|
+
qe,
|
|
560
|
+
{
|
|
561
|
+
Content: z,
|
|
562
|
+
height: y,
|
|
563
|
+
isOpen: w,
|
|
564
|
+
renderSidecar: R,
|
|
565
|
+
width: f
|
|
566
|
+
}
|
|
567
|
+
)
|
|
568
|
+
] })
|
|
569
|
+
}
|
|
570
|
+
)
|
|
571
|
+
}
|
|
572
|
+
) : null;
|
|
573
|
+
}
|
|
574
|
+
function nt(e, t) {
|
|
575
|
+
const n = N(), o = e ?? n?.components;
|
|
576
|
+
if (!o)
|
|
577
|
+
throw new Error(
|
|
578
|
+
"ShortRoundSidekick has no theme: wrap the app in <ShortRoundProvider theme={…}>, or pass SidekickComponents"
|
|
579
|
+
);
|
|
580
|
+
return rt(o), { components: o, showToast: t ?? n?.showToast };
|
|
581
|
+
}
|
|
582
|
+
const ot = ["IntentionPalette", "Sidekick", "SidecarContent"];
|
|
583
|
+
function rt(e) {
|
|
584
|
+
const t = ot.filter((n) => !e[n]);
|
|
585
|
+
if (t.length > 0)
|
|
586
|
+
throw new Error(
|
|
587
|
+
`ShortRoundSidekick: the theme has no ${t.map((n) => `components.${n}`).join(" or ")}`
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
function St({
|
|
591
|
+
title: e,
|
|
592
|
+
palette: t,
|
|
593
|
+
defaultIntentions: n,
|
|
594
|
+
resolveDefaultInput: o,
|
|
595
|
+
resolveDefaultFallbackInput: r,
|
|
596
|
+
SidekickComponents: c,
|
|
597
|
+
showToast: s,
|
|
598
|
+
installKeyboardShortcuts: a,
|
|
599
|
+
sidekickStore: d,
|
|
600
|
+
initialSidekickState: h,
|
|
601
|
+
onClose: l,
|
|
602
|
+
sidecarReducer: p,
|
|
603
|
+
defaultSidecarRenderer: w,
|
|
604
|
+
disableLineHints: v
|
|
605
|
+
}) {
|
|
606
|
+
const R = nt(c, s);
|
|
607
|
+
return /* @__PURE__ */ i(Ee, { initial: h, store: d, children: /* @__PURE__ */ i(
|
|
608
|
+
tt,
|
|
609
|
+
{
|
|
610
|
+
SidekickComponents: R.components,
|
|
611
|
+
defaultIntentions: n,
|
|
612
|
+
defaultSidecarRenderer: w,
|
|
613
|
+
disableLineHints: v,
|
|
614
|
+
installKeyboardShortcuts: a,
|
|
615
|
+
notifyClose: l,
|
|
616
|
+
palette: t,
|
|
617
|
+
resolveDefaultFallbackInput: r,
|
|
618
|
+
resolveDefaultInput: o,
|
|
619
|
+
showToast: R.showToast,
|
|
620
|
+
sidecarReducer: p,
|
|
621
|
+
title: e
|
|
622
|
+
}
|
|
623
|
+
) });
|
|
624
|
+
}
|
|
625
|
+
const ct = { isOpen: !1, message: null };
|
|
626
|
+
function st(e) {
|
|
627
|
+
const t = ["components", "Toast"].filter((n) => !e?.[n]);
|
|
628
|
+
if (t.length > 0)
|
|
629
|
+
throw new Error(`ShortRoundProvider: the theme has no ${t.join(" or ")}`);
|
|
630
|
+
}
|
|
631
|
+
function gt({ theme: e, icons: t, children: n }) {
|
|
632
|
+
st(e);
|
|
633
|
+
const [o, r] = ve(ct), c = _(({ message: h }) => r({ isOpen: !0, message: h }), []), s = _(() => r((h) => ({ ...h, isOpen: !1 })), []), a = F(
|
|
634
|
+
() => ({ components: e.components, showToast: c, icons: t }),
|
|
635
|
+
[e.components, c, t]
|
|
636
|
+
), { Toast: d } = e;
|
|
637
|
+
return /* @__PURE__ */ k(ce.Provider, { value: a, children: [
|
|
638
|
+
n,
|
|
639
|
+
/* @__PURE__ */ i(d, { isOpen: o.isOpen, message: o.message, onClose: s })
|
|
640
|
+
] });
|
|
641
|
+
}
|
|
642
|
+
export {
|
|
643
|
+
De as LineInput,
|
|
644
|
+
gt as ShortRoundProvider,
|
|
645
|
+
St as ShortRoundSidekick,
|
|
646
|
+
Ee as SidekickStoreProvider,
|
|
647
|
+
ft as useShortRound,
|
|
648
|
+
mt as useShortRoundComponents,
|
|
649
|
+
pt as useShortRoundToast,
|
|
650
|
+
j as useSidekick,
|
|
651
|
+
W as useSidekickStore
|
|
652
|
+
};
|