@uipath/apollo-wind 2.86.1 → 2.88.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/dist/components/ui/connection-picker/components/connection-actions-menu.cjs +129 -0
- package/dist/components/ui/connection-picker/components/connection-actions-menu.d.ts +21 -0
- package/dist/components/ui/connection-picker/components/connection-actions-menu.js +95 -0
- package/dist/components/ui/connection-picker/components/connection-status.cjs +81 -0
- package/dist/components/ui/connection-picker/components/connection-status.d.ts +22 -0
- package/dist/components/ui/connection-picker/components/connection-status.js +41 -0
- package/dist/components/ui/connection-picker/connection-picker.cjs +411 -0
- package/dist/components/ui/connection-picker/connection-picker.d.ts +12 -0
- package/dist/components/ui/connection-picker/connection-picker.js +374 -0
- package/dist/components/ui/connection-picker/index.cjs +39 -0
- package/dist/components/ui/connection-picker/index.d.ts +2 -0
- package/dist/components/ui/connection-picker/index.js +2 -0
- package/dist/components/ui/connection-picker/types.cjs +18 -0
- package/dist/components/ui/connection-picker/types.d.ts +124 -0
- package/dist/components/ui/connection-picker/types.js +0 -0
- package/dist/components/ui/field-addons/field-menu.cjs +41 -23
- package/dist/components/ui/field-addons/field-menu.d.ts +2 -0
- package/dist/components/ui/field-addons/field-menu.js +42 -24
- package/dist/components/ui/folder-picker/folder-picker.cjs +4 -3
- package/dist/components/ui/folder-picker/folder-picker.js +4 -3
- package/dist/components/ui/index.cjs +267 -241
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.js +2 -0
- package/dist/components/ui/{folder-picker/components/folder-picker-empty-state.cjs → picker-empty-state.cjs} +11 -11
- package/dist/components/ui/picker-empty-state.d.ts +33 -0
- package/dist/components/ui/{folder-picker/components/folder-picker-empty-state.js → picker-empty-state.js} +9 -9
- package/dist/components/ui/resource-picker/command-value.cjs +48 -0
- package/dist/components/ui/resource-picker/command-value.d.ts +11 -0
- package/dist/components/ui/resource-picker/command-value.js +11 -0
- package/dist/components/ui/resource-picker/components/resource-group-header.cjs +102 -0
- package/dist/components/ui/resource-picker/components/resource-group-header.d.ts +44 -0
- package/dist/components/ui/resource-picker/components/resource-group-header.js +65 -0
- package/dist/components/ui/resource-picker/components/resource-picker-footer.cjs +55 -0
- package/dist/components/ui/resource-picker/components/resource-picker-footer.d.ts +14 -0
- package/dist/components/ui/resource-picker/components/resource-picker-footer.js +21 -0
- package/dist/components/ui/resource-picker/components/resource-row-actions-menu.cjs +136 -0
- package/dist/components/ui/resource-picker/components/resource-row-actions-menu.d.ts +30 -0
- package/dist/components/ui/resource-picker/components/resource-row-actions-menu.js +102 -0
- package/dist/components/ui/resource-picker/components/resource-row.cjs +115 -0
- package/dist/components/ui/resource-picker/components/resource-row.d.ts +16 -0
- package/dist/components/ui/resource-picker/components/resource-row.js +81 -0
- package/dist/components/ui/resource-picker/focus.cjs +66 -0
- package/dist/components/ui/resource-picker/focus.d.ts +1 -0
- package/dist/components/ui/resource-picker/focus.js +32 -0
- package/dist/components/ui/resource-picker/index.cjs +42 -0
- package/dist/components/ui/resource-picker/index.d.ts +2 -0
- package/dist/components/ui/resource-picker/index.js +2 -0
- package/dist/components/ui/resource-picker/resource-picker.cjs +606 -0
- package/dist/components/ui/resource-picker/resource-picker.d.ts +40 -0
- package/dist/components/ui/resource-picker/resource-picker.js +566 -0
- package/dist/components/ui/resource-picker/types.cjs +50 -0
- package/dist/components/ui/resource-picker/types.d.ts +209 -0
- package/dist/components/ui/resource-picker/types.js +16 -0
- package/dist/index.cjs +24 -7
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -1
- package/dist/styles.css +75 -29
- package/package.json +1 -1
- package/dist/components/ui/folder-picker/components/folder-picker-empty-state.d.ts +0 -26
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCommandState } from "cmdk";
|
|
4
|
+
import { ChevronDown, X } from "lucide-react";
|
|
5
|
+
import { cloneElement, forwardRef, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { Command, CommandInput, CommandList } from "../command.js";
|
|
7
|
+
import { FIELD_ADDON_BUTTON_CLASS } from "../field-addons/field-addon-button.js";
|
|
8
|
+
import { FormFieldError } from "../form-field.js";
|
|
9
|
+
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupPopoverTrigger } from "../input-group.js";
|
|
10
|
+
import { InputGroupContext, NO_GROUP, controlValidation, useControlValidation, useInputGroup } from "../input-group-context.js";
|
|
11
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../popover.js";
|
|
12
|
+
import { cn, composeRefs } from "../../../lib/index.js";
|
|
13
|
+
import { PickerEmptyState } from "../picker-empty-state.js";
|
|
14
|
+
import { fromCommandValue } from "./command-value.js";
|
|
15
|
+
import { ResourceGroupHeader, ResourceGroupHeadingOption } from "./components/resource-group-header.js";
|
|
16
|
+
import { ResourcePickerFooter } from "./components/resource-picker-footer.js";
|
|
17
|
+
import { ResourceRow } from "./components/resource-row.js";
|
|
18
|
+
import { ResourceRowActionsMenu } from "./components/resource-row-actions-menu.js";
|
|
19
|
+
import { focusBeside } from "./focus.js";
|
|
20
|
+
import { filterGroups } from "./types.js";
|
|
21
|
+
const PICKER_VALUE_PREFIX = '\uE000resource-picker:';
|
|
22
|
+
const collapsedValue = (groupId)=>`${PICKER_VALUE_PREFIX}collapsed:${groupId}`;
|
|
23
|
+
const openHeadingValue = (groupId)=>`${PICKER_VALUE_PREFIX}open:${groupId}`;
|
|
24
|
+
const hasEnabledRow = (group)=>group.items.some((item)=>!item.disabled);
|
|
25
|
+
const defaultCollapsedGroupLabel = (label)=>`${label}, collapsed`;
|
|
26
|
+
const defaultActionsMenuLabel = (label)=>`Actions for ${label}`;
|
|
27
|
+
const defaultExpandedGroupLabel = (label)=>`${label}, expanded`;
|
|
28
|
+
function CursorPlacer({ target, rootRef, placing }) {
|
|
29
|
+
const current = useCommandState((state)=>state.value);
|
|
30
|
+
useLayoutEffect(()=>{
|
|
31
|
+
if (null === target || fromCommandValue(current) === target) return;
|
|
32
|
+
queueMicrotask(()=>placeCursor(rootRef.current, placing, (value)=>value === target));
|
|
33
|
+
});
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const rowValue = (element)=>fromCommandValue(element.getAttribute('data-value'));
|
|
37
|
+
function placeCursor(root, placing, accept) {
|
|
38
|
+
const row = Array.from(root?.querySelectorAll('[cmdk-item]') ?? []).find((item)=>'true' !== item.getAttribute('aria-disabled') && accept(rowValue(item)));
|
|
39
|
+
if (!row) return;
|
|
40
|
+
placing.current = true;
|
|
41
|
+
row.dispatchEvent(new MouseEvent('pointermove', {
|
|
42
|
+
bubbles: true
|
|
43
|
+
}));
|
|
44
|
+
placing.current = false;
|
|
45
|
+
}
|
|
46
|
+
function ResourcePickerContent({ groups, onSelect, value, searchPlaceholder = 'Search...', initialSearch = '', query: controlledQuery, onQueryChange, emptyText = 'No matches.', loading = false, loadingText, loadError, onRetry, retryLabel, noMatchText, collapsedGroupLabel = defaultCollapsedGroupLabel, expandedGroupLabel = defaultExpandedGroupLabel, listLabel = 'Resources', showCounts = true, locale, formatCount, itemActions, actionsMenuLabel = defaultActionsMenuLabel, onTabOut, footerLeading, footerTrailing, className }) {
|
|
47
|
+
const [uncontrolledQuery, setUncontrolledQuery] = useState(initialSearch);
|
|
48
|
+
const query = controlledQuery ?? uncontrolledQuery;
|
|
49
|
+
const queryReadOnly = void 0 !== controlledQuery && !onQueryChange;
|
|
50
|
+
const [collapsedIds, setCollapsedIds] = useState(()=>new Set(groups.filter((group)=>group.defaultCollapsed).map((group)=>group.id)));
|
|
51
|
+
const [seenIds, setSeenIds] = useState(()=>new Set(groups.map((group)=>group.id)));
|
|
52
|
+
const newGroups = groups.filter((group)=>!seenIds.has(group.id));
|
|
53
|
+
if (newGroups.length > 0) {
|
|
54
|
+
setSeenIds(new Set([
|
|
55
|
+
...seenIds,
|
|
56
|
+
...newGroups.map((group)=>group.id)
|
|
57
|
+
]));
|
|
58
|
+
const collapsedNew = newGroups.filter((group)=>group.defaultCollapsed);
|
|
59
|
+
if (collapsedNew.length > 0) setCollapsedIds((current)=>new Set([
|
|
60
|
+
...current,
|
|
61
|
+
...collapsedNew.map((group)=>group.id)
|
|
62
|
+
]));
|
|
63
|
+
}
|
|
64
|
+
const setQuery = (nextQuery)=>{
|
|
65
|
+
if (void 0 === controlledQuery) setUncontrolledQuery(nextQuery);
|
|
66
|
+
onQueryChange?.(nextQuery);
|
|
67
|
+
};
|
|
68
|
+
useEffect(()=>{
|
|
69
|
+
if ("u" < typeof process || 'production' === process.env.NODE_ENV) return;
|
|
70
|
+
if (groups.some((group)=>group.items.some((item)=>'' === item.id))) console.warn('ResourcePicker: dropped rows with an empty id, which the picker reserves for no selection.');
|
|
71
|
+
}, [
|
|
72
|
+
groups
|
|
73
|
+
]);
|
|
74
|
+
const groupIdBase = useId();
|
|
75
|
+
const visibleGroups = useMemo(()=>filterGroups(groups, query, locale), [
|
|
76
|
+
groups,
|
|
77
|
+
query,
|
|
78
|
+
locale
|
|
79
|
+
]);
|
|
80
|
+
const countFormatter = useMemo(()=>{
|
|
81
|
+
if (formatCount) return formatCount;
|
|
82
|
+
if (!locale) return String;
|
|
83
|
+
const numberFormat = new Intl.NumberFormat(locale);
|
|
84
|
+
return (count)=>numberFormat.format(count);
|
|
85
|
+
}, [
|
|
86
|
+
formatCount,
|
|
87
|
+
locale
|
|
88
|
+
]);
|
|
89
|
+
const filtering = query.trim().length > 0;
|
|
90
|
+
const hasRows = useMemo(()=>filterGroups(groups, '').length > 0, [
|
|
91
|
+
groups
|
|
92
|
+
]);
|
|
93
|
+
const rootRef = useRef(null);
|
|
94
|
+
const activeValue = ()=>{
|
|
95
|
+
const active = rootRef.current?.querySelector('[cmdk-item][aria-selected="true"]');
|
|
96
|
+
return active ? rowValue(active) : '';
|
|
97
|
+
};
|
|
98
|
+
const [cursorTarget, setCursorTarget] = useState(null);
|
|
99
|
+
const placingCursor = useRef(false);
|
|
100
|
+
const [openMenu, setOpenMenu] = useState(null);
|
|
101
|
+
const shownGroups = visibleGroups.filter((group)=>filtering || !collapsedIds.has(group.id));
|
|
102
|
+
const shownRows = shownGroups.flatMap((group)=>group.items);
|
|
103
|
+
const groupOfRow = (id)=>shownGroups.find((group)=>group.items.some((row)=>row.id === id))?.id;
|
|
104
|
+
const menuFor = (id, groupId)=>{
|
|
105
|
+
if (null === id || !itemActions) return null;
|
|
106
|
+
if (void 0 !== groupId && groupOfRow(id) !== groupId) return null;
|
|
107
|
+
const item = shownRows.find((row)=>row.id === id);
|
|
108
|
+
if (!item || item.disabled) return null;
|
|
109
|
+
const anchor = Array.from(rootRef.current?.querySelectorAll('[cmdk-item]') ?? []).find((row)=>rowValue(row) === id);
|
|
110
|
+
if (!anchor) return null;
|
|
111
|
+
const actions = itemActions(item);
|
|
112
|
+
return actions.length > 0 ? {
|
|
113
|
+
item,
|
|
114
|
+
actions,
|
|
115
|
+
anchor
|
|
116
|
+
} : null;
|
|
117
|
+
};
|
|
118
|
+
const actionsMenu = openMenu && menuFor(openMenu.id, openMenu.groupId);
|
|
119
|
+
const searchInput = ()=>rootRef.current?.querySelector('[data-slot="resource-picker-search"]');
|
|
120
|
+
const actionsMenuGone = null !== openMenu && null === actionsMenu;
|
|
121
|
+
useLayoutEffect(()=>{
|
|
122
|
+
if (!actionsMenuGone) return;
|
|
123
|
+
setOpenMenu(null);
|
|
124
|
+
const root = rootRef.current;
|
|
125
|
+
if (!root) return;
|
|
126
|
+
const active = root.getRootNode().activeElement;
|
|
127
|
+
if (active && active !== root.ownerDocument.body) return;
|
|
128
|
+
root.querySelector('[data-slot="resource-picker-search"]')?.focus();
|
|
129
|
+
}, [
|
|
130
|
+
actionsMenuGone
|
|
131
|
+
]);
|
|
132
|
+
const openActionsMenu = ()=>{
|
|
133
|
+
const active = activeValue();
|
|
134
|
+
const groupId = groupOfRow(active);
|
|
135
|
+
if (void 0 === groupId || !menuFor(active)) return false;
|
|
136
|
+
setOpenMenu({
|
|
137
|
+
id: active,
|
|
138
|
+
groupId
|
|
139
|
+
});
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
const leaveActionsMenu = (backwards)=>{
|
|
143
|
+
const anchor = actionsMenu?.anchor;
|
|
144
|
+
const root = rootRef.current;
|
|
145
|
+
setOpenMenu(null);
|
|
146
|
+
if (!anchor || !root) return;
|
|
147
|
+
if (focusBeside(anchor, backwards, root)) return;
|
|
148
|
+
if (!backwards && onTabOut) return void onTabOut();
|
|
149
|
+
if (!backwards && focusBeside(root, false)) return;
|
|
150
|
+
searchInput()?.focus();
|
|
151
|
+
};
|
|
152
|
+
const closeActionsMenu = (restoreFocus)=>{
|
|
153
|
+
setOpenMenu(null);
|
|
154
|
+
if (restoreFocus) searchInput()?.focus();
|
|
155
|
+
};
|
|
156
|
+
const setCollapsed = (id, collapse)=>{
|
|
157
|
+
if (filtering) return;
|
|
158
|
+
setCollapsedIds((current)=>{
|
|
159
|
+
const next = new Set(current);
|
|
160
|
+
if (collapse) next.add(id);
|
|
161
|
+
else next.delete(id);
|
|
162
|
+
return next;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const changeGroup = (leaving, target)=>{
|
|
166
|
+
const active = activeValue();
|
|
167
|
+
if ('' !== active && leaving(active)) placeCursor(rootRef.current, placingCursor, (value)=>!leaving(value));
|
|
168
|
+
if (void 0 !== target) setCursorTarget(target);
|
|
169
|
+
};
|
|
170
|
+
const collapseGroup = (group)=>{
|
|
171
|
+
if (filtering) return;
|
|
172
|
+
const leaving = new Set([
|
|
173
|
+
...group.items.map((item)=>item.id),
|
|
174
|
+
openHeadingValue(group.id)
|
|
175
|
+
]);
|
|
176
|
+
changeGroup((value)=>leaving.has(value), collapsedValue(group.id));
|
|
177
|
+
setCollapsed(group.id, true);
|
|
178
|
+
};
|
|
179
|
+
const expandGroup = (group)=>{
|
|
180
|
+
if (filtering) return;
|
|
181
|
+
const standIn = collapsedValue(group.id);
|
|
182
|
+
const target = group.items.find((item)=>!item.disabled)?.id ?? openHeadingValue(group.id);
|
|
183
|
+
changeGroup((value)=>value === standIn, target);
|
|
184
|
+
setCollapsed(group.id, false);
|
|
185
|
+
};
|
|
186
|
+
const handleGroupKeys = (event)=>{
|
|
187
|
+
if ('ArrowLeft' !== event.key && 'ArrowRight' !== event.key) return;
|
|
188
|
+
if (!(event.target instanceof HTMLInputElement) || 'resource-picker-search' !== event.target.dataset.slot) return;
|
|
189
|
+
if (filtering || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
190
|
+
const active = activeValue();
|
|
191
|
+
for (const group of visibleGroups){
|
|
192
|
+
const collapsed = collapsedIds.has(group.id);
|
|
193
|
+
if ('ArrowRight' === event.key && collapsed && active === collapsedValue(group.id)) {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
expandGroup(group);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if ('ArrowLeft' === event.key && !collapsed && (active === openHeadingValue(group.id) || group.items.some((item)=>item.id === active))) {
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
collapseGroup(group);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
return /*#__PURE__*/ jsxs(Command, {
|
|
206
|
+
loop: true,
|
|
207
|
+
shouldFilter: false,
|
|
208
|
+
"data-slot": "resource-picker",
|
|
209
|
+
"data-query-readonly": queryReadOnly ? '' : void 0,
|
|
210
|
+
className: cn('flex max-h-80 min-w-0 flex-col overflow-hidden bg-popover', className),
|
|
211
|
+
label: listLabel,
|
|
212
|
+
ref: rootRef,
|
|
213
|
+
onPointerMoveCapture: ()=>{
|
|
214
|
+
if (!placingCursor.current && null !== cursorTarget) setCursorTarget(null);
|
|
215
|
+
},
|
|
216
|
+
onKeyDown: (event)=>{
|
|
217
|
+
if (null !== cursorTarget) setCursorTarget(null);
|
|
218
|
+
handleGroupKeys(event);
|
|
219
|
+
if ('Enter' === event.key && event.shiftKey && openActionsMenu()) return void event.preventDefault();
|
|
220
|
+
if ('Escape' === event.key && query && !queryReadOnly) {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
setQuery('');
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
children: [
|
|
227
|
+
/*#__PURE__*/ jsx(CommandInput, {
|
|
228
|
+
"data-slot": "resource-picker-search",
|
|
229
|
+
value: query,
|
|
230
|
+
onValueChange: setQuery,
|
|
231
|
+
readOnly: queryReadOnly,
|
|
232
|
+
placeholder: searchPlaceholder
|
|
233
|
+
}),
|
|
234
|
+
/*#__PURE__*/ jsx("div", {
|
|
235
|
+
role: "status",
|
|
236
|
+
onKeyDown: (event)=>{
|
|
237
|
+
if ('Escape' !== event.key && 'Tab' !== event.key) event.stopPropagation();
|
|
238
|
+
},
|
|
239
|
+
children: 0 === visibleGroups.length && /*#__PURE__*/ jsx(PickerEmptyState, {
|
|
240
|
+
announce: false,
|
|
241
|
+
error: loadError,
|
|
242
|
+
loading: loading,
|
|
243
|
+
query: hasRows ? query.trim() : '',
|
|
244
|
+
emptyText: emptyText,
|
|
245
|
+
noMatchText: noMatchText,
|
|
246
|
+
loadingText: loadingText,
|
|
247
|
+
onRetry: onRetry && (()=>{
|
|
248
|
+
rootRef.current?.querySelector('input[data-slot="resource-picker-search"]')?.focus();
|
|
249
|
+
onRetry();
|
|
250
|
+
}),
|
|
251
|
+
retryLabel: retryLabel
|
|
252
|
+
})
|
|
253
|
+
}),
|
|
254
|
+
/*#__PURE__*/ jsx(CommandList, {
|
|
255
|
+
label: listLabel,
|
|
256
|
+
className: "min-h-0 flex-1",
|
|
257
|
+
children: visibleGroups.map((group, index)=>{
|
|
258
|
+
const collapsed = !filtering && collapsedIds.has(group.id);
|
|
259
|
+
const labelId = `${groupIdBase}-group-${index}`;
|
|
260
|
+
const heading = {
|
|
261
|
+
label: group.label,
|
|
262
|
+
labelId,
|
|
263
|
+
count: countFormatter(group.items.length),
|
|
264
|
+
showCount: showCounts,
|
|
265
|
+
icon: group.icon
|
|
266
|
+
};
|
|
267
|
+
return /*#__PURE__*/ jsx("div", {
|
|
268
|
+
role: "group",
|
|
269
|
+
"aria-labelledby": labelId,
|
|
270
|
+
children: collapsed ? /*#__PURE__*/ jsx(ResourceGroupHeadingOption, {
|
|
271
|
+
...heading,
|
|
272
|
+
collapsed: true,
|
|
273
|
+
value: collapsedValue(group.id),
|
|
274
|
+
ariaLabel: collapsedGroupLabel(group.label),
|
|
275
|
+
onToggle: ()=>expandGroup(group)
|
|
276
|
+
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
277
|
+
children: [
|
|
278
|
+
filtering || hasEnabledRow(group) ? /*#__PURE__*/ jsx(ResourceGroupHeader, {
|
|
279
|
+
...heading,
|
|
280
|
+
collapsed: false,
|
|
281
|
+
disabled: filtering,
|
|
282
|
+
onToggle: ()=>collapseGroup(group)
|
|
283
|
+
}) : /*#__PURE__*/ jsx(ResourceGroupHeadingOption, {
|
|
284
|
+
...heading,
|
|
285
|
+
collapsed: false,
|
|
286
|
+
value: openHeadingValue(group.id),
|
|
287
|
+
ariaLabel: expandedGroupLabel(group.label),
|
|
288
|
+
onToggle: ()=>collapseGroup(group)
|
|
289
|
+
}),
|
|
290
|
+
group.items.map((item)=>/*#__PURE__*/ jsx(ResourceRow, {
|
|
291
|
+
item: item,
|
|
292
|
+
chosen: item.id === value,
|
|
293
|
+
onSelect: ()=>!item.disabled && onSelect(item),
|
|
294
|
+
actions: itemActions?.(item)
|
|
295
|
+
}, item.id))
|
|
296
|
+
]
|
|
297
|
+
})
|
|
298
|
+
}, group.id);
|
|
299
|
+
})
|
|
300
|
+
}),
|
|
301
|
+
/*#__PURE__*/ jsx(ResourcePickerFooter, {
|
|
302
|
+
leading: footerLeading,
|
|
303
|
+
trailing: footerTrailing
|
|
304
|
+
}),
|
|
305
|
+
/*#__PURE__*/ jsx(CursorPlacer, {
|
|
306
|
+
target: cursorTarget,
|
|
307
|
+
rootRef: rootRef,
|
|
308
|
+
placing: placingCursor
|
|
309
|
+
}),
|
|
310
|
+
actionsMenu && /*#__PURE__*/ jsx(ResourceRowActionsMenu, {
|
|
311
|
+
anchor: actionsMenu.anchor,
|
|
312
|
+
label: actionsMenuLabel(actionsMenu.item.label),
|
|
313
|
+
actions: actionsMenu.actions,
|
|
314
|
+
onClose: closeActionsMenu,
|
|
315
|
+
onTabOut: leaveActionsMenu
|
|
316
|
+
})
|
|
317
|
+
]
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function keepResourceSearchOnEscape(event) {
|
|
321
|
+
const target = event.composedPath?.()[0] ?? event.target;
|
|
322
|
+
if (!(target instanceof Element)) return;
|
|
323
|
+
const picker = target.closest('[data-slot="resource-picker"]');
|
|
324
|
+
if (!picker || picker.hasAttribute('data-query-readonly')) return;
|
|
325
|
+
const search = picker.querySelector('input[data-slot="resource-picker-search"]');
|
|
326
|
+
if (search?.value) event.preventDefault();
|
|
327
|
+
}
|
|
328
|
+
const WARNING_FIELD_CLASS = 'border-warning future:ring-1 future:ring-warning/40';
|
|
329
|
+
function ResourcePickerField({ groups, onSelect, onClear, value = '', placeholder = 'Select...', disabled: disabledProp = false, clearable = true, clearAriaLabel = 'Clear selection', icon, children, align = 'start', open: controlledOpen, onOpenChange, trailingAdornment, error, errorId, warning = false, contentClassName, className, id, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-errormessage': ariaErrorMessage, ...contentProps }, forwardedRef) {
|
|
330
|
+
const outerGroup = useInputGroup();
|
|
331
|
+
const grouped = outerGroup.inGroup;
|
|
332
|
+
const disabled = disabledProp || Boolean(outerGroup.disabled);
|
|
333
|
+
const pickerGroup = useMemo(()=>disabled && !outerGroup.disabled ? {
|
|
334
|
+
...outerGroup,
|
|
335
|
+
disabled
|
|
336
|
+
} : outerGroup, [
|
|
337
|
+
outerGroup,
|
|
338
|
+
disabled
|
|
339
|
+
]);
|
|
340
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
341
|
+
const requestedOpen = controlledOpen ?? uncontrolledOpen;
|
|
342
|
+
const open = !disabled && requestedOpen;
|
|
343
|
+
const closedByDisable = disabled && requestedOpen;
|
|
344
|
+
useEffect(()=>{
|
|
345
|
+
if (!closedByDisable) return;
|
|
346
|
+
setUncontrolledOpen(false);
|
|
347
|
+
onOpenChange?.(false);
|
|
348
|
+
}, [
|
|
349
|
+
closedByDisable
|
|
350
|
+
]);
|
|
351
|
+
const contentRef = useRef(null);
|
|
352
|
+
const triggerRef = useRef(null);
|
|
353
|
+
const attachTrigger = useMemo(()=>composeRefs(triggerRef, forwardedRef), [
|
|
354
|
+
forwardedRef
|
|
355
|
+
]);
|
|
356
|
+
const fieldRef = useRef(null);
|
|
357
|
+
const tabbingOut = useRef(false);
|
|
358
|
+
const setOpen = (nextOpen)=>{
|
|
359
|
+
if (nextOpen && disabled) return;
|
|
360
|
+
if (void 0 === controlledOpen) setUncontrolledOpen(nextOpen);
|
|
361
|
+
onOpenChange?.(nextOpen);
|
|
362
|
+
};
|
|
363
|
+
const selected = useMemo(()=>{
|
|
364
|
+
if (!value) return null;
|
|
365
|
+
for (const group of groups){
|
|
366
|
+
const hit = group.items.find((item)=>item.id === value);
|
|
367
|
+
if (hit) return hit;
|
|
368
|
+
}
|
|
369
|
+
return null;
|
|
370
|
+
}, [
|
|
371
|
+
groups,
|
|
372
|
+
value
|
|
373
|
+
]);
|
|
374
|
+
const showClear = Boolean(clearable && onClear && value && !disabled && !children);
|
|
375
|
+
const showAdornment = Boolean(trailingAdornment) && !children;
|
|
376
|
+
const valueId = useId();
|
|
377
|
+
const generatedErrorId = useId();
|
|
378
|
+
const validationId = errorId ?? `resource-picker-${generatedErrorId.replace(/:/g, '')}-error`;
|
|
379
|
+
const externallyLabelled = Boolean(id || ariaLabelledBy);
|
|
380
|
+
const unmatchedValueHidden = Boolean(value) && !selected && placeholder !== value;
|
|
381
|
+
const describeValue = Boolean(value) && (externallyLabelled || unmatchedValueHidden);
|
|
382
|
+
const describedBy = [
|
|
383
|
+
ariaDescribedBy,
|
|
384
|
+
describeValue ? valueId : void 0
|
|
385
|
+
].filter(Boolean).join(' ') || void 0;
|
|
386
|
+
const fieldElement = ()=>fieldRef.current ?? triggerRef.current?.closest('[data-slot="input-group"]') ?? triggerRef.current;
|
|
387
|
+
const blockDisabledTrigger = disabled && void 0 !== children;
|
|
388
|
+
const triggerOwn = children?.props ?? {};
|
|
389
|
+
const customTriggerAria = void 0 !== children ? {
|
|
390
|
+
...controlValidation(NO_GROUP, {
|
|
391
|
+
error,
|
|
392
|
+
errorId: validationId,
|
|
393
|
+
'aria-invalid': ariaInvalid ?? triggerOwn['aria-invalid'],
|
|
394
|
+
'aria-describedby': [
|
|
395
|
+
triggerOwn['aria-describedby'],
|
|
396
|
+
ariaDescribedBy
|
|
397
|
+
].filter(Boolean).join(' ') || void 0,
|
|
398
|
+
'aria-errormessage': ariaErrorMessage ?? triggerOwn['aria-errormessage']
|
|
399
|
+
}),
|
|
400
|
+
'aria-disabled': disabled ? true : triggerOwn['aria-disabled']
|
|
401
|
+
} : void 0;
|
|
402
|
+
const popover = /*#__PURE__*/ jsxs(Popover, {
|
|
403
|
+
open: open,
|
|
404
|
+
onOpenChange: setOpen,
|
|
405
|
+
children: [
|
|
406
|
+
void 0 !== children ? /*#__PURE__*/ jsx(PopoverTrigger, {
|
|
407
|
+
ref: forwardedRef,
|
|
408
|
+
asChild: true,
|
|
409
|
+
disabled: disabled,
|
|
410
|
+
children: children && customTriggerAria ? /*#__PURE__*/ cloneElement(children, customTriggerAria) : children
|
|
411
|
+
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
412
|
+
children: [
|
|
413
|
+
icon && /*#__PURE__*/ jsx(InputGroupAddon, {
|
|
414
|
+
align: "inline-start",
|
|
415
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
416
|
+
"aria-hidden": true,
|
|
417
|
+
className: "grid size-4 shrink-0 place-items-center text-foreground-muted",
|
|
418
|
+
children: icon
|
|
419
|
+
})
|
|
420
|
+
}),
|
|
421
|
+
/*#__PURE__*/ jsx(resource_picker_ResourcePickerTrigger, {
|
|
422
|
+
ref: attachTrigger,
|
|
423
|
+
id: id,
|
|
424
|
+
open: open,
|
|
425
|
+
disabled: disabled,
|
|
426
|
+
label: selected ? selected.fieldLabel ?? selected.label : void 0,
|
|
427
|
+
labelId: valueId,
|
|
428
|
+
placeholder: placeholder,
|
|
429
|
+
className: grouped ? className : void 0,
|
|
430
|
+
error: error,
|
|
431
|
+
errorId: validationId,
|
|
432
|
+
"aria-labelledby": ariaLabelledBy,
|
|
433
|
+
"aria-describedby": describedBy,
|
|
434
|
+
"aria-invalid": ariaInvalid,
|
|
435
|
+
"aria-errormessage": ariaErrorMessage
|
|
436
|
+
}),
|
|
437
|
+
!selected && value && /*#__PURE__*/ jsx("span", {
|
|
438
|
+
id: valueId,
|
|
439
|
+
hidden: true,
|
|
440
|
+
children: value
|
|
441
|
+
}),
|
|
442
|
+
/*#__PURE__*/ jsxs(InputGroupAddon, {
|
|
443
|
+
align: "inline-end",
|
|
444
|
+
children: [
|
|
445
|
+
showClear && /*#__PURE__*/ jsx(InputGroupButton, {
|
|
446
|
+
size: "3xs",
|
|
447
|
+
"aria-label": clearAriaLabel,
|
|
448
|
+
className: cn(FIELD_ADDON_BUTTON_CLASS, 'opacity-0 transition-opacity focus-visible:opacity-100 group-hover/input-group:opacity-100 group-has-[[data-slot=input-group-control]:focus-visible]/input-group:opacity-100'),
|
|
449
|
+
onClick: ()=>{
|
|
450
|
+
onClear?.();
|
|
451
|
+
triggerRef.current?.focus();
|
|
452
|
+
},
|
|
453
|
+
children: /*#__PURE__*/ jsx(X, {})
|
|
454
|
+
}),
|
|
455
|
+
/*#__PURE__*/ jsx("span", {
|
|
456
|
+
"aria-hidden": true,
|
|
457
|
+
"data-slot": "resource-picker-caret",
|
|
458
|
+
className: "grid size-4 shrink-0 cursor-pointer place-items-center text-muted-foreground",
|
|
459
|
+
onClick: ()=>setOpen(!open),
|
|
460
|
+
children: /*#__PURE__*/ jsx(ChevronDown, {
|
|
461
|
+
className: "size-4"
|
|
462
|
+
})
|
|
463
|
+
}),
|
|
464
|
+
showAdornment && trailingAdornment
|
|
465
|
+
]
|
|
466
|
+
})
|
|
467
|
+
]
|
|
468
|
+
}),
|
|
469
|
+
/*#__PURE__*/ jsx(PopoverContent, {
|
|
470
|
+
align: align,
|
|
471
|
+
sideOffset: 4,
|
|
472
|
+
className: cn('w-(--radix-popover-trigger-width) min-w-72 overflow-hidden p-0', contentClassName),
|
|
473
|
+
ref: contentRef,
|
|
474
|
+
"aria-label": contentProps.listLabel ?? 'Resources',
|
|
475
|
+
onEscapeKeyDown: keepResourceSearchOnEscape,
|
|
476
|
+
onInteractOutside: (event)=>{
|
|
477
|
+
const target = event.detail.originalEvent.composedPath()[0] ?? event.target;
|
|
478
|
+
if (target instanceof Element && target.closest('[data-slot="resource-picker-caret"]')) event.preventDefault();
|
|
479
|
+
},
|
|
480
|
+
onOpenAutoFocus: (event)=>{
|
|
481
|
+
event.preventDefault();
|
|
482
|
+
contentRef.current?.querySelector('input')?.focus();
|
|
483
|
+
},
|
|
484
|
+
onCloseAutoFocus: (event)=>{
|
|
485
|
+
if (!tabbingOut.current) return;
|
|
486
|
+
tabbingOut.current = false;
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
const field = fieldElement();
|
|
489
|
+
if (field) focusBeside(field, false);
|
|
490
|
+
},
|
|
491
|
+
children: /*#__PURE__*/ jsx(ResourcePickerContent, {
|
|
492
|
+
...contentProps,
|
|
493
|
+
itemActions: open ? contentProps.itemActions : void 0,
|
|
494
|
+
onRetry: open ? contentProps.onRetry : void 0,
|
|
495
|
+
onTabOut: ()=>{
|
|
496
|
+
tabbingOut.current = true;
|
|
497
|
+
setOpen(false);
|
|
498
|
+
},
|
|
499
|
+
groups: groups,
|
|
500
|
+
value: value,
|
|
501
|
+
onSelect: (item)=>{
|
|
502
|
+
if (!open) return;
|
|
503
|
+
onSelect(item);
|
|
504
|
+
setOpen(false);
|
|
505
|
+
}
|
|
506
|
+
})
|
|
507
|
+
})
|
|
508
|
+
]
|
|
509
|
+
});
|
|
510
|
+
if (void 0 !== children) return /*#__PURE__*/ jsxs("div", {
|
|
511
|
+
ref: fieldRef,
|
|
512
|
+
className: cn('min-w-0', className),
|
|
513
|
+
onClickCapture: blockDisabledTrigger ? (event)=>{
|
|
514
|
+
event.preventDefault();
|
|
515
|
+
event.stopPropagation();
|
|
516
|
+
} : void 0,
|
|
517
|
+
children: [
|
|
518
|
+
popover,
|
|
519
|
+
/*#__PURE__*/ jsx(FormFieldError, {
|
|
520
|
+
id: validationId,
|
|
521
|
+
children: error
|
|
522
|
+
})
|
|
523
|
+
]
|
|
524
|
+
});
|
|
525
|
+
if (grouped) return /*#__PURE__*/ jsx(InputGroupContext.Provider, {
|
|
526
|
+
value: pickerGroup,
|
|
527
|
+
children: popover
|
|
528
|
+
});
|
|
529
|
+
return /*#__PURE__*/ jsx(InputGroup, {
|
|
530
|
+
ref: fieldRef,
|
|
531
|
+
errorId: validationId,
|
|
532
|
+
disabled: disabled,
|
|
533
|
+
className: cn('min-w-0', warning && !error && true !== ariaInvalid && 'true' !== ariaInvalid && WARNING_FIELD_CLASS, className),
|
|
534
|
+
children: popover
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
const ResourcePicker = /*#__PURE__*/ forwardRef(ResourcePickerField);
|
|
538
|
+
ResourcePicker.displayName = 'ResourcePicker';
|
|
539
|
+
const resource_picker_ResourcePickerTrigger = /*#__PURE__*/ forwardRef(function({ id, open, disabled, label, labelId, placeholder, className, error, errorId, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-errormessage': ariaErrorMessage }, ref) {
|
|
540
|
+
const group = useInputGroup();
|
|
541
|
+
const validation = useControlValidation(group, {
|
|
542
|
+
error,
|
|
543
|
+
errorId,
|
|
544
|
+
'aria-invalid': ariaInvalid,
|
|
545
|
+
'aria-describedby': ariaDescribedBy,
|
|
546
|
+
'aria-errormessage': ariaErrorMessage
|
|
547
|
+
});
|
|
548
|
+
return /*#__PURE__*/ jsx(InputGroupPopoverTrigger, {
|
|
549
|
+
ref: ref,
|
|
550
|
+
id: id,
|
|
551
|
+
disabled: disabled,
|
|
552
|
+
"aria-haspopup": "dialog",
|
|
553
|
+
"aria-expanded": open,
|
|
554
|
+
"aria-labelledby": ariaLabelledBy,
|
|
555
|
+
...validation.aria,
|
|
556
|
+
placeholder: placeholder,
|
|
557
|
+
caret: false,
|
|
558
|
+
className: className,
|
|
559
|
+
children: void 0 !== label && /*#__PURE__*/ jsx("span", {
|
|
560
|
+
id: labelId,
|
|
561
|
+
className: "min-w-0 flex-1 truncate",
|
|
562
|
+
children: label
|
|
563
|
+
})
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
export { ResourcePicker, ResourcePickerContent, keepResourceSearchOnEscape };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
filterGroups: ()=>filterGroups
|
|
28
|
+
});
|
|
29
|
+
const hasId = (item)=>'' !== item.id;
|
|
30
|
+
const filterGroups = (allGroups, query, locale)=>{
|
|
31
|
+
const groups = allGroups.map((group)=>group.items.every(hasId) ? group : {
|
|
32
|
+
...group,
|
|
33
|
+
items: group.items.filter(hasId)
|
|
34
|
+
});
|
|
35
|
+
const fold = (text)=>locale ? text.toLocaleLowerCase(locale) : text.toLowerCase();
|
|
36
|
+
const normalizedQuery = fold(query.trim());
|
|
37
|
+
if (!normalizedQuery) return groups.filter((group)=>group.items.length > 0);
|
|
38
|
+
const matches = (text)=>void 0 !== text && fold(text).includes(normalizedQuery);
|
|
39
|
+
return groups.map((group)=>matches(group.label) ? group : {
|
|
40
|
+
...group,
|
|
41
|
+
items: group.items.filter((item)=>matches(item.label) || matches(item.description) || item.keywords?.some(matches) === true)
|
|
42
|
+
}).filter((group)=>group.items.length > 0);
|
|
43
|
+
};
|
|
44
|
+
exports.filterGroups = __webpack_exports__.filterGroups;
|
|
45
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
46
|
+
"filterGroups"
|
|
47
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
48
|
+
Object.defineProperty(exports, '__esModule', {
|
|
49
|
+
value: true
|
|
50
|
+
});
|